6 use Test::More tests => 16;
10 use_ok('MooseX::AttributeHelpers');
18 metaclass => 'Collection::List',
20 isa => 'ArrayRef[Int]',
21 default => sub { [] },
23 'count' => 'num_options',
24 'has_items' => 'has_options',
25 'map' => 'map_options',
26 'grep' => 'filter_options',
27 'find' => 'find_option',
32 my $stuff = Stuff->new(options => [ 1 .. 10 ]);
33 isa_ok($stuff, 'Stuff');
35 can_ok($stuff, $_) for qw[
43 is_deeply($stuff->options, [1 .. 10], '... got options');
45 ok($stuff->has_options, '... we have options');
46 is($stuff->num_options, 10, '... got 2 options');
49 [ $stuff->filter_options(sub { $_[0] % 2 == 0 }) ],
51 '... got the right filtered values'
55 [ $stuff->map_options(sub { $_[0] * 2 }) ],
56 [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ],
57 '... got the right mapped values'
60 is($stuff->find_option(sub { $_[0] % 2 == 0 }), 2, '.. found the right option');
64 my $options = $stuff->meta->get_attribute('options');
65 isa_ok($options, 'MooseX::AttributeHelpers::Collection::List');
67 is_deeply($options->provides, {
68 'map' => 'map_options',
69 'grep' => 'filter_options',
70 'find' => 'find_option',
71 'count' => 'num_options',
72 'has_items' => 'has_options',
73 }, '... got the right provides mapping');
75 is($options->type_constraint->type_parameter, 'Int', '... got the right container type');