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