6 use Test::More tests => 21;
8 use Test::Moose 'does_ok';
11 use_ok('MooseX::AttributeHelpers');
19 traits => [qw/Collection::List/],
21 isa => 'ArrayRef[Int]',
22 init_arg => 'options',
23 default => sub { [] },
25 'count' => 'num_options',
26 'empty' => 'has_options',
27 'map' => 'map_options',
28 'grep' => 'filter_options',
29 'find' => 'find_option',
30 'elements' => 'options',
31 'join' => 'join_options',
36 my $stuff = Stuff->new(options => [ 1 .. 10 ]);
37 isa_ok($stuff, 'Stuff');
39 can_ok($stuff, $_) for qw[
50 is_deeply($stuff->_options, [1 .. 10], '... got options');
52 ok($stuff->has_options, '... we have options');
53 is($stuff->num_options, 10, '... got 2 options');
56 [ $stuff->filter_options(sub { $_[0] % 2 == 0 }) ],
58 '... got the right filtered values'
62 [ $stuff->map_options(sub { $_[0] * 2 }) ],
63 [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ],
64 '... got the right mapped values'
67 is($stuff->find_option(sub { $_[0] % 2 == 0 }), 2, '.. found the right option');
69 is_deeply([ $stuff->options ], [1 .. 10], '... got the list of options');
71 is($stuff->join_options(':'), '1:2:3:4:5:6:7:8:9:10', '... joined the list of options by :');
75 my $options = $stuff->meta->get_attribute('_options');
76 does_ok($options, 'MooseX::AttributeHelpers::Trait::Collection::List');
78 is_deeply($options->provides, {
79 'map' => 'map_options',
80 'grep' => 'filter_options',
81 'find' => 'find_option',
82 'count' => 'num_options',
83 'empty' => 'has_options',
84 'elements' => 'options',
85 'join' => 'join_options',
86 }, '... got the right provies mapping');
88 is($options->type_constraint->type_parameter, 'Int', '... got the right container type');