Ignore meta in a method provider's list of provided methods.
[gitmo/MooseX-AttributeHelpers.git] / t / 206_trait_bag.t
CommitLineData
0951a229 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 20;
7use Test::Exception;
8use Test::Moose 'does_ok';
9
10BEGIN {
11 use_ok('MooseX::AttributeHelpers');
12}
13
14{
15 package Stuff;
16 use Moose;
17 use MooseX::AttributeHelpers;
18
19 has 'word_histogram' => (
c1984b5c 20 traits => [qw/MooseX::AttributeHelpers::Trait::Collection::Bag/],
0951a229 21 is => 'ro',
22 provides => {
23 'add' => 'add_word',
24 'get' => 'get_count_for',
25 'empty' => 'has_any_words',
26 'count' => 'num_words',
27 'delete' => 'delete_word',
28 }
29 );
30}
31
32my $stuff = Stuff->new();
33isa_ok($stuff, 'Stuff');
34
35can_ok($stuff, $_) for qw[
36 add_word
37 get_count_for
38 has_any_words
39 num_words
40 delete_word
41];
42
43ok(!$stuff->has_any_words, '... we have no words');
44is($stuff->num_words, 0, '... we have no words');
45
46lives_ok {
47 $stuff->add_word('bar');
48} '... set the words okay';
49
50ok($stuff->has_any_words, '... we have words');
51is($stuff->num_words, 1, '... we have 1 word(s)');
52is($stuff->get_count_for('bar'), 1, '... got words now');
53
54lives_ok {
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';
59
60is($stuff->num_words, 3, '... we still have 1 word(s)');
61is($stuff->get_count_for('foo'), 1, '... got words now');
62is($stuff->get_count_for('bar'), 5, '... got words now');
63is($stuff->get_count_for('baz'), 11, '... got words now');
64
65## test the meta
66
67my $words = $stuff->meta->get_attribute('word_histogram');
68does_ok($words, 'MooseX::AttributeHelpers::Trait::Collection::Bag');
69
70is_deeply($words->provides, {
71 'add' => 'add_word',
72 'get' => 'get_count_for',
73 'empty' => 'has_any_words',
74 'count' => 'num_words',
75 'delete' => 'delete_word',
76}, '... got the right provides mapping');
77