File | /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers.pm |
Statements Executed | 67 |
Statement Execution Time | 2.83ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 633µs | 5.11ms | BEGIN@15 | MooseX::AttributeHelpers::
1 | 1 | 1 | 436µs | 7.04ms | BEGIN@14 | MooseX::AttributeHelpers::
1 | 1 | 1 | 399µs | 12.5ms | BEGIN@21 | MooseX::AttributeHelpers::
1 | 1 | 1 | 380µs | 6.40ms | BEGIN@16 | MooseX::AttributeHelpers::
1 | 1 | 1 | 352µs | 12.7ms | BEGIN@30 | MooseX::AttributeHelpers::
1 | 1 | 1 | 308µs | 14.5ms | BEGIN@13 | MooseX::AttributeHelpers::
1 | 1 | 1 | 293µs | 11.9ms | BEGIN@31 | MooseX::AttributeHelpers::
1 | 1 | 1 | 292µs | 11.3ms | BEGIN@28 | MooseX::AttributeHelpers::
1 | 1 | 1 | 277µs | 11.5ms | BEGIN@18 | MooseX::AttributeHelpers::
1 | 1 | 1 | 276µs | 10.2ms | BEGIN@24 | MooseX::AttributeHelpers::
1 | 1 | 1 | 275µs | 11.0ms | BEGIN@27 | MooseX::AttributeHelpers::
1 | 1 | 1 | 274µs | 11.5ms | BEGIN@29 | MooseX::AttributeHelpers::
1 | 1 | 1 | 268µs | 4.03ms | BEGIN@20 | MooseX::AttributeHelpers::
1 | 1 | 1 | 260µs | 13.5ms | BEGIN@23 | MooseX::AttributeHelpers::
1 | 1 | 1 | 250µs | 11.0ms | BEGIN@25 | MooseX::AttributeHelpers::
1 | 1 | 1 | 248µs | 11.2ms | BEGIN@26 | MooseX::AttributeHelpers::
1 | 1 | 1 | 247µs | 12.0ms | BEGIN@19 | MooseX::AttributeHelpers::
1 | 1 | 1 | 245µs | 9.92ms | BEGIN@17 | MooseX::AttributeHelpers::
1 | 1 | 1 | 191µs | 2.72ms | BEGIN@10 | MooseX::AttributeHelpers::
1 | 1 | 1 | 177µs | 2.47ms | BEGIN@11 | MooseX::AttributeHelpers::
1 | 1 | 1 | 19µs | 40µs | BEGIN@8 | MooseX::AttributeHelpers::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package MooseX::AttributeHelpers; | ||||
3 | |||||
4 | 1 | 900ns | our $VERSION = '0.23'; | ||
5 | 1 | 15µs | $VERSION = eval $VERSION; | ||
6 | 1 | 400ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
7 | |||||
8 | 3 | 53µs | 2 | 60µs | # spent 40µs (19+21) within MooseX::AttributeHelpers::BEGIN@8 which was called
# once (19µs+21µs) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 8 # spent 40µs making 1 call to MooseX::AttributeHelpers::BEGIN@8
# spent 21µs making 1 call to UNIVERSAL::VERSION |
9 | |||||
10 | 3 | 127µs | 1 | 2.72ms | # spent 2.72ms (191µs+2.53) within MooseX::AttributeHelpers::BEGIN@10 which was called
# once (191µs+2.53ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 10 # spent 2.72ms making 1 call to MooseX::AttributeHelpers::BEGIN@10 |
11 | 3 | 114µs | 1 | 2.47ms | # spent 2.47ms (177µs+2.29) within MooseX::AttributeHelpers::BEGIN@11 which was called
# once (177µs+2.29ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 11 # spent 2.47ms making 1 call to MooseX::AttributeHelpers::BEGIN@11 |
12 | |||||
13 | 3 | 116µs | 1 | 14.5ms | # spent 14.5ms (308µs+14.2) within MooseX::AttributeHelpers::BEGIN@13 which was called
# once (308µs+14.2ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 13 # spent 14.5ms making 1 call to MooseX::AttributeHelpers::BEGIN@13 |
14 | 3 | 143µs | 1 | 7.04ms | # spent 7.04ms (436µs+6.60) within MooseX::AttributeHelpers::BEGIN@14 which was called
# once (436µs+6.60ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 14 # spent 7.04ms making 1 call to MooseX::AttributeHelpers::BEGIN@14 |
15 | 3 | 160µs | 1 | 5.11ms | # spent 5.11ms (633µs+4.47) within MooseX::AttributeHelpers::BEGIN@15 which was called
# once (633µs+4.47ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 15 # spent 5.11ms making 1 call to MooseX::AttributeHelpers::BEGIN@15 |
16 | 3 | 111µs | 1 | 6.40ms | # spent 6.40ms (380µs+6.02) within MooseX::AttributeHelpers::BEGIN@16 which was called
# once (380µs+6.02ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 16 # spent 6.40ms making 1 call to MooseX::AttributeHelpers::BEGIN@16 |
17 | 3 | 113µs | 1 | 9.92ms | # spent 9.92ms (245µs+9.68) within MooseX::AttributeHelpers::BEGIN@17 which was called
# once (245µs+9.68ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 17 # spent 9.92ms making 1 call to MooseX::AttributeHelpers::BEGIN@17 |
18 | 3 | 121µs | 1 | 11.5ms | # spent 11.5ms (277µs+11.2) within MooseX::AttributeHelpers::BEGIN@18 which was called
# once (277µs+11.2ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 18 # spent 11.5ms making 1 call to MooseX::AttributeHelpers::BEGIN@18 |
19 | 3 | 112µs | 1 | 12.0ms | # spent 12.0ms (247µs+11.7) within MooseX::AttributeHelpers::BEGIN@19 which was called
# once (247µs+11.7ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 19 # spent 12.0ms making 1 call to MooseX::AttributeHelpers::BEGIN@19 |
20 | 3 | 125µs | 1 | 4.03ms | # spent 4.03ms (268µs+3.76) within MooseX::AttributeHelpers::BEGIN@20 which was called
# once (268µs+3.76ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 20 # spent 4.03ms making 1 call to MooseX::AttributeHelpers::BEGIN@20 |
21 | 3 | 125µs | 1 | 12.5ms | # spent 12.5ms (399µs+12.1) within MooseX::AttributeHelpers::BEGIN@21 which was called
# once (399µs+12.1ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 21 # spent 12.5ms making 1 call to MooseX::AttributeHelpers::BEGIN@21 |
22 | |||||
23 | 3 | 131µs | 1 | 13.5ms | # spent 13.5ms (260µs+13.2) within MooseX::AttributeHelpers::BEGIN@23 which was called
# once (260µs+13.2ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 23 # spent 13.5ms making 1 call to MooseX::AttributeHelpers::BEGIN@23 |
24 | 3 | 140µs | 1 | 10.2ms | # spent 10.2ms (276µs+9.92) within MooseX::AttributeHelpers::BEGIN@24 which was called
# once (276µs+9.92ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 24 # spent 10.2ms making 1 call to MooseX::AttributeHelpers::BEGIN@24 |
25 | 3 | 136µs | 1 | 11.0ms | # spent 11.0ms (250µs+10.8) within MooseX::AttributeHelpers::BEGIN@25 which was called
# once (250µs+10.8ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 25 # spent 11.0ms making 1 call to MooseX::AttributeHelpers::BEGIN@25 |
26 | 3 | 131µs | 1 | 11.2ms | # spent 11.2ms (248µs+11.0) within MooseX::AttributeHelpers::BEGIN@26 which was called
# once (248µs+11.0ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 26 # spent 11.2ms making 1 call to MooseX::AttributeHelpers::BEGIN@26 |
27 | 3 | 139µs | 1 | 11.0ms | # spent 11.0ms (275µs+10.7) within MooseX::AttributeHelpers::BEGIN@27 which was called
# once (275µs+10.7ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 27 # spent 11.0ms making 1 call to MooseX::AttributeHelpers::BEGIN@27 |
28 | 3 | 170µs | 1 | 11.3ms | # spent 11.3ms (292µs+11.0) within MooseX::AttributeHelpers::BEGIN@28 which was called
# once (292µs+11.0ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 28 # spent 11.3ms making 1 call to MooseX::AttributeHelpers::BEGIN@28 |
29 | 3 | 151µs | 1 | 11.5ms | # spent 11.5ms (274µs+11.2) within MooseX::AttributeHelpers::BEGIN@29 which was called
# once (274µs+11.2ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 29 # spent 11.5ms making 1 call to MooseX::AttributeHelpers::BEGIN@29 |
30 | 3 | 188µs | 1 | 12.7ms | # spent 12.7ms (352µs+12.3) within MooseX::AttributeHelpers::BEGIN@30 which was called
# once (352µs+12.3ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 30 # spent 12.7ms making 1 call to MooseX::AttributeHelpers::BEGIN@30 |
31 | 3 | 198µs | 1 | 11.9ms | # spent 11.9ms (293µs+11.6) within MooseX::AttributeHelpers::BEGIN@31 which was called
# once (293µs+11.6ms) by MooseX::ClassAttribute::Role::Meta::Class::BEGIN@6 at line 31 # spent 11.9ms making 1 call to MooseX::AttributeHelpers::BEGIN@31 |
32 | |||||
33 | 1 | 5µs | 1; | ||
34 | |||||
35 | __END__ | ||||
36 | |||||
37 | =pod | ||||
38 | |||||
39 | =head1 NAME | ||||
40 | |||||
41 | MooseX::AttributeHelpers - Extend your attribute interfaces (deprecated) | ||||
42 | |||||
43 | =head1 SYNOPSIS | ||||
44 | |||||
45 | package MyClass; | ||||
46 | use Moose; | ||||
47 | use MooseX::AttributeHelpers; | ||||
48 | |||||
49 | has 'mapping' => ( | ||||
50 | metaclass => 'Collection::Hash', | ||||
51 | is => 'rw', | ||||
52 | isa => 'HashRef[Str]', | ||||
53 | default => sub { {} }, | ||||
54 | provides => { | ||||
55 | exists => 'exists_in_mapping', | ||||
56 | keys => 'ids_in_mapping', | ||||
57 | get => 'get_mapping', | ||||
58 | set => 'set_mapping', | ||||
59 | }, | ||||
60 | curries => { | ||||
61 | set => { set_quantity => [ 'quantity' ] } | ||||
62 | } | ||||
63 | ); | ||||
64 | |||||
65 | |||||
66 | # ... | ||||
67 | |||||
68 | my $obj = MyClass->new; | ||||
69 | $obj->set_quantity(10); # quantity => 10 | ||||
70 | $obj->set_mapping(4, 'foo'); # 4 => 'foo' | ||||
71 | $obj->set_mapping(5, 'bar'); # 5 => 'bar' | ||||
72 | $obj->set_mapping(6, 'baz'); # 6 => 'baz' | ||||
73 | |||||
74 | |||||
75 | # prints 'bar' | ||||
76 | print $obj->get_mapping(5) if $obj->exists_in_mapping(5); | ||||
77 | |||||
78 | # prints '4, 5, 6' | ||||
79 | print join ', ', $obj->ids_in_mapping; | ||||
80 | |||||
81 | =head1 DESCRIPTION | ||||
82 | |||||
83 | B<This distribution is deprecated. The features it provides have been added to | ||||
84 | the Moose core code as L<Moose::Meta::Attribute::Native>. This distribution | ||||
85 | should not be used by any new code.> | ||||
86 | |||||
87 | While L<Moose> attributes provide you with a way to name your accessors, | ||||
88 | readers, writers, clearers and predicates, this library provides commonly | ||||
89 | used attribute helper methods for more specific types of data. | ||||
90 | |||||
91 | As seen in the L</SYNOPSIS>, you specify the extension via the | ||||
92 | C<metaclass> parameter. Available meta classes are: | ||||
93 | |||||
94 | =head1 PARAMETERS | ||||
95 | |||||
96 | =head2 provides | ||||
97 | |||||
98 | This points to a hashref that uses C<provider> for the keys and | ||||
99 | C<method> for the values. The method will be added to | ||||
100 | the object itself and do what you want. | ||||
101 | |||||
102 | =head2 curries | ||||
103 | |||||
104 | This points to a hashref that uses C<provider> for the keys and | ||||
105 | has two choices for the value: | ||||
106 | |||||
107 | You can supply C<< {method => [ @args ]} >> for the values. The method will be | ||||
108 | added to the object itself (always using C<@args> as the beginning arguments). | ||||
109 | |||||
110 | Another approach to curry a method provider is to supply a coderef instead of an | ||||
111 | arrayref. The code ref takes C<$self>, C<$body>, and any additional arguments | ||||
112 | passed to the final method. | ||||
113 | |||||
114 | # ... | ||||
115 | |||||
116 | curries => { | ||||
117 | grep => { | ||||
118 | times_with_day => sub { | ||||
119 | my ($self, $body, $datetime) = @_; | ||||
120 | $body->($self, sub { $_->ymd eq $datetime->ymd }); | ||||
121 | } | ||||
122 | } | ||||
123 | } | ||||
124 | |||||
125 | # ... | ||||
126 | |||||
127 | $obj->times_with_day(DateTime->now); # takes datetime argument, checks day | ||||
128 | |||||
129 | |||||
130 | =head1 METHOD PROVIDERS | ||||
131 | |||||
132 | =over | ||||
133 | |||||
134 | =item L<Number|MooseX::AttributeHelpers::Number> | ||||
135 | |||||
136 | Common numerical operations. | ||||
137 | |||||
138 | =item L<String|MooseX::AttributeHelpers::String> | ||||
139 | |||||
140 | Common methods for string operations. | ||||
141 | |||||
142 | =item L<Counter|MooseX::AttributeHelpers::Counter> | ||||
143 | |||||
144 | Methods for incrementing and decrementing a counter attribute. | ||||
145 | |||||
146 | =item L<Bool|MooseX::AttributeHelpers::Bool> | ||||
147 | |||||
148 | Common methods for boolean values. | ||||
149 | |||||
150 | =item L<Collection::Hash|MooseX::AttributeHelpers::Collection::Hash> | ||||
151 | |||||
152 | Common methods for hash references. | ||||
153 | |||||
154 | =item L<Collection::ImmutableHash|MooseX::AttributeHelpers::Collection::ImmutableHash> | ||||
155 | |||||
156 | Common methods for inspecting hash references. | ||||
157 | |||||
158 | =item L<Collection::Array|MooseX::AttributeHelpers::Collection::Array> | ||||
159 | |||||
160 | Common methods for array references. | ||||
161 | |||||
162 | =item L<Collection::List|MooseX::AttributeHelpers::Collection::List> | ||||
163 | |||||
164 | Common list methods for array references. | ||||
165 | |||||
166 | =back | ||||
167 | |||||
168 | =head1 CAVEAT | ||||
169 | |||||
170 | This is an early release of this module. Right now it is in great need | ||||
171 | of documentation and tests in the test suite. However, we have used this | ||||
172 | module to great success at C<$work> where it has been tested very thoroughly | ||||
173 | and deployed into a major production site. | ||||
174 | |||||
175 | I plan on getting better docs and tests in the next few releases, but until | ||||
176 | then please refer to the few tests we do have and feel free email and/or | ||||
177 | message me on irc.perl.org if you have any questions. | ||||
178 | |||||
179 | =head1 TODO | ||||
180 | |||||
181 | We need tests and docs badly. | ||||
182 | |||||
183 | =head1 BUGS | ||||
184 | |||||
185 | All complex software has bugs lurking in it, and this module is no | ||||
186 | exception. If you find a bug please either email me, or add the bug | ||||
187 | to cpan-RT. | ||||
188 | |||||
189 | =head1 AUTHOR | ||||
190 | |||||
191 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
192 | |||||
193 | B<with contributions from:> | ||||
194 | |||||
195 | Robert (rlb3) Boone | ||||
196 | |||||
197 | Paul (frodwith) Driver | ||||
198 | |||||
199 | Shawn (Sartak) Moore | ||||
200 | |||||
201 | Chris (perigrin) Prather | ||||
202 | |||||
203 | Robert (phaylon) Sedlacek | ||||
204 | |||||
205 | Tom (dec) Lanyon | ||||
206 | |||||
207 | Yuval Kogman | ||||
208 | |||||
209 | Jason May | ||||
210 | |||||
211 | Cory (gphat) Watson | ||||
212 | |||||
213 | Florian (rafl) Ragwitz | ||||
214 | |||||
215 | Evan Carroll | ||||
216 | |||||
217 | Jesse (doy) Luehrs | ||||
218 | |||||
219 | =head1 COPYRIGHT AND LICENSE | ||||
220 | |||||
221 | Copyright 2007-2009 by Infinity Interactive, Inc. | ||||
222 | |||||
223 | L<http://www.iinteractive.com> | ||||
224 | |||||
225 | This library is free software; you can redistribute it and/or modify | ||||
226 | it under the same terms as Perl itself. | ||||
227 | |||||
228 | =cut |