← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:10 2010

File /usr/local/lib/perl/5.10.0/Class/MOP/Method/Accessor.pm
Statements Executed 4281
Total Time 0.0173877 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
177114.34ms44.3msClass::MOP::Method::Accessor::::newClass::MOP::Method::Accessor::new
223223.90ms3.90msClass::MOP::Method::Accessor::::_newClass::MOP::Method::Accessor::_new
177112.04ms31.6msClass::MOP::Method::Accessor::::_initialize_bodyClass::MOP::Method::Accessor::_initialize_body
5211631µs11.1msClass::MOP::Method::Accessor::::_generate_reader_method_inlineClass::MOP::Method::Accessor::_generate_reader_method_inline
5211554µs768µsClass::MOP::Method::Accessor::::_generate_reader_methodClass::MOP::Method::Accessor::_generate_reader_method
1511235µs4.60msClass::MOP::Method::Accessor::::_generate_accessor_method_inlineClass::MOP::Method::Accessor::_generate_accessor_method_inline
1311187µs1.79msClass::MOP::Method::Accessor::::_generate_predicate_method_inlineClass::MOP::Method::Accessor::_generate_predicate_method_inline
1511158µs216µsClass::MOP::Method::Accessor::::_generate_accessor_methodClass::MOP::Method::Accessor::_generate_accessor_method
1311143µs183µsClass::MOP::Method::Accessor::::_generate_predicate_methodClass::MOP::Method::Accessor::_generate_predicate_method
31156µs443µsClass::MOP::Method::Accessor::::_generate_writer_method_inlineClass::MOP::Method::Accessor::_generate_writer_method_inline
31128µs39µsClass::MOP::Method::Accessor::::_generate_writer_methodClass::MOP::Method::Accessor::_generate_writer_method
0000s0sClass::MOP::Method::Accessor::::BEGINClass::MOP::Method::Accessor::BEGIN
0000s0sClass::MOP::Method::Accessor::::__ANON__[:105]Class::MOP::Method::Accessor::__ANON__[:105]
0000s0sClass::MOP::Method::Accessor::::__ANON__[:113]Class::MOP::Method::Accessor::__ANON__[:113]
0000s0sClass::MOP::Method::Accessor::::__ANON__[:120]Class::MOP::Method::Accessor::__ANON__[:120]
0000s0sClass::MOP::Method::Accessor::::__ANON__[:127]Class::MOP::Method::Accessor::__ANON__[:127]
0000s0sClass::MOP::Method::Accessor::::__ANON__[:97]Class::MOP::Method::Accessor::__ANON__[:97]
0000s0sClass::MOP::Method::Accessor::::_generate_clearer_methodClass::MOP::Method::Accessor::_generate_clearer_method
0000s0sClass::MOP::Method::Accessor::::_generate_clearer_method_inlineClass::MOP::Method::Accessor::_generate_clearer_method_inline
LineStmts.Exclusive
Time
Avg.Code
1
2package Class::MOP::Method::Accessor;
3
4329µs10µsuse strict;
# spent 12µs making 1 call to strict::import
5324µs8µsuse warnings;
# spent 18µs making 1 call to warnings::import
6
7338µs12µsuse Carp 'confess';
# spent 50µs making 1 call to Exporter::import
8363µs21µsuse Scalar::Util 'blessed', 'weaken';
# spent 43µs making 1 call to Exporter::import
9
101700ns700nsour $VERSION = '1.09';
11126µs26µs$VERSION = eval $VERSION;
121600ns600nsour $AUTHORITY = 'cpan:STEVAN';
13
1431.06ms355µsuse base 'Class::MOP::Method::Generated';
# spent 1.18ms making 1 call to base::import
15
16
# spent 44.3ms (4.34+39.9) within Class::MOP::Method::Accessor::new which was called 177 times, avg 250µs/call: # 177 times (4.34ms+39.9ms) by Class::MOP::Attribute::_process_accessors or Class::MOP::Attribute::__ANON__[/usr/local/lib/perl/5.10.0/Class/MOP/Attribute.pm:342] at line 334 of /usr/local/lib/perl/5.10.0/Class/MOP/Attribute.pm, avg 250µs/call
sub new {
1717706.61ms4µs my $class = shift;
18 my %options = @_;
19
20 (exists $options{attribute})
21 || confess "You must supply an attribute to construct with";
22
23 (exists $options{accessor_type})
24 || confess "You must supply an accessor_type to construct with";
25
26 (blessed($options{attribute}) && $options{attribute}->isa('Class::MOP::Attribute'))
# spent 609µs making 177 calls to UNIVERSAL::isa, avg 3µs/call # spent 578µs making 177 calls to Scalar::Util::blessed, avg 3µs/call
27 || confess "You must supply an attribute which is a 'Class::MOP::Attribute' instance";
28
29 ($options{package_name} && $options{name})
30 || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
31
32 my $self = $class->_new(\%options);
# spent 2.90ms making 166 calls to Class::MOP::Method::Accessor::_new, avg 17µs/call # spent 2.70ms making 2 calls to Class::MOP::Method::_new, avg 1.35ms/call # spent 787µs making 9 calls to Moose::Meta::Method::Accessor::_new, avg 87µs/call
33
34 # we don't want this creating
35 # a cycle in the code, if not
36 # needed
37 weaken($self->{'attribute'});
# spent 740µs making 177 calls to Scalar::Util::weaken, avg 4µs/call
38
39 $self->_initialize_body;
# spent 31.6ms making 177 calls to Class::MOP::Method::Accessor::_initialize_body, avg 179µs/call
40
41 return $self;
42}
43
44
# spent 3.90ms within Class::MOP::Method::Accessor::_new which was called 223 times, avg 17µs/call: # 166 times (2.90ms+0s) by Class::MOP::Method::Accessor::new at line 32, avg 17µs/call # 57 times (1.01ms+0s) by Class::MOP::Method::wrap at line 44 of /usr/local/lib/perl/5.10.0/Class/MOP/Method.pm, avg 18µs/call
sub _new {
458923.45ms4µs my $class = shift;
46
47 return Class::MOP::Class->initialize($class)->new_object(@_)
48 if $class ne __PACKAGE__;
49
50 my $params = @_ == 1 ? $_[0] : {@_};
51
52 return bless {
53 # inherited from Class::MOP::Method
54 body => $params->{body},
55 associated_metaclass => $params->{associated_metaclass},
56 package_name => $params->{package_name},
57 name => $params->{name},
58 original_method => $params->{original_method},
59
60 # inherit from Class::MOP::Generated
61 is_inline => $params->{is_inline} || 0,
62 definition_context => $params->{definition_context},
63
64 # defined in this class
65 attribute => $params->{attribute},
66 accessor_type => $params->{accessor_type},
67 } => $class;
68}
69
70## accessors
71
72293467µs2µssub associated_attribute { (shift)->{'attribute'} }
73177311µs2µssub accessor_type { (shift)->{'accessor_type'} }
74
75## factory
76
77
# spent 31.6ms (2.04+29.6) within Class::MOP::Method::Accessor::_initialize_body which was called 177 times, avg 179µs/call: # 177 times (2.04ms+29.6ms) by Class::MOP::Method::Accessor::new at line 39, avg 179µs/call
sub _initialize_body {
785312.93ms6µs my $self = shift;
79
80 my $method_name = join "_" => (
# spent 689µs making 177 calls to Class::MOP::Method::Accessor::accessor_type, avg 4µs/call # spent 662µs making 177 calls to Class::MOP::Method::Generated::is_inline, avg 4µs/call
81 '_generate',
82 $self->accessor_type,
83 'method',
84 ($self->is_inline ? 'inline' : ())
85 );
86
87 $self->{'body'} = $self->$method_name();
# spent 11.1ms making 52 calls to Class::MOP::Method::Accessor::_generate_reader_method_inline, avg 213µs/call # spent 6.26ms making 7 calls to Moose::Meta::Method::Accessor::_generate_accessor_method, avg 895µs/call # spent 4.60ms making 15 calls to Class::MOP::Method::Accessor::_generate_accessor_method_inline, avg 307µs/call # spent 1.79ms making 13 calls to Class::MOP::Method::Accessor::_generate_predicate_method_inline, avg 138µs/call # spent 1.52ms making 2 calls to Moose::Meta::Method::Accessor::_generate_reader_method, avg 758µs/call # spent 768µs making 52 calls to Class::MOP::Method::Accessor::_generate_reader_method, avg 15µs/call # spent 767µs making 1 call to Moose::Meta::Method::Accessor::_generate_writer_method # spent 555µs making 1 call to Moose::Meta::Method::Accessor::_generate_reader_method_inline # spent 443µs making 3 calls to Class::MOP::Method::Accessor::_generate_writer_method_inline, avg 148µs/call # spent 216µs making 15 calls to Class::MOP::Method::Accessor::_generate_accessor_method, avg 14µs/call # spent 183µs making 13 calls to Class::MOP::Method::Accessor::_generate_predicate_method, avg 14µs/call # spent 39µs making 3 calls to Class::MOP::Method::Accessor::_generate_writer_method, avg 13µs/call
88}
89
90## generators
91
92
# spent 216µs (158+59) within Class::MOP::Method::Accessor::_generate_accessor_method which was called 15 times, avg 14µs/call: # 15 times (158µs+59µs) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 14µs/call
sub _generate_accessor_method {
9330147µs5µs my $attr = (shift)->associated_attribute;
# spent 59µs making 15 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
94 return sub {
95 $attr->set_value($_[0], $_[1]) if scalar(@_) == 2;
96 $attr->get_value($_[0]);
97 };
98}
99
100
# spent 768µs (554+214) within Class::MOP::Method::Accessor::_generate_reader_method which was called 52 times, avg 15µs/call: # 52 times (554µs+214µs) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 15µs/call
sub _generate_reader_method {
101104513µs5µs my $attr = (shift)->associated_attribute;
# spent 214µs making 52 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
102 return sub {
1031646µs3µs confess "Cannot assign a value to a read-only accessor" if @_ > 1;
104 $attr->get_value($_[0]);
# spent 362µs making 8 calls to Class::MOP::Attribute::get_value, avg 45µs/call
105 };
106}
107
108
109
# spent 39µs (28+11) within Class::MOP::Method::Accessor::_generate_writer_method which was called 3 times, avg 13µs/call: # 3 times (28µs+11µs) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 13µs/call
sub _generate_writer_method {
110624µs4µs my $attr = (shift)->associated_attribute;
# spent 11µs making 3 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
111 return sub {
112 $attr->set_value($_[0], $_[1]);
113 };
114}
115
116
# spent 183µs (143+40) within Class::MOP::Method::Accessor::_generate_predicate_method which was called 13 times, avg 14µs/call: # 13 times (143µs+40µs) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 14µs/call
sub _generate_predicate_method {
11726131µs5µs my $attr = (shift)->associated_attribute;
# spent 40µs making 13 calls to Class::MOP::Method::Accessor::associated_attribute, avg 3µs/call
118 return sub {
119213µs7µs $attr->has_value($_[0])
# spent 113µs making 2 calls to Class::MOP::Attribute::has_value, avg 56µs/call
120 };
121}
122
123sub _generate_clearer_method {
124 my $attr = (shift)->associated_attribute;
125 return sub {
126 $attr->clear_value($_[0])
127 };
128}
129
130## Inline methods
131
132
# spent 4.60ms (235µs+4.37) within Class::MOP::Method::Accessor::_generate_accessor_method_inline which was called 15 times, avg 307µs/call: # 15 times (235µs+4.37ms) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 307µs/call
sub _generate_accessor_method_inline {
13375335µs4µs my $self = shift;
134 my $attr = $self->associated_attribute;
# spent 55µs making 15 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
135
136 my ( $code, $e ) = $self->_eval_closure(
# spent 2.20ms making 15 calls to Class::MOP::Attribute::inline_set, avg 146µs/call # spent 1.65ms making 15 calls to Class::MOP::Method::Generated::_eval_closure, avg 110µs/call # spent 469µs making 15 calls to Class::MOP::Attribute::inline_get, avg 31µs/call
137 {},
138 'sub {'
139 . $attr->inline_set( '$_[0]', '$_[1]' )
140 . ' if scalar(@_) == 2; '
141 . $attr->inline_get('$_[0]') . '}'
142 );
143 confess "Could not generate inline accessor because : $e" if $e;
144
145 return $code;
146}
147
148
# spent 11.1ms (631µs+10.5) within Class::MOP::Method::Accessor::_generate_reader_method_inline which was called 52 times, avg 213µs/call: # 52 times (631µs+10.5ms) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 213µs/call
sub _generate_reader_method_inline {
149260869µs3µs my $self = shift;
150 my $attr = $self->associated_attribute;
# spent 187µs making 52 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
151
152 my ( $code, $e ) = $self->_eval_closure(
# spent 5.36ms making 52 calls to Class::MOP::Method::Generated::_eval_closure, avg 103µs/call # spent 4.91ms making 52 calls to Class::MOP::Attribute::inline_get, avg 94µs/call
153 {},
154 'sub {'
155 . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;'
156 . $attr->inline_get('$_[0]') . '}'
157 );
158 confess "Could not generate inline reader because : $e" if $e;
159
160 return $code;
161}
162
163
# spent 443µs (56+387) within Class::MOP::Method::Accessor::_generate_writer_method_inline which was called 3 times, avg 148µs/call: # 3 times (56µs+387µs) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 148µs/call
sub _generate_writer_method_inline {
1641562µs4µs my $self = shift;
165 my $attr = $self->associated_attribute;
# spent 11µs making 3 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
166
167 my ( $code, $e ) = $self->_eval_closure(
# spent 275µs making 3 calls to Class::MOP::Method::Generated::_eval_closure, avg 92µs/call # spent 101µs making 3 calls to Class::MOP::Attribute::inline_set, avg 34µs/call
168 {},
169 'sub {' . $attr->inline_set( '$_[0]', '$_[1]' ) . '}'
170 );
171 confess "Could not generate inline writer because : $e" if $e;
172
173 return $code;
174}
175
176
# spent 1.79ms (187µs+1.60) within Class::MOP::Method::Accessor::_generate_predicate_method_inline which was called 13 times, avg 138µs/call: # 13 times (187µs+1.60ms) by Class::MOP::Method::Accessor::_initialize_body at line 87, avg 138µs/call
sub _generate_predicate_method_inline {
17765242µs4µs my $self = shift;
178 my $attr = $self->associated_attribute;
# spent 43µs making 13 calls to Class::MOP::Method::Accessor::associated_attribute, avg 3µs/call
179
180 my ( $code, $e ) = $self->_eval_closure(
# spent 1.10ms making 13 calls to Class::MOP::Method::Generated::_eval_closure, avg 85µs/call # spent 458µs making 13 calls to Class::MOP::Attribute::inline_has, avg 35µs/call
181 {},
182 'sub {' . $attr->inline_has('$_[0]') . '}'
183 );
184 confess "Could not generate inline predicate because : $e" if $e;
185
186 return $code;
187}
188
189sub _generate_clearer_method_inline {
190 my $self = shift;
191 my $attr = $self->associated_attribute;
192
193 my ( $code, $e ) = $self->_eval_closure(
194 {},
195 'sub {' . $attr->inline_clear('$_[0]') . '}'
196 );
197 confess "Could not generate inline clearer because : $e" if $e;
198
199 return $code;
200}
201
20214µs4µs1;
203
204__END__
205
206=pod
207
208=head1 NAME
209
210Class::MOP::Method::Accessor - Method Meta Object for accessors
211
212=head1 SYNOPSIS
213
214 use Class::MOP::Method::Accessor;
215
216 my $reader = Class::MOP::Method::Accessor->new(
217 attribute => $attribute,
218 is_inline => 1,
219 accessor_type => 'reader',
220 );
221
222 $reader->body->execute($instance); # call the reader method
223
224=head1 DESCRIPTION
225
226This is a subclass of C<Class::MOP::Method> which is used by
227C<Class::MOP::Attribute> to generate accessor code. It handles
228generation of readers, writers, predicates and clearers. For each type
229of method, it can either create a subroutine reference, or actually
230inline code by generating a string and C<eval>'ing it.
231
232=head1 METHODS
233
234=over 4
235
236=item B<< Class::MOP::Method::Accessor->new(%options) >>
237
238This returns a new C<Class::MOP::Method::Accessor> based on the
239C<%options> provided.
240
241=over 4
242
243=item * attribute
244
245This is the C<Class::MOP::Attribute> for which accessors are being
246generated. This option is required.
247
248=item * accessor_type
249
250This is a string which should be one of "reader", "writer",
251"accessor", "predicate", or "clearer". This is the type of method
252being generated. This option is required.
253
254=item * is_inline
255
256This indicates whether or not the accessor should be inlined. This
257defaults to false.
258
259=item * name
260
261The method name (without a package name). This is required.
262
263=item * package_name
264
265The package name for the method. This is required.
266
267=back
268
269=item B<< $metamethod->accessor_type >>
270
271Returns the accessor type which was passed to C<new>.
272
273=item B<< $metamethod->is_inline >>
274
275Returns a boolean indicating whether or not the accessor is inlined.
276
277=item B<< $metamethod->associated_attribute >>
278
279This returns the L<Class::MOP::Attribute> object which was passed to
280C<new>.
281
282=item B<< $metamethod->body >>
283
284The method itself is I<generated> when the accessor object is
285constructed.
286
287=back
288
289=head1 AUTHORS
290
291Stevan Little E<lt>stevan@iinteractive.comE<gt>
292
293=head1 COPYRIGHT AND LICENSE
294
295Copyright 2006-2010 by Infinity Interactive, Inc.
296
297L<http://www.iinteractive.com>
298
299This library is free software; you can redistribute it and/or modify
300it under the same terms as Perl itself.
301
302=cut
303