| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::AttributeHelpers; # git description: v0.24-5-gb4c52f0 |
|
2
|
|
|
|
|
|
|
# ABSTRACT: (DEPRECATED) Extend your attribute interfaces |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
22
|
|
|
22
|
|
2333357
|
use Moose 0.56 (); |
|
|
22
|
|
|
|
|
6220137
|
|
|
|
22
|
|
|
|
|
741
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
22
|
|
|
22
|
|
11575
|
use MooseX::AttributeHelpers::Meta::Method::Provided; |
|
|
22
|
|
|
|
|
57
|
|
|
|
22
|
|
|
|
|
707
|
|
|
9
|
22
|
|
|
22
|
|
9304
|
use MooseX::AttributeHelpers::Meta::Method::Curried; |
|
|
22
|
|
|
|
|
45
|
|
|
|
22
|
|
|
|
|
691
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
22
|
|
|
22
|
|
8814
|
use MooseX::AttributeHelpers::Trait::Bool; |
|
|
22
|
|
|
|
|
77
|
|
|
|
22
|
|
|
|
|
807
|
|
|
12
|
22
|
|
|
22
|
|
9647
|
use MooseX::AttributeHelpers::Trait::Counter; |
|
|
22
|
|
|
|
|
57
|
|
|
|
22
|
|
|
|
|
747
|
|
|
13
|
22
|
|
|
22
|
|
9337
|
use MooseX::AttributeHelpers::Trait::Number; |
|
|
22
|
|
|
|
|
50
|
|
|
|
22
|
|
|
|
|
673
|
|
|
14
|
22
|
|
|
22
|
|
15414
|
use MooseX::AttributeHelpers::Trait::String; |
|
|
22
|
|
|
|
|
60
|
|
|
|
22
|
|
|
|
|
738
|
|
|
15
|
22
|
|
|
22
|
|
9244
|
use MooseX::AttributeHelpers::Trait::Collection::List; |
|
|
22
|
|
|
|
|
55
|
|
|
|
22
|
|
|
|
|
748
|
|
|
16
|
22
|
|
|
22
|
|
9018
|
use MooseX::AttributeHelpers::Trait::Collection::Array; |
|
|
22
|
|
|
|
|
60
|
|
|
|
22
|
|
|
|
|
717
|
|
|
17
|
22
|
|
|
22
|
|
9502
|
use MooseX::AttributeHelpers::Trait::Collection::Hash; |
|
|
22
|
|
|
|
|
62
|
|
|
|
22
|
|
|
|
|
737
|
|
|
18
|
22
|
|
|
22
|
|
9822
|
use MooseX::AttributeHelpers::Trait::Collection::ImmutableHash; |
|
|
22
|
|
|
|
|
56
|
|
|
|
22
|
|
|
|
|
705
|
|
|
19
|
22
|
|
|
22
|
|
9560
|
use MooseX::AttributeHelpers::Trait::Collection::Bag; |
|
|
22
|
|
|
|
|
66
|
|
|
|
22
|
|
|
|
|
748
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
22
|
|
|
22
|
|
9468
|
use MooseX::AttributeHelpers::Counter; |
|
|
22
|
|
|
|
|
70
|
|
|
|
22
|
|
|
|
|
876
|
|
|
22
|
22
|
|
|
22
|
|
9689
|
use MooseX::AttributeHelpers::Number; |
|
|
22
|
|
|
|
|
65
|
|
|
|
22
|
|
|
|
|
888
|
|
|
23
|
22
|
|
|
22
|
|
9465
|
use MooseX::AttributeHelpers::String; |
|
|
22
|
|
|
|
|
80
|
|
|
|
22
|
|
|
|
|
872
|
|
|
24
|
22
|
|
|
22
|
|
10364
|
use MooseX::AttributeHelpers::Bool; |
|
|
22
|
|
|
|
|
71
|
|
|
|
22
|
|
|
|
|
915
|
|
|
25
|
22
|
|
|
22
|
|
10435
|
use MooseX::AttributeHelpers::Collection::List; |
|
|
22
|
|
|
|
|
62
|
|
|
|
22
|
|
|
|
|
845
|
|
|
26
|
22
|
|
|
22
|
|
9787
|
use MooseX::AttributeHelpers::Collection::Array; |
|
|
22
|
|
|
|
|
65
|
|
|
|
22
|
|
|
|
|
931
|
|
|
27
|
22
|
|
|
22
|
|
10002
|
use MooseX::AttributeHelpers::Collection::Hash; |
|
|
22
|
|
|
|
|
68
|
|
|
|
22
|
|
|
|
|
2998
|
|
|
28
|
22
|
|
|
22
|
|
10138
|
use MooseX::AttributeHelpers::Collection::ImmutableHash; |
|
|
22
|
|
|
|
|
62
|
|
|
|
22
|
|
|
|
|
892
|
|
|
29
|
22
|
|
|
22
|
|
10304
|
use MooseX::AttributeHelpers::Collection::Bag; |
|
|
22
|
|
|
|
|
63
|
|
|
|
22
|
|
|
|
|
861
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=encoding UTF-8 |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
MooseX::AttributeHelpers - (DEPRECATED) Extend your attribute interfaces |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 VERSION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
version 0.25 |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
package MyClass; |
|
50
|
|
|
|
|
|
|
use Moose; |
|
51
|
|
|
|
|
|
|
use MooseX::AttributeHelpers; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has 'mapping' => ( |
|
54
|
|
|
|
|
|
|
metaclass => 'Collection::Hash', |
|
55
|
|
|
|
|
|
|
is => 'rw', |
|
56
|
|
|
|
|
|
|
isa => 'HashRef[Str]', |
|
57
|
|
|
|
|
|
|
default => sub { {} }, |
|
58
|
|
|
|
|
|
|
provides => { |
|
59
|
|
|
|
|
|
|
exists => 'exists_in_mapping', |
|
60
|
|
|
|
|
|
|
keys => 'ids_in_mapping', |
|
61
|
|
|
|
|
|
|
get => 'get_mapping', |
|
62
|
|
|
|
|
|
|
set => 'set_mapping', |
|
63
|
|
|
|
|
|
|
}, |
|
64
|
|
|
|
|
|
|
curries => { |
|
65
|
|
|
|
|
|
|
set => { set_quantity => [ 'quantity' ] } |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# ... |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $obj = MyClass->new; |
|
73
|
|
|
|
|
|
|
$obj->set_quantity(10); # quantity => 10 |
|
74
|
|
|
|
|
|
|
$obj->set_mapping(4, 'foo'); # 4 => 'foo' |
|
75
|
|
|
|
|
|
|
$obj->set_mapping(5, 'bar'); # 5 => 'bar' |
|
76
|
|
|
|
|
|
|
$obj->set_mapping(6, 'baz'); # 6 => 'baz' |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# prints 'bar' |
|
80
|
|
|
|
|
|
|
print $obj->get_mapping(5) if $obj->exists_in_mapping(5); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# prints '4, 5, 6' |
|
83
|
|
|
|
|
|
|
print join ', ', $obj->ids_in_mapping; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
B<This distribution is deprecated. The features it provides have been added to |
|
88
|
|
|
|
|
|
|
the Moose core code as L<Moose::Meta::Attribute::Native>. This distribution |
|
89
|
|
|
|
|
|
|
should not be used by any new code.> |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
While L<Moose> attributes provide you with a way to name your accessors, |
|
92
|
|
|
|
|
|
|
readers, writers, clearers and predicates, this library provides commonly |
|
93
|
|
|
|
|
|
|
used attribute helper methods for more specific types of data. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
As seen in the L</SYNOPSIS>, you specify the extension via the |
|
96
|
|
|
|
|
|
|
C<metaclass> parameter. Available meta classes are: |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 PARAMETERS |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 provides |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This points to a hashref that uses C<provider> for the keys and |
|
103
|
|
|
|
|
|
|
C<method> for the values. The method will be added to |
|
104
|
|
|
|
|
|
|
the object itself and do what you want. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 curries |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This points to a hashref that uses C<provider> for the keys and |
|
109
|
|
|
|
|
|
|
has two choices for the value: |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
You can supply C<< {method => [ @args ]} >> for the values. The method will be |
|
112
|
|
|
|
|
|
|
added to the object itself (always using C<@args> as the beginning arguments). |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Another approach to curry a method provider is to supply a coderef instead of an |
|
115
|
|
|
|
|
|
|
arrayref. The code ref takes C<$self>, C<$body>, and any additional arguments |
|
116
|
|
|
|
|
|
|
passed to the final method. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# ... |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
curries => { |
|
121
|
|
|
|
|
|
|
grep => { |
|
122
|
|
|
|
|
|
|
times_with_day => sub { |
|
123
|
|
|
|
|
|
|
my ($self, $body, $datetime) = @_; |
|
124
|
|
|
|
|
|
|
$body->($self, sub { $_->ymd eq $datetime->ymd }); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# ... |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$obj->times_with_day(DateTime->now); # takes datetime argument, checks day |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 METHOD PROVIDERS |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item L<Number|MooseX::AttributeHelpers::Number> |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Common numerical operations. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item L<String|MooseX::AttributeHelpers::String> |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Common methods for string operations. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item L<Counter|MooseX::AttributeHelpers::Counter> |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Methods for incrementing and decrementing a counter attribute. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item L<Bool|MooseX::AttributeHelpers::Bool> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Common methods for boolean values. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item L<Collection::Hash|MooseX::AttributeHelpers::Collection::Hash> |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Common methods for hash references. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item L<Collection::ImmutableHash|MooseX::AttributeHelpers::Collection::ImmutableHash> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Common methods for inspecting hash references. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item L<Collection::Array|MooseX::AttributeHelpers::Collection::Array> |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Common methods for array references. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item L<Collection::List|MooseX::AttributeHelpers::Collection::List> |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Common list methods for array references. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 DEPRECATION NOTICE |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The functionality in this family of modules is now implemented in the L<Moose> |
|
174
|
|
|
|
|
|
|
core as L<Moose::Meta::Attribute::Native|native attribute traits>. No more |
|
175
|
|
|
|
|
|
|
development is being done on MooseX::AttributeHelpers, so we encourage you to |
|
176
|
|
|
|
|
|
|
switch to native attribute traits. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SUPPORT |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> |
|
181
|
|
|
|
|
|
|
(or L<bug-MooseX-AttributeHelpers@rt.cpan.org|mailto:bug-MooseX-AttributeHelpers@rt.cpan.org>). |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
|
184
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
|
187
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 AUTHOR |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Stevan Little <stevan@iinteractive.com> |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=for stopwords Shawn M Moore Stevan Little Dave Rolsky Florian Ragwitz Yuval Kogman Jason May Karen Etheridge Cory G Watson Jesse Luehrs Robert Boone Bruno Vecchi Johannes Plunien Mike Whitaker Hans Dieter Pearcey Paul Driver 'phaylon' Sedlacek Evan Carroll Dagfinn Ilmari Mannsåker Chris Prather Tom Lanyon nperez |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=over 4 |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Shawn M Moore <sartak@gmail.com> |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Stevan Little <stevan.little@iinteractive.com> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Yuval Kogman <nothingmuch@woobling.org> |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Jason May <jason.a.may@gmail.com> |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item * |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Cory G Watson <gphat@onemogin.com> |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Jesse Luehrs <doy@tozt.net> |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item * |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Robert Boone <robo4288@gmail.com> |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item * |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Bruno Vecchi <vecchi.b@gmail.com> |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item * |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Johannes Plunien <plu@pqpq.de> |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item * |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Mike Whitaker <mike@altrion.org> |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item * |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@weftsoar.net> |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Paul Driver <frodwith@gmail.com> |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item * |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Robert 'phaylon' Sedlacek <rs@474.at> |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item * |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Evan Carroll <me@evancarroll.com> |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item * |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Chris Prather <cprather@hdpublishing.com> |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item * |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Tom Lanyon <tom@netspot.com.au> |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=item * |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item * |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
nperez <nperez@cpan.org> |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=back |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc. |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
294
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=cut |