Filename | /usr/share/perl5/Class/Accessor.pm |
Statements | Executed 514 statements in 2.70ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 1 | 1 | 631µs | 885µs | _mk_accessors | Class::Accessor::
4 | 4 | 4 | 100µs | 985µs | mk_accessors | Class::Accessor::
18 | 1 | 1 | 84µs | 84µs | make_accessor | Class::Accessor::
18 | 1 | 1 | 55µs | 55µs | accessor_name_for | Class::Accessor::
7 | 1 | 1 | 44µs | 44µs | get | Class::Accessor::
18 | 1 | 1 | 38µs | 38µs | mutator_name_for | Class::Accessor::
4 | 4 | 4 | 34µs | 34µs | import | Class::Accessor::
7 | 1 | 1 | 24µs | 24µs | set | Class::Accessor::
1 | 1 | 1 | 21µs | 28µs | BEGIN@3 | Class::Accessor::
1 | 1 | 1 | 10µs | 31µs | BEGIN@27 | Class::Accessor::
1 | 1 | 1 | 8µs | 8µs | BEGIN@218 | Class::Accessor::
0 | 0 | 0 | 0s | 0s | __ANON__[:182] | Class::Accessor::
0 | 0 | 0 | 0s | 0s | __ANON__[:198] | Class::Accessor::
0 | 0 | 0 | 0s | 0s | __ANON__[:214] | Class::Accessor::
0 | 0 | 0 | 0s | 0s | __ANON__[:37] | Class::Accessor::
0 | 0 | 0 | 0s | 0s | __ANON__[:43] | Class::Accessor::
0 | 0 | 0 | 0s | 0s | _carp | Class::Accessor::
0 | 0 | 0 | 0s | 0s | _croak | Class::Accessor::
0 | 0 | 0 | 0s | 0s | best_practice_accessor_name_for | Class::Accessor::
0 | 0 | 0 | 0s | 0s | best_practice_mutator_name_for | Class::Accessor::
0 | 0 | 0 | 0s | 0s | follow_best_practice | Class::Accessor::
0 | 0 | 0 | 0s | 0s | make_ro_accessor | Class::Accessor::
0 | 0 | 0 | 0s | 0s | make_wo_accessor | Class::Accessor::
0 | 0 | 0 | 0s | 0s | mk_ro_accessors | Class::Accessor::
0 | 0 | 0 | 0s | 0s | mk_wo_accessors | Class::Accessor::
0 | 0 | 0 | 0s | 0s | new | Class::Accessor::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::Accessor; | ||||
2 | 1 | 18µs | require 5.00502; | ||
3 | 3 | 140µs | 2 | 34µs | # spent 28µs (21+6) within Class::Accessor::BEGIN@3 which was called:
# once (21µs+6µs) by base::import at line 3 # spent 28µs making 1 call to Class::Accessor::BEGIN@3
# spent 6µs making 1 call to strict::import |
4 | 1 | 600ns | $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 985µs (100+885) within Class::Accessor::mk_accessors which was called 4 times, avg 246µs/call:
# once (16µs+352µs) by C4::Output::BEGIN@36 at line 39 of /usr/share/koha/lib/C4/Templates.pm
# once (16µs+279µs) by MARC::Charset::Table::BEGIN@38 at line 10 of MARC/Charset/Code.pm
# once (42µs+237µs) by C4::Search::parseQuery at line 51 of /usr/share/koha/lib/Koha/QueryParser/Driver/PQF.pm
# once (25µs+17µs) by C4::Biblio::BEGIN@38 at line 52 of /usr/share/koha/lib/C4/Linker.pm | ||||
17 | 4 | 22µs | my($self, @fields) = @_; | ||
18 | |||||
19 | 4 | 72µs | 4 | 885µs | $self->_mk_accessors('rw', @fields); # spent 885µs making 4 calls to Class::Accessor::_mk_accessors, avg 221µs/call |
20 | } | ||||
21 | |||||
22 | 2 | 96µs | 1 | 41µs | if (eval { require Sub::Name }) { # spent 41µs making 1 call to Exporter::import |
23 | Sub::Name->import; | ||||
24 | } | ||||
25 | |||||
26 | { | ||||
27 | 4 | 1.07ms | 2 | 53µs | # spent 31µs (10+21) within Class::Accessor::BEGIN@27 which was called:
# once (10µs+21µs) by base::import at line 27 # spent 31µs making 1 call to Class::Accessor::BEGIN@27
# spent 21µs making 1 call to strict::unimport |
28 | |||||
29 | # spent 34µs within Class::Accessor::import which was called 4 times, avg 9µs/call:
# once (12µs+0s) by C4::Auth::BEGIN@29 at line 29 of /usr/share/koha/lib/C4/Auth.pm
# once (8µs+0s) by MARC::Charset::Table::BEGIN@38 at line 38 of MARC/Charset/Table.pm
# once (7µs+0s) by C4::Output::BEGIN@36 at line 36 of /usr/share/koha/lib/C4/Output.pm
# once (7µs+0s) by C4::Biblio::BEGIN@38 at line 38 of /usr/share/koha/lib/C4/Biblio.pm | ||||
30 | 4 | 8µs | my ($class, @what) = @_; | ||
31 | 4 | 7µs | my $caller = caller; | ||
32 | 4 | 27µs | 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 885µs (631+254) within Class::Accessor::_mk_accessors which was called 4 times, avg 221µs/call:
# 4 times (631µs+254µs) by Class::Accessor::mk_accessors at line 19, avg 221µs/call | ||||
59 | 4 | 15µs | my($self, $access, @fields) = @_; | ||
60 | 4 | 6µs | my $class = ref $self || $self; | ||
61 | 4 | 9µs | my $ra = $access eq 'rw' || $access eq 'ro'; | ||
62 | 4 | 6µs | my $wa = $access eq 'rw' || $access eq 'wo'; | ||
63 | |||||
64 | 4 | 39µs | foreach my $field (@fields) { | ||
65 | 18 | 56µs | 18 | 55µs | my $accessor_name = $self->accessor_name_for($field); # spent 55µs making 18 calls to Class::Accessor::accessor_name_for, avg 3µs/call |
66 | 18 | 47µs | 18 | 38µs | my $mutator_name = $self->mutator_name_for($field); # spent 38µs making 18 calls to Class::Accessor::mutator_name_for, avg 2µs/call |
67 | 18 | 10µs | 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 | 18 | 21µs | if ($accessor_name eq $mutator_name) { | ||
71 | 18 | 4µs | my $accessor; | ||
72 | 18 | 46µs | 18 | 84µs | if ($ra && $wa) { # spent 84µs making 18 calls to Class::Accessor::make_accessor, avg 5µ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 | 18 | 17µs | my $fullname = "${class}::$accessor_name"; | ||
80 | 18 | 5µs | my $subnamed = 0; | ||
81 | 18 | 28µs | unless (defined &{$fullname}) { | ||
82 | 18 | 158µs | 18 | 77µs | subname($fullname, $accessor) if defined &subname; # spent 77µs making 18 calls to Sub::Name::subname, avg 4µs/call |
83 | 18 | 33µs | $subnamed = 1; | ||
84 | 18 | 42µs | *{$fullname} = $accessor; | ||
85 | } | ||||
86 | 18 | 17µs | if ($accessor_name eq $field) { | ||
87 | # the old behaviour | ||||
88 | 18 | 18µs | my $alias = "${class}::_${field}_accessor"; | ||
89 | 18 | 9µs | subname($alias, $accessor) if defined &subname and not $subnamed; | ||
90 | 18 | 55µs | *{$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 | sub mk_ro_accessors { | ||||
112 | my($self, @fields) = @_; | ||||
113 | |||||
114 | $self->_mk_accessors('ro', @fields); | ||||
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 55µs within Class::Accessor::accessor_name_for which was called 18 times, avg 3µs/call:
# 18 times (55µs+0s) by Class::Accessor::_mk_accessors at line 65, avg 3µs/call | ||||
134 | 18 | 17µs | my ($class, $field) = @_; | ||
135 | 18 | 77µs | return $field; | ||
136 | } | ||||
137 | |||||
138 | # spent 38µs within Class::Accessor::mutator_name_for which was called 18 times, avg 2µs/call:
# 18 times (38µs+0s) by Class::Accessor::_mk_accessors at line 66, avg 2µs/call | ||||
139 | 18 | 11µs | my ($class, $field) = @_; | ||
140 | 18 | 43µs | return $field; | ||
141 | } | ||||
142 | |||||
143 | # spent 24µs within Class::Accessor::set which was called 7 times, avg 3µs/call:
# 7 times (24µs+0s) by C4::Templates::activethemes or C4::Templates::filename or C4::Templates::htdocs or C4::Templates::interface or C4::Templates::lang or C4::Templates::preferredtheme or C4::Templates::theme at line 177, avg 3µs/call | ||||
144 | 7 | 7µs | my($self, $key) = splice(@_, 0, 2); | ||
145 | |||||
146 | 7 | 32µs | 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 | # spent 44µs within Class::Accessor::get which was called 7 times, avg 6µs/call:
# 7 times (44µs+0s) by C4::Templates::filename or C4::Templates::interface or C4::Templates::lang or C4::Templates::preferredtheme or C4::Templates::theme at line 180, avg 6µs/call | ||||
158 | 7 | 5µs | my $self = shift; | ||
159 | |||||
160 | 7 | 64µs | 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 | # spent 84µs within Class::Accessor::make_accessor which was called 18 times, avg 5µs/call:
# 18 times (84µs+0s) by Class::Accessor::_mk_accessors at line 72, avg 5µs/call | ||||
172 | 18 | 12µs | my ($class, $field) = @_; | ||
173 | |||||
174 | return sub { | ||||
175 | 14 | 10µs | my $self = shift; | ||
176 | |||||
177 | 14 | 54µs | 7 | 24µs | if(@_) { # spent 24µs making 7 calls to Class::Accessor::set, avg 3µs/call |
178 | return $self->set($field, @_); | ||||
179 | } else { | ||||
180 | 7 | 80µs | 7 | 44µs | return $self->get($field); # spent 44µs making 7 calls to Class::Accessor::get, avg 6µs/call |
181 | } | ||||
182 | 18 | 94µs | }; | ||
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 | 92µs | 1 | 8µs | # spent 8µs within Class::Accessor::BEGIN@218 which was called:
# once (8µs+0s) by base::import at line 218 # spent 8µ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 | 6µs | 1; | ||
233 | |||||
234 | __END__ |