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