6 use Test::More tests => 19;
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',
34 my $stuff = Stuff->new(options => [ 1 .. 10 ]);
35 isa_ok($stuff, 'Stuff');
37 can_ok($stuff, $_) for qw[
47 is_deeply($stuff->_options, [1 .. 10], '... got options');
49 ok($stuff->has_options, '... we have options');
50 is($stuff->num_options, 10, '... got 2 options');
53 [ $stuff->filter_options(sub { $_[0] % 2 == 0 }) ],
55 '... got the right filtered values'
59 [ $stuff->map_options(sub { $_[0] * 2 }) ],
60 [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ],
61 '... got the right mapped values'
64 is($stuff->find_option(sub { $_[0] % 2 == 0 }), 2, '.. found the right option');
66 is_deeply([ $stuff->options ], [1 .. 10], '... got the list of options');
70 my $options = $stuff->meta->get_attribute('_options');
71 isa_ok($options, 'MooseX::AttributeHelpers::Collection::List');
73 is_deeply($options->provides, {
74 'map' => 'map_options',
75 'grep' => 'filter_options',
76 'find' => 'find_option',
77 'count' => 'num_options',
78 'empty' => 'has_options',
79 'elements' => 'options',
80 }, '... got the right provies mapping');
82 is($options->type_constraint->type_parameter, 'Int', '... got the right container type');