fix all examples to use handles; fix links to be to traits
[gitmo/Moose.git] / lib / Moose / AttributeHelpers.pm
CommitLineData
e3c07b19 1
2package Moose::AttributeHelpers;
3
dbd46676 4our $VERSION = '0.83';
e3c07b19 5$VERSION = eval $VERSION;
6our $AUTHORITY = 'cpan:STEVAN';
7
8use Moose 0.56 ();
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;
18use Moose::AttributeHelpers::Trait::Collection::Bag;
19
20use Moose::AttributeHelpers::Counter;
21use Moose::AttributeHelpers::Number;
22use Moose::AttributeHelpers::String;
23use Moose::AttributeHelpers::Bool;
24use Moose::AttributeHelpers::Collection::List;
25use Moose::AttributeHelpers::Collection::Array;
26use Moose::AttributeHelpers::Collection::Hash;
27use Moose::AttributeHelpers::Collection::ImmutableHash;
28use Moose::AttributeHelpers::Collection::Bag;
29
301;
31
32__END__
33
34=pod
35
36=head1 NAME
37
38Moose::AttributeHelpers - Extend your attribute interfaces
39
40=head1 SYNOPSIS
41
42 package MyClass;
43 use Moose;
44 use Moose::AttributeHelpers;
45
46 has 'mapping' => (
47 metaclass => 'Collection::Hash',
48 is => 'rw',
49 isa => 'HashRef[Str]',
50 default => sub { {} },
51 handles => {
52 exists_in_mapping => 'exists',
53 ids_in_mapping => 'keys',
54 get_mapping => 'get',
55 set_mapping => 'set',
56 set_quantity => [ set => [ 'quantity' ] ],
57 },
58 );
59
60
61 # ...
62
63 my $obj = MyClass->new;
64 $obj->set_quantity(10); # quantity => 10
65 $obj->set_mapping(4, 'foo'); # 4 => 'foo'
66 $obj->set_mapping(5, 'bar'); # 5 => 'bar'
67 $obj->set_mapping(6, 'baz'); # 6 => 'baz'
68
69
70 # prints 'bar'
71 print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
72
73 # prints '4, 5, 6'
74 print join ', ', $obj->ids_in_mapping;
75
76=head1 DESCRIPTION
77
78While L<Moose> attributes provide you with a way to name your accessors,
79readers, writers, clearers and predicates, this library provides commonly
80used attribute helper methods for more specific types of data.
81
82As seen in the L</SYNOPSIS>, you specify the extension via the
5f3663b2 83C<trait> parameter. Available meta classes are below; see L</METHOD PROVIDERS>.
e3c07b19 84
85=head1 PARAMETERS
86
87=head2 handles
88
5f3663b2 89This is like C<< handles >> in L<Moose/has>, but only HASH references are
90allowed. Keys are method names that you want installed locally, and values are
91methods from the method providers (below). Currying with delegated methods works normally for C<< handles >>.
e3c07b19 92
93=head1 METHOD PROVIDERS
94
95=over
96
5f3663b2 97=item L<Number|Moose::AttributeHelpers::Trait::Number>
e3c07b19 98
99Common numerical operations.
100
5f3663b2 101=item L<String|Moose::AttributeHelpers::Trait::String>
e3c07b19 102
103Common methods for string operations.
104
5f3663b2 105=item L<Counter|Moose::AttributeHelpers::Trait::Counter>
e3c07b19 106
107Methods for incrementing and decrementing a counter attribute.
108
5f3663b2 109=item L<Bool|Moose::AttributeHelpers::Trait::Bool>
e3c07b19 110
111Common methods for boolean values.
112
5f3663b2 113=item L<Collection::Hash|Moose::AttributeHelpers::Trait::Collection::Hash>
e3c07b19 114
115Common methods for hash references.
116
5f3663b2 117=item L<Collection::ImmutableHash|Moose::AttributeHelpers::Trait::Collection::ImmutableHash>
e3c07b19 118
119Common methods for inspecting hash references.
120
5f3663b2 121=item L<Collection::Array|Moose::AttributeHelpers::Trait::Collection::Array>
e3c07b19 122
123Common methods for array references.
124
5f3663b2 125=item L<Collection::List|Moose::AttributeHelpers::Trait::Collection::List>
e3c07b19 126
127Common list methods for array references.
128
129=back
130
131=head1 CAVEAT
132
133This is an early release of this module. Right now it is in great need
134of documentation and tests in the test suite. However, we have used this
135module to great success at C<$work> where it has been tested very thoroughly
136and deployed into a major production site.
137
138I plan on getting better docs and tests in the next few releases, but until
139then please refer to the few tests we do have and feel free email and/or
140message me on irc.perl.org if you have any questions.
141
142=head1 TODO
143
144We need tests and docs badly.
145
146=head1 BUGS
147
148All complex software has bugs lurking in it, and this module is no
149exception. If you find a bug please either email me, or add the bug
150to cpan-RT.
151
152=head1 AUTHOR
153
154Stevan Little E<lt>stevan@iinteractive.comE<gt>
155
156B<with contributions from:>
157
158Robert (rlb3) Boone
159
160Paul (frodwith) Driver
161
162Shawn (Sartak) Moore
163
164Chris (perigrin) Prather
165
166Robert (phaylon) Sedlacek
167
168Tom (dec) Lanyon
169
170Yuval Kogman
171
172Jason May
173
174Cory (gphat) Watson
175
176Florian (rafl) Ragwitz
177
178Evan Carroll
179
180Jesse (doy) Luehrs
181
182=head1 COPYRIGHT AND LICENSE
183
184Copyright 2007-2009 by Infinity Interactive, Inc.
185
186L<http://www.iinteractive.com>
187
188This library is free software; you can redistribute it and/or modify
189it under the same terms as Perl itself.
190
191=cut