1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
use strict;
use warnings;
use Test::More 0.96;
my $mod = 'Config::MVP::Slicer';
eval "require $mod" or die $@;
my $slicer = new_ok($mod, [{
config => {
opt => 'main config val',
'Plug.attr' => 'pa',
'Mod::Name.opt' => 'val',
'Loco.cookie[]' => 'snicker',
'X::Crazy.cookie[]' => 'doodle',
'Crazy.frosting' => 'cupcake',
'Moose.and[]' => 'squirrel',
'Hunting.season[0]' => 'duck',
'Hunting.season[1]' => 'wabbit',
'Hunting.season[9]' => 'fudd',
# keys are sorted very simply (alphabetically)
'Hunting2.season[1.09]' => 'bunny',
'Hunting2.season[1.10]' => 'bird',
'Hunting2.season[1.08]' => 'wabbit',
'Hunting2.season[1.11]' => 'duck',
'Hunting2.season[z]' => 'zombie',
},
}]);
is_deeply
$slicer->slice([Plug => 'X::Plug' => {}]),
{ attr => 'pa' },
'matches on plugin name';
my $previous = { unused => 'config' };
is_deeply
$slicer->slice([ModName => 'Mod::Name' => $previous ]),
{ opt => 'val' },
'matches on class name';
is_deeply $previous, { unused => 'config' }, 'slice leaves conf untouched';
is_deeply
$slicer->slice([Loco => 'X::Crazy' => $previous ]),
{ cookie => [qw(snicker doodle)] },
'matches on package and class name (merges array)';
is_deeply
$slicer->slice([AnyCrazy => 'X::Crazy' => $previous ]),
{ cookie => ['doodle'] },
'matches on package without class name';
is_deeply
$slicer->slice([Crazy => 'X::Crazy' => $previous ]),
{ frosting => 'cupcake', cookie => ['doodle'] },
'matches on package and class name (merges hash)';
is_deeply
$slicer->slice([Moose => Moose => {}]),
{ and => [qw(squirrel)] },
'received array ref when specified as []';
is_deeply
$slicer->slice([Hunting => 'X::Hunting' => {}]),
{ season => [qw(duck wabbit fudd)] },
'received array ref containing all items';
is_deeply
$slicer->slice([Hunting2 => 'X::Hunting' => {}]),
{ season => [qw(wabbit bunny bird duck zombie)] },
'received array ref containing all items';
done_testing;
|