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