6 use Test::More tests => 20;
10 use_ok('Moose::AttributeHelpers');
16 use Moose::AttributeHelpers;
18 has 'word_histogram' => (
19 metaclass => 'Collection::Bag',
23 'get' => 'get_count_for',
24 'empty' => 'has_any_words',
25 'count' => 'num_words',
26 'delete' => 'delete_word',
31 my $stuff = Stuff->new();
32 isa_ok($stuff, 'Stuff');
34 can_ok($stuff, $_) for qw[
42 ok(!$stuff->has_any_words, '... we have no words');
43 is($stuff->num_words, 0, '... we have no words');
46 $stuff->add_word('bar');
47 } '... set the words okay';
49 ok($stuff->has_any_words, '... we have words');
50 is($stuff->num_words, 1, '... we have 1 word(s)');
51 is($stuff->get_count_for('bar'), 1, '... got words now');
54 $stuff->add_word('foo');
55 $stuff->add_word('bar') for 0 .. 3;
56 $stuff->add_word('baz') for 0 .. 10;
57 } '... set the words okay';
59 is($stuff->num_words, 3, '... we still have 1 word(s)');
60 is($stuff->get_count_for('foo'), 1, '... got words now');
61 is($stuff->get_count_for('bar'), 5, '... got words now');
62 is($stuff->get_count_for('baz'), 11, '... got words now');
66 my $words = $stuff->meta->get_attribute('word_histogram');
67 isa_ok($words, 'Moose::AttributeHelpers::Collection::Bag');
69 is_deeply($words->provides, {
71 'get' => 'get_count_for',
72 'empty' => 'has_any_words',
73 'count' => 'num_words',
74 'delete' => 'delete_word',
75 }, '... got the right provides mapping');