14 use_ok('MooseX::AttributeHelpers');
22 metaclass => 'Collection::List',
24 isa => 'ArrayRef[Int]',
25 init_arg => 'options',
26 default => sub { [] },
28 'count' => 'num_options',
29 'empty' => 'has_options',
30 'map' => 'map_options',
31 'grep' => 'filter_options',
32 'find' => 'find_option',
33 'elements' => 'options',
34 'join' => 'join_options',
35 'get' => 'get_option_at',
36 'first' => 'get_first_option',
37 'last' => 'get_last_option',
40 'grep' => {less_than_five => [ sub { $_ < 5 } ]},
41 'map' => {up_by_one => [ sub { $_ + 1 } ]},
42 'join' => {dashify => [ '-' ]}
47 my $stuff = Stuff->new(options => [ 1 .. 10 ]);
48 isa_ok($stuff, 'Stuff');
50 can_ok($stuff, $_) for qw[
62 is_deeply($stuff->_options, [1 .. 10], '... got options');
64 ok($stuff->has_options, '... we have options');
65 is($stuff->num_options, 10, '... got 2 options');
66 cmp_ok($stuff->get_option_at(0), '==', 1, '... get option 0');
67 cmp_ok($stuff->get_first_option, '==', 1, '... get first');
68 cmp_ok($stuff->get_last_option, '==', 10, '... get first');
71 [ $stuff->filter_options(sub { $_[0] % 2 == 0 }) ],
73 '... got the right filtered values'
77 [ $stuff->map_options(sub { $_[0] * 2 }) ],
78 [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ],
79 '... got the right mapped values'
82 is($stuff->find_option(sub { $_[0] % 2 == 0 }), 2, '.. found the right option');
84 is_deeply([ $stuff->options ], [1 .. 10], '... got the list of options');
86 is($stuff->join_options(':'), '1:2:3:4:5:6:7:8:9:10', '... joined the list of options by :');
89 is_deeply([ $stuff->less_than_five() ], [1 .. 4]);
91 is_deeply([ $stuff->up_by_one() ], [2 .. 11]);
93 is($stuff->dashify, '1-2-3-4-5-6-7-8-9-10');
97 my $options = $stuff->meta->get_attribute('_options');
98 isa_ok($options, 'MooseX::AttributeHelpers::Collection::List');
100 is_deeply($options->provides, {
101 'map' => 'map_options',
102 'grep' => 'filter_options',
103 'find' => 'find_option',
104 'count' => 'num_options',
105 'empty' => 'has_options',
106 'elements' => 'options',
107 'join' => 'join_options',
108 'get' => 'get_option_at',
109 'first' => 'get_first_option',
110 'last' => 'get_last_option'
111 }, '... got the right provies mapping');
113 is($options->type_constraint->type_parameter, 'Int', '... got the right container type');