Profile of Class/Accessor.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:00 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Class/Accessor.pm
Statements | Executed 350 statements in 1.48ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
5 | 2 | 1 | 309µs | 462µs | Class::Accessor::::_mk_accessorsClass::Accessor::_mk_accessors
15 | 1 | 1 | 26µs | 26µs | Class::Accessor::::accessor_name_forClass::Accessor::accessor_name_for
3 | 3 | 1 | 21µs | 393µs | Class::Accessor::::mk_ro_accessorsClass::Accessor::mk_ro_accessors
15 | 1 | 1 | 21µs | 21µs | Class::Accessor::::mutator_name_forClass::Accessor::mutator_name_for
2 | 2 | 2 | 15µs | 106µs | Class::Accessor::::mk_accessorsClass::Accessor::mk_accessors
1 | 1 | 1 | 12µs | 19µs | Class::Accessor::::BEGIN@3Class::Accessor::BEGIN@3
1 | 1 | 1 | 7µs | 18µs | Class::Accessor::::BEGIN@27Class::Accessor::BEGIN@27
1 | 1 | 1 | 4µs | 4µs | Class::Accessor::::importClass::Accessor::import
1 | 1 | 1 | 4µs | 4µs | Class::Accessor::::BEGIN@218Class::Accessor::BEGIN@218
0 | 0 | 0 | 0s | 0s | Class::Accessor::::__ANON__[:182]Class::Accessor::__ANON__[:182]
0 | 0 | 0 | 0s | 0s | Class::Accessor::::__ANON__[:198]Class::Accessor::__ANON__[:198]
0 | 0 | 0 | 0s | 0s | Class::Accessor::::__ANON__[:214]Class::Accessor::__ANON__[:214]
0 | 0 | 0 | 0s | 0s | Class::Accessor::::__ANON__[:37]Class::Accessor::__ANON__[:37]
0 | 0 | 0 | 0s | 0s | Class::Accessor::::__ANON__[:43]Class::Accessor::__ANON__[:43]
0 | 0 | 0 | 0s | 0s | Class::Accessor::::_carpClass::Accessor::_carp
0 | 0 | 0 | 0s | 0s | Class::Accessor::::_croakClass::Accessor::_croak
0 | 0 | 0 | 0s | 0s | Class::Accessor::::best_practice_accessor_name_forClass::Accessor::best_practice_accessor_name_for
0 | 0 | 0 | 0s | 0s | Class::Accessor::::best_practice_mutator_name_forClass::Accessor::best_practice_mutator_name_for
0 | 0 | 0 | 0s | 0s | Class::Accessor::::follow_best_practiceClass::Accessor::follow_best_practice
0 | 0 | 0 | 0s | 0s | Class::Accessor::::getClass::Accessor::get
0 | 0 | 0 | 0s | 0s | Class::Accessor::::make_accessorClass::Accessor::make_accessor
0 | 0 | 0 | 0s | 0s | Class::Accessor::::make_ro_accessorClass::Accessor::make_ro_accessor
0 | 0 | 0 | 0s | 0s | Class::Accessor::::make_wo_accessorClass::Accessor::make_wo_accessor
0 | 0 | 0 | 0s | 0s | Class::Accessor::::mk_wo_accessorsClass::Accessor::mk_wo_accessors
0 | 0 | 0 | 0s | 0s | Class::Accessor::::newClass::Accessor::new
0 | 0 | 0 | 0s | 0s | Class::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
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Class::Accessor;
2 | 1 | 20µs |  |  | require 5.00502;
3 | 3 | 104µs | 2 | 26µs | # spent 19µs (12+7) within Class::Accessor::BEGIN@3 which was called: # once (12µs+7µs) by base::import at line 3 use strict; # spent 19µs making 1 call to Class::Accessor::BEGIN@3 # spent 7µs making 1 call to strict::import
4 | 1 | 400ns |  |  | $Class::Accessor::VERSION = '0.34';
5 |  |  |  |  |
6 |  |  |  |  | sub new {
7 |  |  |  |  | my($proto, $fields) = @_;
8 |  |  |  |  | my($class) = ref $proto || $proto;
9 |  |  |  |  |
10 |  |  |  |  | $fields = {} unless defined $fields;
11 |  |  |  |  |
12 |  |  |  |  | # make a copy of $fields.
13 |  |  |  |  | bless {%$fields}, $class;
14 |  |  |  |  | }
15 |  |  |  |  |
16 |  |  |  |  | # spent 106µs (15+91) within Class::Accessor::mk_accessors which was called 2 times, avg 53µs/call: # once (10µs+56µs) by DBIx::Class::InflateColumn::Object::Enum::BEGIN@6 at line 21 of Object/Enum.pm # once (5µs+35µs) by Devel::Backtrace::BEGIN@4 at line 134 of Devel/Backtrace/Point.pm sub mk_accessors {
17 | 4 | 14µs |  |  | my($self, @fields) = @_;
18 |  |  |  |  |
19 |  |  | 2 | 91µs | $self->_mk_accessors('rw', @fields); # spent 91µs making 2 calls to Class::Accessor::_mk_accessors, avg 45µs/call
20 |  |  |  |  | }
21 |  |  |  |  |
22 | 2 | 9µs | 1 | 31µs | if (eval { require Sub::Name }) { # spent 31µs making 1 call to Exporter::import
23 |  |  |  |  | Sub::Name->import;
24 |  |  |  |  | }
25 |  |  |  |  |
26 |  |  |  |  | {
27 | 4 | 847µs | 2 | 29µs | # spent 18µs (7+11) within Class::Accessor::BEGIN@27 which was called: # once (7µs+11µs) by base::import at line 27 no strict 'refs'; # spent 18µs making 1 call to Class::Accessor::BEGIN@27 # spent 11µs making 1 call to strict::unimport
28 |  |  |  |  |
29 |  |  |  |  | # spent 4µs within Class::Accessor::import which was called: # once (4µs+0s) by Devel::Backtrace::BEGIN@4 at line 4 of Devel/Backtrace.pm sub import {
30 | 3 | 7µs |  |  | my ($class, @what) = @_;
31 |  |  |  |  | my $caller = caller;
32 |  |  |  |  | for (@what) {
33 |  |  |  |  | if (/^(?:antlers|moose-?like)$/i) {
34 |  |  |  |  | *{"${caller}::has"} = sub {
35 |  |  |  |  | my ($f, %args) = @_;
36 |  |  |  |  | $caller->_mk_accessors(($args{is}||"rw"), $f);
37 |  |  |  |  | };
38 |  |  |  |  | *{"${caller}::extends"} = sub {
39 |  |  |  |  | @{"${caller}::ISA"} = @_;
40 |  |  |  |  | unless (grep $_->can("_mk_accessors"), @_) {
41 |  |  |  |  | push @{"${caller}::ISA"}, $class;
42 |  |  |  |  | }
43 |  |  |  |  | };
44 |  |  |  |  | # we'll use their @ISA as a default, in case it happens to be
45 |  |  |  |  | # set already
46 |  |  |  |  | &{"${caller}::extends"}(@{"${caller}::ISA"});
47 |  |  |  |  | }
48 |  |  |  |  | }
49 |  |  |  |  | }
50 |  |  |  |  |
51 |  |  |  |  | sub follow_best_practice {
52 |  |  |  |  | my($self) = @_;
53 |  |  |  |  | my $class = ref $self || $self;
54 |  |  |  |  | *{"${class}::accessor_name_for"} = \&best_practice_accessor_name_for;
55 |  |  |  |  | *{"${class}::mutator_name_for"} = \&best_practice_mutator_name_for;
56 |  |  |  |  | }
57 |  |  |  |  |
58 |  |  |  |  | # spent 462µs (309+153) within Class::Accessor::_mk_accessors which was called 5 times, avg 92µs/call: # 3 times (247µs+124µs) by Class::Accessor::mk_ro_accessors at line 114, avg 124µs/call # 2 times (62µs+29µs) by Class::Accessor::mk_accessors at line 19, avg 45µs/call sub _mk_accessors {
59 | 25 | 32µs |  |  | my($self, $access, @fields) = @_;
60 |  |  |  |  | my $class = ref $self || $self;
61 |  |  |  |  | my $ra = $access eq 'rw' || $access eq 'ro';
62 |  |  |  |  | my $wa = $access eq 'rw' || $access eq 'wo';
63 |  |  |  |  |
64 |  |  |  |  | foreach my $field (@fields) {
65 | 60 | 66µs | 15 | 26µs | my $accessor_name = $self->accessor_name_for($field); # spent 26µs making 15 calls to Class::Accessor::accessor_name_for, avg 2µs/call
66 |  |  | 15 | 21µs | my $mutator_name = $self->mutator_name_for($field); # spent 21µs making 15 calls to Class::Accessor::mutator_name_for, avg 1µs/call
67 |  |  |  |  | if( $accessor_name eq 'DESTROY' or $mutator_name eq 'DESTROY' ) {
68 |  |  |  |  | $self->_carp("Having a data accessor named DESTROY in '$class' is unwise.");
69 |  |  |  |  | }
70 | 90 | 64µs |  |  | if ($accessor_name eq $mutator_name) {
71 |  |  |  |  | my $accessor;
72 |  |  | 15 | 69µs | if ($ra && $wa) { # spent 56µs making 13 calls to Class::Accessor::Fast::make_ro_accessor, avg 4µs/call # spent 13µs making 2 calls to Class::Accessor::Fast::make_accessor, avg 6µs/call
73 |  |  |  |  | $accessor = $self->make_accessor($field);
74 |  |  |  |  | } elsif ($ra) {
75 |  |  |  |  | $accessor = $self->make_ro_accessor($field);
76 |  |  |  |  | } else {
77 |  |  |  |  | $accessor = $self->make_wo_accessor($field);
78 |  |  |  |  | }
79 |  |  |  |  | my $fullname = "${class}::$accessor_name";
80 |  |  |  |  | my $subnamed = 0;
81 | 42 | 90µs |  |  | unless (defined &{$fullname}) {
82 |  |  | 14 | 33µs | subname($fullname, $accessor) if defined &subname; # spent 33µs making 14 calls to Sub::Name::subname, avg 2µs/call
83 |  |  |  |  | $subnamed = 1;
84 |  |  |  |  | *{$fullname} = $accessor;
85 |  |  |  |  | }
86 | 45 | 58µs |  |  | if ($accessor_name eq $field) {
87 |  |  |  |  | # the old behaviour
88 |  |  |  |  | my $alias = "${class}::_${field}_accessor";
89 |  |  | 1 | 4µs | subname($alias, $accessor) if defined &subname and not $subnamed; # spent 4µs making 1 call to Sub::Name::subname
90 |  |  |  |  | *{$alias} = $accessor unless defined &{$alias};
91 |  |  |  |  | }
92 |  |  |  |  | } else {
93 |  |  |  |  | my $fullaccname = "${class}::$accessor_name";
94 |  |  |  |  | my $fullmutname = "${class}::$mutator_name";
95 |  |  |  |  | if ($ra and not defined &{$fullaccname}) {
96 |  |  |  |  | my $accessor = $self->make_ro_accessor($field);
97 |  |  |  |  | subname($fullaccname, $accessor) if defined &subname;
98 |  |  |  |  | *{$fullaccname} = $accessor;
99 |  |  |  |  | }
100 |  |  |  |  | if ($wa and not defined &{$fullmutname}) {
101 |  |  |  |  | my $mutator = $self->make_wo_accessor($field);
102 |  |  |  |  | subname($fullmutname, $mutator) if defined &subname;
103 |  |  |  |  | *{$fullmutname} = $mutator;
104 |  |  |  |  | }
105 |  |  |  |  | }
106 |  |  |  |  | }
107 |  |  |  |  | }
108 |  |  |  |  |
109 |  |  |  |  | }
110 |  |  |  |  |
111 |  |  |  |  | # spent 393µs (21+371) within Class::Accessor::mk_ro_accessors which was called 3 times, avg 131µs/call: # once (14µs+319µs) by Devel::Backtrace::BEGIN@4 at line 68 of Devel/Backtrace/Point.pm # once (4µs+26µs) by Devel::Backtrace::BEGIN@4 at line 77 of Devel/Backtrace/Point.pm # once (3µs+26µs) by Devel::Backtrace::BEGIN@4 at line 133 of Devel/Backtrace/Point.pm sub mk_ro_accessors {
112 | 6 | 21µs |  |  | my($self, @fields) = @_;
113 |  |  |  |  |
114 |  |  | 3 | 372µs | $self->_mk_accessors('ro', @fields); # spent 372µs making 3 calls to Class::Accessor::_mk_accessors, avg 124µs/call
115 |  |  |  |  | }
116 |  |  |  |  |
117 |  |  |  |  | sub mk_wo_accessors {
118 |  |  |  |  | my($self, @fields) = @_;
119 |  |  |  |  |
120 |  |  |  |  | $self->_mk_accessors('wo', @fields);
121 |  |  |  |  | }
122 |  |  |  |  |
123 |  |  |  |  | sub best_practice_accessor_name_for {
124 |  |  |  |  | my ($class, $field) = @_;
125 |  |  |  |  | return "get_$field";
126 |  |  |  |  | }
127 |  |  |  |  |
128 |  |  |  |  | sub best_practice_mutator_name_for {
129 |  |  |  |  | my ($class, $field) = @_;
130 |  |  |  |  | return "set_$field";
131 |  |  |  |  | }
132 |  |  |  |  |
133 |  |  |  |  | # spent 26µs within Class::Accessor::accessor_name_for which was called 15 times, avg 2µs/call: # 15 times (26µs+0s) by Class::Accessor::_mk_accessors at line 65, avg 2µs/call sub accessor_name_for {
134 | 30 | 41µs |  |  | my ($class, $field) = @_;
135 |  |  |  |  | return $field;
136 |  |  |  |  | }
137 |  |  |  |  |
138 |  |  |  |  | # spent 21µs within Class::Accessor::mutator_name_for which was called 15 times, avg 1µs/call: # 15 times (21µs+0s) by Class::Accessor::_mk_accessors at line 66, avg 1µs/call sub mutator_name_for {
139 | 30 | 33µs |  |  | my ($class, $field) = @_;
140 |  |  |  |  | return $field;
141 |  |  |  |  | }
142 |  |  |  |  |
143 |  |  |  |  | sub set {
144 |  |  |  |  | my($self, $key) = splice(@_, 0, 2);
145 |  |  |  |  |
146 |  |  |  |  | if(@_ == 1) {
147 |  |  |  |  | $self->{$key} = $_[0];
148 |  |  |  |  | }
149 |  |  |  |  | elsif(@_ > 1) {
150 |  |  |  |  | $self->{$key} = [@_];
151 |  |  |  |  | }
152 |  |  |  |  | else {
153 |  |  |  |  | $self->_croak("Wrong number of arguments received");
154 |  |  |  |  | }
155 |  |  |  |  | }
156 |  |  |  |  |
157 |  |  |  |  | sub get {
158 |  |  |  |  | my $self = shift;
159 |  |  |  |  |
160 |  |  |  |  | if(@_ == 1) {
161 |  |  |  |  | return $self->{$_[0]};
162 |  |  |  |  | }
163 |  |  |  |  | elsif( @_ > 1 ) {
164 |  |  |  |  | return @{$self}{@_};
165 |  |  |  |  | }
166 |  |  |  |  | else {
167 |  |  |  |  | $self->_croak("Wrong number of arguments received");
168 |  |  |  |  | }
169 |  |  |  |  | }
170 |  |  |  |  |
171 |  |  |  |  | sub make_accessor {
172 |  |  |  |  | my ($class, $field) = @_;
173 |  |  |  |  |
174 |  |  |  |  | return sub {
175 |  |  |  |  | my $self = shift;
176 |  |  |  |  |
177 |  |  |  |  | if(@_) {
178 |  |  |  |  | return $self->set($field, @_);
179 |  |  |  |  | } else {
180 |  |  |  |  | return $self->get($field);
181 |  |  |  |  | }
182 |  |  |  |  | };
183 |  |  |  |  | }
184 |  |  |  |  |
185 |  |  |  |  | sub make_ro_accessor {
186 |  |  |  |  | my($class, $field) = @_;
187 |  |  |  |  |
188 |  |  |  |  | return sub {
189 |  |  |  |  | my $self = shift;
190 |  |  |  |  |
191 |  |  |  |  | if (@_) {
192 |  |  |  |  | my $caller = caller;
193 |  |  |  |  | $self->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'");
194 |  |  |  |  | }
195 |  |  |  |  | else {
196 |  |  |  |  | return $self->get($field);
197 |  |  |  |  | }
198 |  |  |  |  | };
199 |  |  |  |  | }
200 |  |  |  |  |
201 |  |  |  |  | sub make_wo_accessor {
202 |  |  |  |  | my($class, $field) = @_;
203 |  |  |  |  |
204 |  |  |  |  | return sub {
205 |  |  |  |  | my $self = shift;
206 |  |  |  |  |
207 |  |  |  |  | unless (@_) {
208 |  |  |  |  | my $caller = caller;
209 |  |  |  |  | $self->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'");
210 |  |  |  |  | }
211 |  |  |  |  | else {
212 |  |  |  |  | return $self->set($field, @_);
213 |  |  |  |  | }
214 |  |  |  |  | };
215 |  |  |  |  | }
216 |  |  |  |  |
217 |  |  |  |  |
218 | 3 | 65µs | 1 | 4µs | # spent 4µs within Class::Accessor::BEGIN@218 which was called: # once (4µs+0s) by base::import at line 218 use Carp (); # spent 4µs making 1 call to Class::Accessor::BEGIN@218
219 |  |  |  |  |
220 |  |  |  |  | sub _carp {
221 |  |  |  |  | my ($self, $msg) = @_;
222 |  |  |  |  | Carp::carp($msg || $self);
223 |  |  |  |  | return;
224 |  |  |  |  | }
225 |  |  |  |  |
226 |  |  |  |  | sub _croak {
227 |  |  |  |  | my ($self, $msg) = @_;
228 |  |  |  |  | Carp::croak($msg || $self);
229 |  |  |  |  | return;
230 |  |  |  |  | }
231 |  |  |  |  |
232 | 1 | 4µs |  |  | 1;
233 |  |  |  |  |
234 |  |  |  |  | __END__