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