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