| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use Test::More tests => 8; |
| 5 |
|
| 6 |
{ |
| 7 |
package Dancer2::Plugin::FromConfig; |
| 8 |
|
| 9 |
use Dancer2::Plugin; |
| 10 |
|
| 11 |
BEGIN { |
| 12 |
has one => ( |
| 13 |
is => 'ro', |
| 14 |
from_config => 1, |
| 15 |
); |
| 16 |
|
| 17 |
has three => ( |
| 18 |
is => 'ro', |
| 19 |
from_config => 'two.three', |
| 20 |
); |
| 21 |
|
| 22 |
has four => ( |
| 23 |
is => 'ro', |
| 24 |
from_config => 1, |
| 25 |
default => sub { 'quatre' }, |
| 26 |
); |
| 27 |
|
| 28 |
has five => ( |
| 29 |
is => 'ro', |
| 30 |
from_config => sub { 'cinq' }, |
| 31 |
); |
| 32 |
|
| 33 |
has six => ( |
| 34 |
is => 'ro', |
| 35 |
from_config => sub { 'six' }, |
| 36 |
default => sub { 'AH!' }, |
| 37 |
plugin_keyword => 1, |
| 38 |
); |
| 39 |
|
| 40 |
has [qw(seven eight)] => ( |
| 41 |
is => 'ro', |
| 42 |
from_config => 1, |
| 43 |
plugin_keyword => 1, |
| 44 |
); |
| 45 |
|
| 46 |
eval { |
| 47 |
has [qw(nine ten)] => ( |
| 48 |
is => 'ro', |
| 49 |
from_config => 1, |
| 50 |
plugin_keyword => ['nine', 'ten'], |
| 51 |
); |
| 52 |
}; |
| 53 |
our $plugin_keyword_exception = $@; |
| 54 |
|
| 55 |
plugin_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 |
|