6 use Test::More tests => 20;
8 use Test::Moose 'does_ok';
11 use_ok('Moose::AttributeHelpers');
17 use Moose::AttributeHelpers;
19 has 'word_histogram' => (
20 traits => [qw/Collection::Bag/],
24 'get' => 'get_count_for',
25 'empty' => 'has_any_words',
26 'count' => 'num_words',
27 'delete' => 'delete_word',
32 my $stuff = Stuff->new();
33 isa_ok($stuff, 'Stuff');
35 can_ok($stuff, $_) for qw[
43 ok(!$stuff->has_any_words, '... we have no words');
44 is($stuff->num_words, 0, '... we have no words');
47 $stuff->add_word('bar');
48 } '... set the words okay';
50 ok($stuff->has_any_words, '... we have words');
51 is($stuff->num_words, 1, '... we have 1 word(s)');
52 is($stuff->get_count_for('bar'), 1, '... got words now');
55 $stuff->add_word('foo');
56 $stuff->add_word('bar') for 0 .. 3;
57 $stuff->add_word('baz') for 0 .. 10;
58 } '... set the words okay';
60 is($stuff->num_words, 3, '... we still have 1 word(s)');
61 is($stuff->get_count_for('foo'), 1, '... got words now');
62 is($stuff->get_count_for('bar'), 5, '... got words now');
63 is($stuff->get_count_for('baz'), 11, '... got words now');
67 my $words = $stuff->meta->get_attribute('word_histogram');
68 does_ok($words, 'Moose::AttributeHelpers::Trait::Collection::Bag');
70 is_deeply($words->provides, {
72 'get' => 'get_count_for',
73 'empty' => 'has_any_words',
74 'count' => 'num_words',
75 'delete' => 'delete_word',
76 }, '... got the right provides mapping');