1use strict;
2use warnings;
3
4use Test::More tests => 8;
5
6{
7package Dancer2::Plugin::FromConfig;
8
9use Dancer2::Plugin;
10
11BEGIN {
12has one => (
13    is => 'ro',
14    from_config => 1,
15);
16
17has three => (
18    is => 'ro',
19    from_config => 'two.three',
20);
21
22has four => (
23    is => 'ro',
24    from_config => 1,
25    default => sub { 'quatre' },
26);
27
28has five => (
29    is => 'ro',
30    from_config => sub { 'cinq' },
31);
32
33has six => (
34    is => 'ro',
35    from_config => sub { 'six' },
36    default => sub { 'AH!' },
37    plugin_keyword => 1,
38);
39
40has [qw(seven eight)] => (
41    is => 'ro',
42    from_config => 1,
43    plugin_keyword => 1,
44);
45
46eval {
47    has [qw(nine ten)] => (
48        is => 'ro',
49        from_config => 1,
50        plugin_keyword => ['nine', 'ten'],
51    );
52};
53our $plugin_keyword_exception = $@;
54
55plugin_keywords qw/ one three four five /;
56
57}
58}
59
60{
61    package MyApp;
62
63    use Dancer2;
64
65    use Dancer2::Plugin::FromConfig;
66
67    set plugins => {
68        FromConfig => {
69            one => 'un',
70            two => {
71                three => 'trois',
72            },
73            seven => 'sept',
74            eight => 'huit',
75        }
76    };
77
78
79    Test::More::is one() => 'un', 'from config';
80    Test::More::is three() => 'trois', 'from config, nested';
81    Test::More::is four() => 'quatre', 'nothing in config, default value';
82    Test::More::is five() => 'cinq', 'from_config a coderef';
83    Test::More::is six() => 'AH!', 'from_config a coderef, no override';
84    Test::More::is seven() => 'sept', 'from_config, defined two fields at once #1';
85    Test::More::is eight() => 'huit', 'from_config, defined two fields at once #2';
86    Test::More::ok $Dancer2::Plugin::FromConfig::plugin_keyword_exception,
87        "defining two fields simultaneously with multiple plugin_keyword values"
88        . " is disallowed";
89}
90
91
92
93