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