3b1afd92f882e7ac42b4e1a52324bbc410bdd6be
[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.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
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 Moose::Meta::Attribute::Custom::Collection::Bag;
37 sub register_implementation { 'MooseX::AttributeHelpers::Collection::Bag' }
38
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
102 Copyright 2007 by Infinity Interactive, Inc.
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