← Index
NYTProf Performance Profile   « block view • line view • sub view »
For conv.pl
  Run on Sun Nov 14 21:14:18 2010
Reported on Sun Nov 14 21:17:55 2010

Filename/usr/share/perl5/Class/Accessor.pm
StatementsExecuted 116 statements in 2.05ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111292µs407µsClass::Accessor::::_mk_accessorsClass::Accessor::_mk_accessors
61151µs51µsClass::Accessor::::make_accessorClass::Accessor::make_accessor
61140µs40µsClass::Accessor::::accessor_name_forClass::Accessor::accessor_name_for
11125µs432µsClass::Accessor::::mk_accessorsClass::Accessor::mk_accessors
61124µs24µsClass::Accessor::::mutator_name_forClass::Accessor::mutator_name_for
11122µs28µsClass::Accessor::::BEGIN@3Class::Accessor::BEGIN@3
11114µs42µsClass::Accessor::::BEGIN@150Class::Accessor::BEGIN@150
11110µs10µsClass::Accessor::::BEGIN@460Class::Accessor::BEGIN@460
0000s0sClass::Accessor::::__ANON__[:395]Class::Accessor::__ANON__[:395]
0000s0sClass::Accessor::::__ANON__[:422]Class::Accessor::__ANON__[:422]
0000s0sClass::Accessor::::__ANON__[:449]Class::Accessor::__ANON__[:449]
0000s0sClass::Accessor::::_carpClass::Accessor::_carp
0000s0sClass::Accessor::::_croakClass::Accessor::_croak
0000s0sClass::Accessor::::best_practice_accessor_name_forClass::Accessor::best_practice_accessor_name_for
0000s0sClass::Accessor::::best_practice_mutator_name_forClass::Accessor::best_practice_mutator_name_for
0000s0sClass::Accessor::::follow_best_practiceClass::Accessor::follow_best_practice
0000s0sClass::Accessor::::getClass::Accessor::get
0000s0sClass::Accessor::::make_ro_accessorClass::Accessor::make_ro_accessor
0000s0sClass::Accessor::::make_wo_accessorClass::Accessor::make_wo_accessor
0000s0sClass::Accessor::::mk_ro_accessorsClass::Accessor::mk_ro_accessors
0000s0sClass::Accessor::::mk_wo_accessorsClass::Accessor::mk_wo_accessors
0000s0sClass::Accessor::::newClass::Accessor::new
0000s0sClass::Accessor::::setClass::Accessor::set
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::Accessor;
2126µsrequire 5.00502;
33198µs234µs
# spent 28µs (22+6) within Class::Accessor::BEGIN@3 which was called: # once (22µs+6µs) by base::import at line 3
use strict;
# spent 28µs making 1 call to Class::Accessor::BEGIN@3 # spent 6µs making 1 call to strict::import
412µs$Class::Accessor::VERSION = '0.31';
5
6=head1 NAME
7
- -
115sub new {
116 my($proto, $fields) = @_;
117 my($class) = ref $proto || $proto;
118
119 $fields = {} unless defined $fields;
120
121 # make a copy of $fields.
122 bless {%$fields}, $class;
123}
124
125=head2 mk_accessors
126
- -
142
# spent 432µs (25+407) within Class::Accessor::mk_accessors which was called: # once (25µs+407µs) by MARC::Charset::Table::BEGIN@38 at line 10 of MARC/Charset/Code.pm
sub mk_accessors {
14316µs my($self, @fields) = @_;
144
145115µs1407µs $self->_mk_accessors('rw', @fields);
# spent 407µs making 1 call to Class::Accessor::_mk_accessors
146}
147
148
149{
15041.23ms270µs
# spent 42µs (14+28) within Class::Accessor::BEGIN@150 which was called: # once (14µs+28µs) by base::import at line 150
no strict 'refs';
# spent 42µs making 1 call to Class::Accessor::BEGIN@150 # spent 28µs making 1 call to strict::unimport
151
152
# spent 407µs (292+115) within Class::Accessor::_mk_accessors which was called: # once (292µs+115µs) by Class::Accessor::mk_accessors at line 145
sub _mk_accessors {
15315µs my($self, $access, @fields) = @_;
15412µs my $class = ref $self || $self;
15513µs my $ra = $access eq 'rw' || $access eq 'ro';
15612µs my $wa = $access eq 'rw' || $access eq 'wo';
157
15819µs foreach my $field (@fields) {
159641µs640µs my $accessor_name = $self->accessor_name_for($field);
# spent 40µs making 6 calls to Class::Accessor::accessor_name_for, avg 7µs/call
160631µs624µs my $mutator_name = $self->mutator_name_for($field);
# spent 24µs making 6 calls to Class::Accessor::mutator_name_for, avg 4µs/call
16168µs if( $accessor_name eq 'DESTROY' or $mutator_name eq 'DESTROY' ) {
162 $self->_carp("Having a data accessor named DESTROY in '$class' is unwise.");
163 }
164622µs if ($accessor_name eq $mutator_name) {
16565µs my $accessor;
166630µs651µs if ($ra && $wa) {
# spent 51µs making 6 calls to Class::Accessor::make_accessor, avg 8µs/call
167 $accessor = $self->make_accessor($field);
168 } elsif ($ra) {
169 $accessor = $self->make_ro_accessor($field);
170 } else {
171 $accessor = $self->make_wo_accessor($field);
172 }
173640µs unless (defined &{"${class}::$accessor_name"}) {
174 *{"${class}::$accessor_name"} = $accessor;
175 }
176618µs if ($accessor_name eq $field) {
177 # the old behaviour
178610µs my $alias = "_${field}_accessor";
179637µs *{"${class}::$alias"} = $accessor unless defined &{"${class}::$alias"};
180 }
181 } else {
182 if ($ra and not defined &{"${class}::$accessor_name"}) {
183 *{"${class}::$accessor_name"} = $self->make_ro_accessor($field);
184 }
185 if ($wa and not defined &{"${class}::$mutator_name"}) {
186 *{"${class}::$mutator_name"} = $self->make_wo_accessor($field);
187 }
188 }
189 }
190 }
191
192 sub follow_best_practice {
193 my($self) = @_;
194 my $class = ref $self || $self;
195 *{"${class}::accessor_name_for"} = \&best_practice_accessor_name_for;
196 *{"${class}::mutator_name_for"} = \&best_practice_mutator_name_for;
197 }
198
199}
200
201=head2 mk_ro_accessors
202
- -
221sub mk_ro_accessors {
222 my($self, @fields) = @_;
223
224 $self->_mk_accessors('ro', @fields);
225}
226
227=head2 mk_wo_accessors
228
- -
249sub mk_wo_accessors {
250 my($self, @fields) = @_;
251
252 $self->_mk_accessors('wo', @fields);
253}
254
255=head1 DETAILS
256
- -
292sub best_practice_accessor_name_for {
293 my ($class, $field) = @_;
294 return "get_$field";
295}
296
297sub best_practice_mutator_name_for {
298 my ($class, $field) = @_;
299 return "set_$field";
300}
301
302
# spent 40µs within Class::Accessor::accessor_name_for which was called 6 times, avg 7µs/call: # 6 times (40µs+0s) by Class::Accessor::_mk_accessors at line 159, avg 7µs/call
sub accessor_name_for {
30369µs my ($class, $field) = @_;
304640µs return $field;
305}
306
307
# spent 24µs within Class::Accessor::mutator_name_for which was called 6 times, avg 4µs/call: # 6 times (24µs+0s) by Class::Accessor::_mk_accessors at line 160, avg 4µs/call
sub mutator_name_for {
30868µs my ($class, $field) = @_;
309628µs return $field;
310}
311
312=head2 Modifying the behavior of the accessor
313
- -
331sub set {
332 my($self, $key) = splice(@_, 0, 2);
333
334 if(@_ == 1) {
335 $self->{$key} = $_[0];
336 }
337 elsif(@_ > 1) {
338 $self->{$key} = [@_];
339 }
340 else {
341 $self->_croak("Wrong number of arguments received");
342 }
343}
344
345=head2 get
346
- -
356sub get {
357 my $self = shift;
358
359 if(@_ == 1) {
360 return $self->{$_[0]};
361 }
362 elsif( @_ > 1 ) {
363 return @{$self}{@_};
364 }
365 else {
366 $self->_croak("Wrong number of arguments received");
367 }
368}
369
370=head2 make_accessor
371
- -
382
# spent 51µs within Class::Accessor::make_accessor which was called 6 times, avg 8µs/call: # 6 times (51µs+0s) by Class::Accessor::_mk_accessors at line 166, avg 8µs/call
sub make_accessor {
383610µs my ($class, $field) = @_;
384
385 # Build a closure around $field.
386 return sub {
387 my $self = shift;
388
389 if(@_) {
390 return $self->set($field, @_);
391 }
392 else {
393 return $self->get($field);
394 }
395651µs };
396}
397
398=head2 make_ro_accessor
399
- -
409sub make_ro_accessor {
410 my($class, $field) = @_;
411
412 return sub {
413 my $self = shift;
414
415 if (@_) {
416 my $caller = caller;
417 $self->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'");
418 }
419 else {
420 return $self->get($field);
421 }
422 };
423}
424
425=head2 make_wo_accessor
426
- -
436sub make_wo_accessor {
437 my($class, $field) = @_;
438
439 return sub {
440 my $self = shift;
441
442 unless (@_) {
443 my $caller = caller;
444 $self->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'");
445 }
446 else {
447 return $self->set($field, @_);
448 }
449 };
450}
451
452=head1 EXCEPTIONS
453
- -
4603159µs110µs
# spent 10µs within Class::Accessor::BEGIN@460 which was called: # once (10µs+0s) by base::import at line 460
use Carp ();
# spent 10µs making 1 call to Class::Accessor::BEGIN@460
461
462sub _carp {
463 my ($self, $msg) = @_;
464 Carp::carp($msg || $self);
465 return;
466}
467
468sub _croak {
469 my ($self, $msg) = @_;
470 Carp::croak($msg || $self);
471 return;
472}
473
474=head1 EFFICIENCY
475
- -
67515µs1;