Commit | Line | Data |
e3c07b19 |
1 | |
2 | package Moose::AttributeHelpers; |
3 | |
115601b6 |
4 | our $VERSION = '0.85'; |
e3c07b19 |
5 | $VERSION = eval $VERSION; |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
792d7b13 |
8 | use Moose; |
e3c07b19 |
9 | |
e3c07b19 |
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 | |
e3c07b19 |
20 | 1; |
21 | |
22 | __END__ |
23 | |
24 | =pod |
25 | |
26 | =head1 NAME |
27 | |
28 | Moose::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 | |
68 | While L<Moose> attributes provide you with a way to name your accessors, |
69 | readers, writers, clearers and predicates, this library provides commonly |
70 | used attribute helper methods for more specific types of data. |
71 | |
72 | As seen in the L</SYNOPSIS>, you specify the extension via the |
5f3663b2 |
73 | C<trait> parameter. Available meta classes are below; see L</METHOD PROVIDERS>. |
e3c07b19 |
74 | |
87b4e821 |
75 | This module used to exist as the L<MooseX::AttributeHelpers> extension. It was |
76 | very commonly used, so we moved it into core Moose. Since this gave us a chance |
77 | to change the interface, you will have to change your code or continue using |
78 | the L<MooseX::AttributeHelpers> extension. |
79 | |
e3c07b19 |
80 | =head1 PARAMETERS |
81 | |
82 | =head2 handles |
83 | |
5f3663b2 |
84 | This is like C<< handles >> in L<Moose/has>, but only HASH references are |
85 | allowed. Keys are method names that you want installed locally, and values are |
87b4e821 |
86 | methods from the method providers (below). Currying with delegated methods |
87 | works 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 | |
95 | Common numerical operations. |
96 | |
5f3663b2 |
97 | =item L<String|Moose::AttributeHelpers::Trait::String> |
e3c07b19 |
98 | |
99 | Common methods for string operations. |
100 | |
5f3663b2 |
101 | =item L<Counter|Moose::AttributeHelpers::Trait::Counter> |
e3c07b19 |
102 | |
103 | Methods for incrementing and decrementing a counter attribute. |
104 | |
5f3663b2 |
105 | =item L<Bool|Moose::AttributeHelpers::Trait::Bool> |
e3c07b19 |
106 | |
107 | Common methods for boolean values. |
108 | |
5f3663b2 |
109 | =item L<Collection::Hash|Moose::AttributeHelpers::Trait::Collection::Hash> |
e3c07b19 |
110 | |
111 | Common methods for hash references. |
112 | |
5f3663b2 |
113 | =item L<Collection::ImmutableHash|Moose::AttributeHelpers::Trait::Collection::ImmutableHash> |
e3c07b19 |
114 | |
115 | Common methods for inspecting hash references. |
116 | |
5f3663b2 |
117 | =item L<Collection::Array|Moose::AttributeHelpers::Trait::Collection::Array> |
e3c07b19 |
118 | |
119 | Common methods for array references. |
120 | |
5f3663b2 |
121 | =item L<Collection::List|Moose::AttributeHelpers::Trait::Collection::List> |
e3c07b19 |
122 | |
123 | Common list methods for array references. |
124 | |
125 | =back |
126 | |
e3c07b19 |
127 | =head1 BUGS |
128 | |
129 | All complex software has bugs lurking in it, and this module is no |
130 | exception. If you find a bug please either email me, or add the bug |
131 | to cpan-RT. |
132 | |
133 | =head1 AUTHOR |
134 | |
135 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
136 | |
137 | B<with contributions from:> |
138 | |
139 | Robert (rlb3) Boone |
140 | |
141 | Paul (frodwith) Driver |
142 | |
143 | Shawn (Sartak) Moore |
144 | |
145 | Chris (perigrin) Prather |
146 | |
147 | Robert (phaylon) Sedlacek |
148 | |
149 | Tom (dec) Lanyon |
150 | |
151 | Yuval Kogman |
152 | |
153 | Jason May |
154 | |
155 | Cory (gphat) Watson |
156 | |
157 | Florian (rafl) Ragwitz |
158 | |
159 | Evan Carroll |
160 | |
161 | Jesse (doy) Luehrs |
162 | |
163 | =head1 COPYRIGHT AND LICENSE |
164 | |
165 | Copyright 2007-2009 by Infinity Interactive, Inc. |
166 | |
167 | L<http://www.iinteractive.com> |
168 | |
169 | This library is free software; you can redistribute it and/or modify |
170 | it under the same terms as Perl itself. |
171 | |
172 | =cut |