1MooseX::AttributeHelperUss(e3r)Contributed Perl DocumentMaotoisoenX::AttributeHelpers(3)
2
3
4
6 MooseX::AttributeHelpers - Extend your attribute interfaces
7 (deprecated)
8
10 package MyClass;
11 use Moose;
12 use MooseX::AttributeHelpers;
13
14 has 'mapping' => (
15 metaclass => 'Collection::Hash',
16 is => 'rw',
17 isa => 'HashRef[Str]',
18 default => sub { {} },
19 provides => {
20 exists => 'exists_in_mapping',
21 keys => 'ids_in_mapping',
22 get => 'get_mapping',
23 set => 'set_mapping',
24 },
25 curries => {
26 set => { set_quantity => [ 'quantity' ] }
27 }
28 );
29
30
31 # ...
32
33 my $obj = MyClass->new;
34 $obj->set_quantity(10); # quantity => 10
35 $obj->set_mapping(4, 'foo'); # 4 => 'foo'
36 $obj->set_mapping(5, 'bar'); # 5 => 'bar'
37 $obj->set_mapping(6, 'baz'); # 6 => 'baz'
38
39
40 # prints 'bar'
41 print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
42
43 # prints '4, 5, 6'
44 print join ', ', $obj->ids_in_mapping;
45
47 This distribution is deprecated. The features it provides have been
48 added to the Moose core code as Moose::Meta::Attribute::Native. This
49 distribution should not be used by any new code.
50
51 While Moose attributes provide you with a way to name your accessors,
52 readers, writers, clearers and predicates, this library provides
53 commonly used attribute helper methods for more specific types of data.
54
55 As seen in the "SYNOPSIS", you specify the extension via the
56 "metaclass" parameter. Available meta classes are:
57
59 provides
60 This points to a hashref that uses "provider" for the keys and "method"
61 for the values. The method will be added to the object itself and do
62 what you want.
63
64 curries
65 This points to a hashref that uses "provider" for the keys and has two
66 choices for the value:
67
68 You can supply "{method => [ @args ]}" for the values. The method will
69 be added to the object itself (always using @args as the beginning
70 arguments).
71
72 Another approach to curry a method provider is to supply a coderef
73 instead of an arrayref. The code ref takes $self, $body, and any
74 additional arguments passed to the final method.
75
76 # ...
77
78 curries => {
79 grep => {
80 times_with_day => sub {
81 my ($self, $body, $datetime) = @_;
82 $body->($self, sub { $_->ymd eq $datetime->ymd });
83 }
84 }
85 }
86
87 # ...
88
89 $obj->times_with_day(DateTime->now); # takes datetime argument, checks day
90
92 Number
93 Common numerical operations.
94
95 String
96 Common methods for string operations.
97
98 Counter
99 Methods for incrementing and decrementing a counter attribute.
100
101 Bool
102 Common methods for boolean values.
103
104 Collection::Hash
105 Common methods for hash references.
106
107 Collection::ImmutableHash
108 Common methods for inspecting hash references.
109
110 Collection::Array
111 Common methods for array references.
112
113 Collection::List
114 Common list methods for array references.
115
117 This is an early release of this module. Right now it is in great need
118 of documentation and tests in the test suite. However, we have used
119 this module to great success at $work where it has been tested very
120 thoroughly and deployed into a major production site.
121
122 I plan on getting better docs and tests in the next few releases, but
123 until then please refer to the few tests we do have and feel free email
124 and/or message me on irc.perl.org if you have any questions.
125
127 We need tests and docs badly.
128
130 All complex software has bugs lurking in it, and this module is no
131 exception. If you find a bug please either email me, or add the bug to
132 cpan-RT.
133
135 Stevan Little <stevan@iinteractive.com>
136
137 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
164 Copyright 2007-2009 by Infinity Interactive, Inc.
165
166 <http://www.iinteractive.com>
167
168 This library is free software; you can redistribute it and/or modify it
169 under the same terms as Perl itself.
170
171
172
173perl v5.12.0 2010-01-01 MooseX::AttributeHelpers(3)