6 use Test::More tests => 24;
10 use_ok('MooseX::AttributeHelpers');
18 metaclass => 'Collection::List',
20 isa => 'ArrayRef[Int]',
21 init_arg => 'options',
22 default => sub { [] },
24 'count' => 'num_options',
25 'empty' => 'has_options',
26 'map' => 'map_options',
27 'grep' => 'filter_options',
28 'find' => 'find_option',
29 'elements' => 'options',
30 'join' => 'join_options',
33 'grep' => {less_than_five => [ sub { $_ < 5 } ]},
34 'map' => {up_by_one => [ sub { $_ + 1 } ]},
35 'join' => {dashify => [ '-' ]}
40 my $stuff = Stuff->new(options => [ 1 .. 10 ]);
41 isa_ok($stuff, 'Stuff');
43 can_ok($stuff, $_) for qw[
54 is_deeply($stuff->_options, [1 .. 10], '... got options');
56 ok($stuff->has_options, '... we have options');
57 is($stuff->num_options, 10, '... got 2 options');
60 [ $stuff->filter_options(sub { $_[0] % 2 == 0 }) ],
62 '... got the right filtered values'
66 [ $stuff->map_options(sub { $_[0] * 2 }) ],
67 [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ],
68 '... got the right mapped values'
71 is($stuff->find_option(sub { $_[0] % 2 == 0 }), 2, '.. found the right option');
73 is_deeply([ $stuff->options ], [1 .. 10], '... got the list of options');
75 is($stuff->join_options(':'), '1:2:3:4:5:6:7:8:9:10', '... joined the list of options by :');
78 is_deeply([ $stuff->less_than_five() ], [1 .. 4]);
80 is_deeply([ $stuff->up_by_one() ], [2 .. 11]);
82 is($stuff->dashify, '1-2-3-4-5-6-7-8-9-10');
86 my $options = $stuff->meta->get_attribute('_options');
87 isa_ok($options, 'MooseX::AttributeHelpers::Collection::List');
89 is_deeply($options->provides, {
90 'map' => 'map_options',
91 'grep' => 'filter_options',
92 'find' => 'find_option',
93 'count' => 'num_options',
94 'empty' => 'has_options',
95 'elements' => 'options',
96 'join' => 'join_options',
97 }, '... got the right provies mapping');
99 is($options->type_constraint->type_parameter, 'Int', '... got the right container type');