fix all examples to use handles; fix links to be to traits
[gitmo/Moose.git] / lib / Moose / AttributeHelpers / Trait / Collection / Bag.pm
CommitLineData
e3c07b19 1
2package Moose::AttributeHelpers::Trait::Collection::Bag;
3use Moose::Role;
4use Moose::Util::TypeConstraints;
5
dbd46676 6our $VERSION = '0.83';
e3c07b19 7$VERSION = eval $VERSION;
8our $AUTHORITY = 'cpan:STEVAN';
9
10use Moose::AttributeHelpers::MethodProvider::Bag;
11
12with 'Moose::AttributeHelpers::Trait::Collection';
13
14has 'method_provider' => (
15 is => 'ro',
16 isa => 'ClassName',
17 predicate => 'has_method_provider',
18 default => 'Moose::AttributeHelpers::MethodProvider::Bag'
19);
20
21subtype 'Bag' => as 'HashRef[Int]';
22
23sub helper_type { 'Bag' }
24
25d86888 25before 'process_options_for_handles' => sub {
e3c07b19 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 'Moose::AttributeHelpers::Trait::Collection::Bag'
44}
45
461;
47
48__END__
49
50=pod
51
52=head1 NAME
53
54Moose::AttributeHelpers::Collection::Bag
55
56=head1 SYNOPSIS
57
58 package Stuff;
59 use Moose;
60 use Moose::AttributeHelpers;
61
62 has 'word_histogram' => (
63 metaclass => 'Collection::Bag',
64 is => 'ro',
65 isa => 'Bag', # optional ... as is defalt
5f3663b2 66 handles => {
67 add_word => 'add',
68 get_count_for => 'get',
69 has_any_words => 'empty',
70 num_words => 'count',
71 delete_word => 'delete',
e3c07b19 72 }
73 );
74
75=head1 DESCRIPTION
76
77This module provides a Bag attribute which provides a number of
78bag-like operations. See L<Moose::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
25d86888 93=item B<process_options_for_handles>
e3c07b19 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-2009 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