Merge branch 'master' into attribute_helpers
[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
87b4e821 75This module used to exist as the L<MooseX::AttributeHelpers> extension. It was
76very commonly used, so we moved it into core Moose. Since this gave us a chance
77to change the interface, you will have to change your code or continue using
78the L<MooseX::AttributeHelpers> extension.
79
e3c07b19 80=head1 PARAMETERS
81
82=head2 handles
83
5f3663b2 84This is like C<< handles >> in L<Moose/has>, but only HASH references are
85allowed. Keys are method names that you want installed locally, and values are
87b4e821 86methods from the method providers (below). Currying with delegated methods
87works normally for C<< handles >>.
e3c07b19 88
89=head1 METHOD PROVIDERS
90
91=over
92
5f3663b2 93=item L<Number|Moose::AttributeHelpers::Trait::Number>
e3c07b19 94
95Common numerical operations.
96
5f3663b2 97=item L<String|Moose::AttributeHelpers::Trait::String>
e3c07b19 98
99Common methods for string operations.
100
5f3663b2 101=item L<Counter|Moose::AttributeHelpers::Trait::Counter>
e3c07b19 102
103Methods for incrementing and decrementing a counter attribute.
104
5f3663b2 105=item L<Bool|Moose::AttributeHelpers::Trait::Bool>
e3c07b19 106
107Common methods for boolean values.
108
5f3663b2 109=item L<Collection::Hash|Moose::AttributeHelpers::Trait::Collection::Hash>
e3c07b19 110
111Common methods for hash references.
112
5f3663b2 113=item L<Collection::ImmutableHash|Moose::AttributeHelpers::Trait::Collection::ImmutableHash>
e3c07b19 114
115Common methods for inspecting hash references.
116
5f3663b2 117=item L<Collection::Array|Moose::AttributeHelpers::Trait::Collection::Array>
e3c07b19 118
119Common methods for array references.
120
5f3663b2 121=item L<Collection::List|Moose::AttributeHelpers::Trait::Collection::List>
e3c07b19 122
123Common list methods for array references.
124
125=back
126
e3c07b19 127=head1 BUGS
128
129All complex software has bugs lurking in it, and this module is no
130exception. If you find a bug please either email me, or add the bug
131to cpan-RT.
132
133=head1 AUTHOR
134
135Stevan Little E<lt>stevan@iinteractive.comE<gt>
136
137B<with contributions from:>
138
139Robert (rlb3) Boone
140
141Paul (frodwith) Driver
142
143Shawn (Sartak) Moore
144
145Chris (perigrin) Prather
146
147Robert (phaylon) Sedlacek
148
149Tom (dec) Lanyon
150
151Yuval Kogman
152
153Jason May
154
155Cory (gphat) Watson
156
157Florian (rafl) Ragwitz
158
159Evan Carroll
160
161Jesse (doy) Luehrs
162
163=head1 COPYRIGHT AND LICENSE
164
165Copyright 2007-2009 by Infinity Interactive, Inc.
166
167L<http://www.iinteractive.com>
168
169This library is free software; you can redistribute it and/or modify
170it under the same terms as Perl itself.
171
172=cut