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