Commit | Line | Data |
ca6ab7d1 |
1 | |
2 | package MooseX::AttributeHelpers::Trait::Collection::Bag; |
3 | use Moose::Role; |
4 | use Moose::Util::TypeConstraints; |
5 | |
9807aa66 |
6 | our $VERSION = '0.21'; |
cf0d1310 |
7 | $VERSION = eval $VERSION; |
ca6ab7d1 |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | |
10 | use MooseX::AttributeHelpers::MethodProvider::Bag; |
11 | |
12 | with 'MooseX::AttributeHelpers::Trait::Collection'; |
13 | |
14 | has 'method_provider' => ( |
15 | is => 'ro', |
16 | isa => 'ClassName', |
17 | predicate => 'has_method_provider', |
18 | default => 'MooseX::AttributeHelpers::MethodProvider::Bag' |
19 | ); |
20 | |
0afcb318 |
21 | subtype 'Bag' => as 'HashRef[Int]'; |
ca6ab7d1 |
22 | |
23 | sub helper_type { 'Bag' } |
24 | |
25 | before 'process_options_for_provides' => sub { |
26 | my ($self, $options, $name) = @_; |
27 | |
28 | # Set some default attribute options here unless already defined |
29 | if ((my $type = $self->helper_type) && !exists $options->{isa}){ |
30 | $options->{isa} = $type; |
31 | } |
32 | |
33 | $options->{default} = sub { +{} } unless exists $options->{default}; |
34 | }; |
35 | |
36 | no Moose::Role; |
37 | no Moose::Util::TypeConstraints; |
38 | |
ca6ab7d1 |
39 | 1; |
40 | |
41 | __END__ |
42 | |
43 | =pod |
44 | |
45 | =head1 NAME |
46 | |
47 | MooseX::AttributeHelpers::Collection::Bag |
48 | |
49 | =head1 SYNOPSIS |
50 | |
51 | package Stuff; |
52 | use Moose; |
53 | use MooseX::AttributeHelpers; |
54 | |
55 | has 'word_histogram' => ( |
56 | metaclass => 'Collection::Bag', |
57 | is => 'ro', |
58 | isa => 'Bag', # optional ... as is defalt |
59 | provides => { |
60 | 'add' => 'add_word', |
61 | 'get' => 'get_count_for', |
62 | 'empty' => 'has_any_words', |
63 | 'count' => 'num_words', |
64 | 'delete' => 'delete_word', |
65 | } |
66 | ); |
67 | |
68 | =head1 DESCRIPTION |
69 | |
70 | This module provides a Bag attribute which provides a number of |
71 | bag-like operations. See L<MooseX::AttributeHelpers::MethodProvider::Bag> |
72 | for more details. |
73 | |
74 | =head1 METHODS |
75 | |
76 | =over 4 |
77 | |
78 | =item B<meta> |
79 | |
80 | =item B<method_provider> |
81 | |
82 | =item B<has_method_provider> |
83 | |
84 | =item B<helper_type> |
85 | |
86 | =item B<process_options_for_provides> |
87 | |
88 | =back |
89 | |
90 | =head1 BUGS |
91 | |
92 | All complex software has bugs lurking in it, and this module is no |
93 | exception. If you find a bug please either email me, or add the bug |
94 | to cpan-RT. |
95 | |
96 | =head1 AUTHOR |
97 | |
98 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
99 | |
100 | =head1 COPYRIGHT AND LICENSE |
101 | |
9c5d164e |
102 | Copyright 2007-2009 by Infinity Interactive, Inc. |
ca6ab7d1 |
103 | |
104 | L<http://www.iinteractive.com> |
105 | |
106 | This library is free software; you can redistribute it and/or modify |
107 | it under the same terms as Perl itself. |
108 | |
109 | =cut |