we aren't coring Bag
[gitmo/Moose.git] / lib / Moose / AttributeHelpers.pm
CommitLineData
e3c07b19 1
2package Moose::AttributeHelpers;
3
96539d20 4our $VERSION = '0.87';
e3c07b19 5$VERSION = eval $VERSION;
6our $AUTHORITY = 'cpan:STEVAN';
7
792d7b13 8use Moose;
e3c07b19 9
e3c07b19 10use Moose::AttributeHelpers::Trait::Bool;
11use Moose::AttributeHelpers::Trait::Counter;
12use Moose::AttributeHelpers::Trait::Number;
13use Moose::AttributeHelpers::Trait::String;
14use Moose::AttributeHelpers::Trait::Collection::List;
15use Moose::AttributeHelpers::Trait::Collection::Array;
16use Moose::AttributeHelpers::Trait::Collection::Hash;
17use Moose::AttributeHelpers::Trait::Collection::ImmutableHash;
e3c07b19 18
e3c07b19 191;
20
21__END__
22
23=pod
24
25=head1 NAME
26
27Moose::AttributeHelpers - Extend your attribute interfaces
28
29=head1 SYNOPSIS
30
31 package MyClass;
32 use Moose;
33 use Moose::AttributeHelpers;
34
35 has 'mapping' => (
c13596ce 36 traits => [ 'Collection::Hash' ],
e3c07b19 37 is => 'rw',
38 isa => 'HashRef[Str]',
39 default => sub { {} },
40 handles => {
41 exists_in_mapping => 'exists',
42 ids_in_mapping => 'keys',
43 get_mapping => 'get',
44 set_mapping => 'set',
45 set_quantity => [ set => [ 'quantity' ] ],
46 },
47 );
48
49
50 # ...
51
52 my $obj = MyClass->new;
53 $obj->set_quantity(10); # quantity => 10
54 $obj->set_mapping(4, 'foo'); # 4 => 'foo'
55 $obj->set_mapping(5, 'bar'); # 5 => 'bar'
56 $obj->set_mapping(6, 'baz'); # 6 => 'baz'
57
58
59 # prints 'bar'
60 print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
61
62 # prints '4, 5, 6'
63 print join ', ', $obj->ids_in_mapping;
64
65=head1 DESCRIPTION
66
67While L<Moose> attributes provide you with a way to name your accessors,
68readers, writers, clearers and predicates, this library provides commonly
69used attribute helper methods for more specific types of data.
70
71As seen in the L</SYNOPSIS>, you specify the extension via the
5f3663b2 72C<trait> parameter. Available meta classes are below; see L</METHOD PROVIDERS>.
e3c07b19 73
87b4e821 74This module used to exist as the L<MooseX::AttributeHelpers> extension. It was
75very commonly used, so we moved it into core Moose. Since this gave us a chance
76to change the interface, you will have to change your code or continue using
77the L<MooseX::AttributeHelpers> extension.
78
e3c07b19 79=head1 PARAMETERS
80
81=head2 handles
82
5f3663b2 83This is like C<< handles >> in L<Moose/has>, but only HASH references are
84allowed. Keys are method names that you want installed locally, and values are
87b4e821 85methods from the method providers (below). Currying with delegated methods
86works normally for C<< handles >>.
e3c07b19 87
88=head1 METHOD PROVIDERS
89
90=over
91
5f3663b2 92=item L<Number|Moose::AttributeHelpers::Trait::Number>
e3c07b19 93
94Common numerical operations.
95
5f3663b2 96=item L<String|Moose::AttributeHelpers::Trait::String>
e3c07b19 97
98Common methods for string operations.
99
5f3663b2 100=item L<Counter|Moose::AttributeHelpers::Trait::Counter>
e3c07b19 101
102Methods for incrementing and decrementing a counter attribute.
103
5f3663b2 104=item L<Bool|Moose::AttributeHelpers::Trait::Bool>
e3c07b19 105
106Common methods for boolean values.
107
5f3663b2 108=item L<Collection::Hash|Moose::AttributeHelpers::Trait::Collection::Hash>
e3c07b19 109
110Common methods for hash references.
111
5f3663b2 112=item L<Collection::ImmutableHash|Moose::AttributeHelpers::Trait::Collection::ImmutableHash>
e3c07b19 113
114Common methods for inspecting hash references.
115
5f3663b2 116=item L<Collection::Array|Moose::AttributeHelpers::Trait::Collection::Array>
e3c07b19 117
118Common methods for array references.
119
5f3663b2 120=item L<Collection::List|Moose::AttributeHelpers::Trait::Collection::List>
e3c07b19 121
122Common list methods for array references.
123
124=back
125
e3c07b19 126=head1 BUGS
127
128All complex software has bugs lurking in it, and this module is no
129exception. If you find a bug please either email me, or add the bug
130to cpan-RT.
131
132=head1 AUTHOR
133
134Stevan Little E<lt>stevan@iinteractive.comE<gt>
135
136B<with contributions from:>
137
138Robert (rlb3) Boone
139
140Paul (frodwith) Driver
141
142Shawn (Sartak) Moore
143
144Chris (perigrin) Prather
145
146Robert (phaylon) Sedlacek
147
148Tom (dec) Lanyon
149
150Yuval Kogman
151
152Jason May
153
154Cory (gphat) Watson
155
156Florian (rafl) Ragwitz
157
158Evan Carroll
159
160Jesse (doy) Luehrs
161
162=head1 COPYRIGHT AND LICENSE
163
164Copyright 2007-2009 by Infinity Interactive, Inc.
165
166L<http://www.iinteractive.com>
167
168This library is free software; you can redistribute it and/or modify
169it under the same terms as Perl itself.
170
171=cut