← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 13:01:18 2016
Reported on Fri Jan 8 13:01:36 2016

Filename/usr/share/perl5/Method/Generate/Accessor.pm
StatementsExecuted 633 statements in 5.17ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
711239µs1.44msMethod::Generate::Accessor::::generate_methodMethod::Generate::Accessor::generate_method
111194µs345µsMethod::Generate::Accessor::::_generate_populate_setMethod::Generate::Accessor::_generate_populate_set
165193µs235µsMethod::Generate::Accessor::::_generate_simple_setMethod::Generate::Accessor::_generate_simple_set
43156µs161µsMethod::Generate::Accessor::::_generate_call_codeMethod::Generate::Accessor::_generate_call_code
161156µs96µsMethod::Generate::Accessor::::_generate_core_setMethod::Generate::Accessor::_generate_core_set
111152µs398µsMethod::Generate::Accessor::::generate_populate_setMethod::Generate::Accessor::generate_populate_set
32152µs369µsMethod::Generate::Accessor::::_generate_getMethod::Generate::Accessor::_generate_get
31146µs238µsMethod::Generate::Accessor::::_generate_use_defaultMethod::Generate::Accessor::_generate_use_default
11132µs140µsMethod::Generate::Accessor::::BEGIN@11Method::Generate::Accessor::BEGIN@11
41132µs292µsMethod::Generate::Accessor::::_generate_xsMethod::Generate::Accessor::_generate_xs
22130µs117µsMethod::Generate::Accessor::::_generate_setMethod::Generate::Accessor::_generate_set
42129µs125µsMethod::Generate::Accessor::::_generate_get_defaultMethod::Generate::Accessor::_generate_get_default
32126µs34µsMethod::Generate::Accessor::::_validate_codulatableMethod::Generate::Accessor::_validate_codulatable
62125µs48µsMethod::Generate::Accessor::::_generate_simple_getMethod::Generate::Accessor::_generate_simple_get
31121µs49µsMethod::Generate::Accessor::::_generate_simple_hasMethod::Generate::Accessor::_generate_simple_has
11120µs39µsMethod::Generate::Accessor::::_wrap_attr_exceptionMethod::Generate::Accessor::_wrap_attr_exception
132219µs19µsMethod::Generate::Accessor::::has_eager_defaultMethod::Generate::Accessor::has_eager_default
103119µs19µsMethod::Generate::Accessor::::is_simple_getMethod::Generate::Accessor::is_simple_get
11118µs18µsMethod::Generate::Accessor::::CORE:regcompMethod::Generate::Accessor::CORE:regcomp (opcode)
11117µs56µsMethod::Generate::Accessor::::BEGIN@3Method::Generate::Accessor::BEGIN@3
11114µs258µsMethod::Generate::Accessor::::_generate_getsetMethod::Generate::Accessor::_generate_getset
32112µs12µsMethod::Generate::Accessor::::is_simple_setMethod::Generate::Accessor::is_simple_set
11111µs39µsMethod::Generate::Accessor::::BEGIN@7Method::Generate::Accessor::BEGIN@7
11111µs26µsMethod::Generate::Accessor::::BEGIN@10Method::Generate::Accessor::BEGIN@10
11110µs58µsMethod::Generate::Accessor::::BEGIN@4Method::Generate::Accessor::BEGIN@4
1119µs85µsMethod::Generate::Accessor::::_generate_isa_checkMethod::Generate::Accessor::_generate_isa_check
1119µs25µsMethod::Generate::Accessor::::BEGIN@8Method::Generate::Accessor::BEGIN@8
1116µs9µsMethod::Generate::Accessor::::_generate_simple_clearMethod::Generate::Accessor::_generate_simple_clear
1115µs40µsMethod::Generate::Accessor::::_generate_triggerMethod::Generate::Accessor::_generate_trigger
1115µs8µsMethod::Generate::Accessor::::_attr_descMethod::Generate::Accessor::_attr_desc
1115µs5µsMethod::Generate::Accessor::::BEGIN@9Method::Generate::Accessor::BEGIN@9
1114µs4µsMethod::Generate::Accessor::::BEGIN@5Method::Generate::Accessor::BEGIN@5
1112µs2µsMethod::Generate::Accessor::::CORE:qrMethod::Generate::Accessor::CORE:qr (opcode)
7112µs2µsMethod::Generate::Accessor::::CORE:substMethod::Generate::Accessor::CORE:subst (opcode)
1112µs2µsMethod::Generate::Accessor::::default_construction_stringMethod::Generate::Accessor::default_construction_string
0000s0sMethod::Generate::Accessor::::__ANON__[:78]Method::Generate::Accessor::__ANON__[:78]
0000s0sMethod::Generate::Accessor::::_die_overwriteMethod::Generate::Accessor::_die_overwrite
0000s0sMethod::Generate::Accessor::::_generate_asserterMethod::Generate::Accessor::_generate_asserter
0000s0sMethod::Generate::Accessor::::_generate_coerceMethod::Generate::Accessor::_generate_coerce
0000s0sMethod::Generate::Accessor::::_generate_delegationMethod::Generate::Accessor::_generate_delegation
0000s0sMethod::Generate::Accessor::::_sanitize_nameMethod::Generate::Accessor::_sanitize_name
0000s0sMethod::Generate::Accessor::::generate_coerceMethod::Generate::Accessor::generate_coerce
0000s0sMethod::Generate::Accessor::::generate_get_defaultMethod::Generate::Accessor::generate_get_default
0000s0sMethod::Generate::Accessor::::generate_isa_checkMethod::Generate::Accessor::generate_isa_check
0000s0sMethod::Generate::Accessor::::generate_simple_getMethod::Generate::Accessor::generate_simple_get
0000s0sMethod::Generate::Accessor::::generate_simple_hasMethod::Generate::Accessor::generate_simple_has
0000s0sMethod::Generate::Accessor::::generate_triggerMethod::Generate::Accessor::generate_trigger
0000s0sMethod::Generate::Accessor::::generate_use_defaultMethod::Generate::Accessor::generate_use_default
0000s0sMethod::Generate::Accessor::::is_simple_attributeMethod::Generate::Accessor::is_simple_attribute
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Method::Generate::Accessor;
2
3340µs395µs
# spent 56µs (17+39) within Method::Generate::Accessor::BEGIN@3 which was called: # once (17µs+39µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 3
use strictures 1;
# spent 56µs making 1 call to Method::Generate::Accessor::BEGIN@3 # spent 23µs making 1 call to strictures::import # spent 16µs making 1 call to strictures::VERSION
4281µs2106µs
# spent 58µs (10+48) within Method::Generate::Accessor::BEGIN@4 which was called: # once (10µs+48µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 4
use Moo::_Utils;
# spent 58µs making 1 call to Method::Generate::Accessor::BEGIN@4 # spent 48µs making 1 call to Exporter::import
5240µs14µs
# spent 4µs within Method::Generate::Accessor::BEGIN@5 which was called: # once (4µs+0s) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 5
use Moo::Object ();
# spent 4µs making 1 call to Method::Generate::Accessor::BEGIN@5
6112µsour @ISA = qw(Moo::Object);
7262µs266µs
# spent 39µs (11+27) within Method::Generate::Accessor::BEGIN@7 which was called: # once (11µs+27µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 7
use Sub::Quote qw(quote_sub quoted_from_sub quotify);
# spent 39µs making 1 call to Method::Generate::Accessor::BEGIN@7 # spent 27µs making 1 call to Exporter::import
8245µs242µs
# spent 25µs (9+16) within Method::Generate::Accessor::BEGIN@8 which was called: # once (9µs+16µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 8
use Scalar::Util 'blessed';
# spent 25µs making 1 call to Method::Generate::Accessor::BEGIN@8 # spent 16µs making 1 call to Exporter::import
9224µs15µs
# spent 5µs within Method::Generate::Accessor::BEGIN@9 which was called: # once (5µs+0s) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 9
use overload ();
# spent 5µs making 1 call to Method::Generate::Accessor::BEGIN@9
102182µs242µs
# spent 26µs (11+15) within Method::Generate::Accessor::BEGIN@10 which was called: # once (11µs+15µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 10
use Module::Runtime qw(use_module);
# spent 26µs making 1 call to Method::Generate::Accessor::BEGIN@10 # spent 15µs making 1 call to Module::Runtime::import
11
# spent 140µs (32+108) within Method::Generate::Accessor::BEGIN@11 which was called: # once (32µs+108µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 23
BEGIN {
12 our $CAN_HAZ_XS =
13 !$ENV{MOO_XS_DISABLE}
14 &&
15 _maybe_load_module('Class::XSAccessor')
16 &&
17231µs2100µs (eval { Class::XSAccessor->VERSION('1.07') })
# spent 87µs making 1 call to Moo::_Utils::_maybe_load_module # spent 14µs making 1 call to version::vxs::_VERSION
18 ;
19 our $CAN_HAZ_XS_PRED =
20 $CAN_HAZ_XS &&
21221µs18µs (eval { Class::XSAccessor->VERSION('1.17') })
# spent 8µs making 1 call to version::vxs::_VERSION
22 ;
2313.67ms1140µs}
# spent 140µs making 1 call to Method::Generate::Accessor::BEGIN@11
24
25139µs220µsmy $module_name_only = qr/\A$Module::Runtime::module_name_rx\z/;
# spent 18µs making 1 call to Method::Generate::Accessor::CORE:regcomp # spent 2µs making 1 call to Method::Generate::Accessor::CORE:qr
26
27sub _die_overwrite
28{
29 my ($pkg, $method, $type) = @_;
30 die "You cannot overwrite a locally defined method ($method) with "
31 . ( $type || 'an accessor' );
32}
33
34
# spent 1.44ms (239µs+1.20) within Method::Generate::Accessor::generate_method which was called 7 times, avg 206µs/call: # 7 times (239µs+1.20ms) by Moo::has at line 54 of Moo.pm, avg 206µs/call
sub generate_method {
3573µs my ($self, $into, $name, $spec, $quote_opts) = @_;
36716µs72µs $spec->{allow_overwrite}++ if $name =~ s/^\+//;
# spent 2µs making 7 calls to Method::Generate::Accessor::CORE:subst, avg 257ns/call
3773µs die "Must have an is" unless my $is = $spec->{is};
3878µs if ($is eq 'ro') {
39 $spec->{reader} = $name unless exists $spec->{reader};
40 } elsif ($is eq 'rw') {
41 $spec->{accessor} = $name unless exists $spec->{accessor}
42 or ( $spec->{reader} and $spec->{writer} );
43 } elsif ($is eq 'lazy') {
44 $spec->{reader} = $name unless exists $spec->{reader};
45 $spec->{lazy} = 1;
46 $spec->{builder} ||= '_build_'.$name unless exists $spec->{default};
47 } elsif ($is eq 'rwp') {
48 $spec->{reader} = $name unless exists $spec->{reader};
49 $spec->{writer} = "_set_${name}" unless exists $spec->{writer};
50 } elsif ($is ne 'bare') {
51 die "Unknown is ${is}";
52 }
5372µs if (exists $spec->{builder}) {
54 if(ref $spec->{builder}) {
55 $self->_validate_codulatable('builder', $spec->{builder},
56 "$into->$name", 'or a method name');
57 $spec->{builder_sub} = $spec->{builder};
58 $spec->{builder} = 1;
59 }
60 $spec->{builder} = '_build_'.$name if ($spec->{builder}||0) eq 1;
61 die "Invalid builder for $into->$name - not a valid method name"
62 if $spec->{builder} !~ $module_name_only;
63 }
6473µs if (($spec->{predicate}||0) eq 1) {
65 $spec->{predicate} = $name =~ /^_/ ? "_has${name}" : "has_${name}";
66 }
6772µs if (($spec->{clearer}||0) eq 1) {
68 $spec->{clearer} = $name =~ /^_/ ? "_clear${name}" : "clear_${name}";
69 }
7072µs if (($spec->{trigger}||0) eq 1) {
71 $spec->{trigger} = quote_sub('shift->_trigger_'.$name.'(@_)');
72 }
7372µs if (($spec->{coerce}||0) eq 1) {
74 my $isa = $spec->{isa};
75 if (blessed $isa and $isa->can('coercion')) {
76 $spec->{coerce} = $isa->coercion;
77 } elsif (blessed $isa and $isa->can('coerce')) {
78 $spec->{coerce} = sub { $isa->coerce(@_) };
79 } else {
80 die "Invalid coercion for $into->$name - no appropriate type constraint";
81 }
82 }
83
8479µs for my $setting (qw( isa coerce )) {
85145µs next if !exists $spec->{$setting};
8612µs113µs $self->_validate_codulatable($setting, $spec->{$setting}, "$into->$name");
# spent 13µs making 1 call to Method::Generate::Accessor::_validate_codulatable
87 }
88
8979µs220µs if (exists $spec->{default}) {
# spent 20µs making 2 calls to Method::Generate::Accessor::_validate_codulatable, avg 10µs/call
90 if (ref $spec->{default}) {
91 $self->_validate_codulatable('default', $spec->{default}, "$into->$name",
92 'or a non-ref');
93 }
94 }
95
9672µs if (exists $spec->{moosify}) {
97 if (ref $spec->{moosify} ne 'ARRAY') {
98 $spec->{moosify} = [$spec->{moosify}];
99 }
100
101 for my $spec (@{$spec->{moosify}}) {
102 $self->_validate_codulatable('moosify', $spec, "$into->$name");
103 }
104 }
105
10671µs my %methods;
10775µs if (my $reader = $spec->{reader}) {
108 _die_overwrite($into, $reader, 'a reader')
109612µs620µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${reader}")}{CODE};
# spent 20µs making 6 calls to Moo::_Utils::_getglob, avg 3µs/call
110615µs10302µs if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) {
# spent 292µs making 4 calls to Method::Generate::Accessor::_generate_xs, avg 73µs/call # spent 10µs making 6 calls to Method::Generate::Accessor::is_simple_get, avg 2µs/call
111 $methods{$reader} = $self->_generate_xs(
112 getters => $into, $reader, $name, $spec
113 );
114 } else {
11522µs $self->{captures} = {};
116211µs4313µs $methods{$reader} =
# spent 168µs making 2 calls to Method::Generate::Accessor::_generate_get, avg 84µs/call # spent 145µs making 2 calls to Sub::Quote::quote_sub, avg 72µs/call
117 quote_sub "${into}::${reader}"
118 => ' die "'.$reader.' is a read-only accessor" if @_ > 1;'."\n"
119 .$self->_generate_get($name, $spec)
120 => delete $self->{captures}
121 ;
122 }
123 }
12474µs if (my $accessor = $spec->{accessor}) {
125 _die_overwrite($into, $accessor, 'an accessor')
12613µs15µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${accessor}")}{CODE};
# spent 5µs making 1 call to Moo::_Utils::_getglob
12713µs14µs if (
# spent 4µs making 1 call to Method::Generate::Accessor::is_simple_get
128 our $CAN_HAZ_XS
129 && $self->is_simple_get($name, $spec)
130 && $self->is_simple_set($name, $spec)
131 ) {
132 $methods{$accessor} = $self->_generate_xs(
133 accessors => $into, $accessor, $name, $spec
134 );
135 } else {
13612µs $self->{captures} = {};
137118µs2329µs $methods{$accessor} =
# spent 258µs making 1 call to Method::Generate::Accessor::_generate_getset # spent 70µs making 1 call to Sub::Quote::quote_sub
138 quote_sub "${into}::${accessor}"
139 => $self->_generate_getset($name, $spec)
140 => delete $self->{captures}
141 ;
142 }
143 }
14474µs if (my $writer = $spec->{writer}) {
145 _die_overwrite($into, $writer, 'a writer')
14613µs13µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${writer}")}{CODE};
# spent 3µs making 1 call to Moo::_Utils::_getglob
14713µs15µs if (
# spent 5µs making 1 call to Method::Generate::Accessor::is_simple_set
148 our $CAN_HAZ_XS
149 && $self->is_simple_set($name, $spec)
150 ) {
151 $methods{$writer} = $self->_generate_xs(
152 setters => $into, $writer, $name, $spec
153 );
154 } else {
1551900ns $self->{captures} = {};
15615µs2128µs $methods{$writer} =
# spent 73µs making 1 call to Method::Generate::Accessor::_generate_set # spent 55µs making 1 call to Sub::Quote::quote_sub
157 quote_sub "${into}::${writer}"
158 => $self->_generate_set($name, $spec)
159 => delete $self->{captures}
160 ;
161 }
162 }
16372µs if (my $pred = $spec->{predicate}) {
164 _die_overwrite($into, $pred, 'a predicate')
165 if !$spec->{allow_overwrite} && *{_getglob("${into}::${pred}")}{CODE};
166 if (our $CAN_HAZ_XS && our $CAN_HAZ_XS_PRED) {
167 $methods{$pred} = $self->_generate_xs(
168 exists_predicates => $into, $pred, $name, $spec
169 );
170 } else {
171 $methods{$pred} =
172 quote_sub "${into}::${pred}" =>
173 ' '.$self->_generate_simple_has('$_[0]', $name, $spec)."\n"
174 ;
175 }
176 }
17772µs if (my $pred = $spec->{builder_sub}) {
178 _install_coderef( "${into}::$spec->{builder}" => $spec->{builder_sub} );
179 }
18072µs if (my $cl = $spec->{clearer}) {
181 _die_overwrite($into, $cl, 'a clearer')
18212µs12µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${cl}")}{CODE};
# spent 2µs making 1 call to Moo::_Utils::_getglob
18314µs253µs $methods{$cl} =
# spent 44µs making 1 call to Sub::Quote::quote_sub # spent 9µs making 1 call to Method::Generate::Accessor::_generate_simple_clear
184 quote_sub "${into}::${cl}" =>
185 $self->_generate_simple_clear('$_[0]', $name, $spec)."\n"
186 ;
187 }
18872µs if (my $hspec = $spec->{handles}) {
189 my $asserter = $spec->{asserter} ||= '_assert_'.$name;
190 my @specs = do {
191 if (ref($hspec) eq 'ARRAY') {
192 map [ $_ => $_ ], @$hspec;
193 } elsif (ref($hspec) eq 'HASH') {
194 map [ $_ => ref($hspec->{$_}) ? @{$hspec->{$_}} : $hspec->{$_} ],
195 keys %$hspec;
196 } elsif (!ref($hspec)) {
197 map [ $_ => $_ ], use_module('Moo::Role')->methods_provided_by(use_module($hspec))
198 } else {
199 die "You gave me a handles of ${hspec} and I have no idea why";
200 }
201 };
202 foreach my $delegation_spec (@specs) {
203 my ($proxy, $target, @args) = @$delegation_spec;
204 _die_overwrite($into, $proxy, 'a delegation')
205 if !$spec->{allow_overwrite} && *{_getglob("${into}::${proxy}")}{CODE};
206 $self->{captures} = {};
207 $methods{$proxy} =
208 quote_sub "${into}::${proxy}" =>
209 $self->_generate_delegation($asserter, $target, \@args),
210 delete $self->{captures}
211 ;
212 }
213 }
21472µs if (my $asserter = $spec->{asserter}) {
215 $self->{captures} = {};
216
217
218 $methods{$asserter} =
219 quote_sub "${into}::${asserter}" =>
220 $self->_generate_asserter($name, $spec),
221 delete $self->{captures};
222 }
223717µs \%methods;
224}
225
226sub is_simple_attribute {
227 my ($self, $name, $spec) = @_;
228 # clearer doesn't have to be listed because it doesn't
229 # affect whether defined/exists makes a difference
230 !grep $spec->{$_},
231 qw(lazy default builder coerce isa trigger predicate weak_ref);
232}
233
234
# spent 19µs within Method::Generate::Accessor::is_simple_get which was called 10 times, avg 2µs/call: # 6 times (10µs+0s) by Method::Generate::Accessor::generate_method at line 110, avg 2µs/call # 3 times (5µs+0s) by Method::Generate::Accessor::_generate_get at line 252, avg 2µs/call # once (4µs+0s) by Method::Generate::Accessor::generate_method at line 127
sub is_simple_get {
235104µs my ($self, $name, $spec) = @_;
2361028µs !($spec->{lazy} and (exists $spec->{default} or $spec->{builder}));
237}
238
239
# spent 12µs within Method::Generate::Accessor::is_simple_set which was called 3 times, avg 4µs/call: # 2 times (7µs+0s) by Method::Generate::Accessor::_generate_set at line 340, avg 4µs/call # once (5µs+0s) by Method::Generate::Accessor::generate_method at line 147
sub is_simple_set {
24031µs my ($self, $name, $spec) = @_;
241318µs !grep $spec->{$_}, qw(coerce isa trigger weak_ref);
242}
243
244
# spent 19µs within Method::Generate::Accessor::has_eager_default which was called 13 times, avg 1µs/call: # 11 times (15µs+0s) by Method::Generate::Accessor::_generate_populate_set at line 497, avg 1µs/call # 2 times (4µs+0s) by Method::Generate::Constructor::_assign_new at line 172 of Method/Generate/Constructor.pm, avg 2µs/call
sub has_eager_default {
245133µs my ($self, $name, $spec) = @_;
2461331µs (!$spec->{lazy} and (exists $spec->{default} or $spec->{builder}));
247}
248
249
# spent 369µs (52+316) within Method::Generate::Accessor::_generate_get which was called 3 times, avg 123µs/call: # 2 times (22µs+146µs) by Method::Generate::Accessor::generate_method at line 116, avg 84µs/call # once (30µs+170µs) by Method::Generate::Accessor::_generate_getset at line 609
sub _generate_get {
25032µs my ($self, $name, $spec) = @_;
25134µs324µs my $simple = $self->_generate_simple_get('$_[0]', $name, $spec);
# spent 24µs making 3 calls to Method::Generate::Accessor::_generate_simple_get, avg 8µs/call
252316µs35µs if ($self->is_simple_get($name, $spec)) {
# spent 5µs making 3 calls to Method::Generate::Accessor::is_simple_get, avg 2µs/call
253 $simple;
254 } else {
255316µs6287µs $self->_generate_use_default(
# spent 238µs making 3 calls to Method::Generate::Accessor::_generate_use_default, avg 79µs/call # spent 49µs making 3 calls to Method::Generate::Accessor::_generate_simple_has, avg 16µs/call
256 '$_[0]', $name, $spec,
257 $self->_generate_simple_has('$_[0]', $name, $spec),
258 );
259 }
260}
261
262sub generate_simple_has {
263 my $self = shift;
264 $self->{captures} = {};
265 my $code = $self->_generate_simple_has(@_);
266 ($code, delete $self->{captures});
267}
268
269
# spent 49µs (21+28) within Method::Generate::Accessor::_generate_simple_has which was called 3 times, avg 16µs/call: # 3 times (21µs+28µs) by Method::Generate::Accessor::_generate_get at line 255, avg 16µs/call
sub _generate_simple_has {
27032µs my ($self, $me, $name) = @_;
271316µs328µs "exists ${me}->{${\quotify $name}}";
# spent 28µs making 3 calls to Sub::Quote::quotify, avg 9µs/call
272}
273
274
# spent 9µs (6+3) within Method::Generate::Accessor::_generate_simple_clear which was called: # once (6µs+3µs) by Method::Generate::Accessor::generate_method at line 183
sub _generate_simple_clear {
2751700ns my ($self, $me, $name) = @_;
27615µs13µs " delete ${me}->{${\quotify $name}}\n"
# spent 3µs making 1 call to Sub::Quote::quotify
277}
278
279sub generate_get_default {
280 my $self = shift;
281 $self->{captures} = {};
282 my $code = $self->_generate_get_default(@_);
283 ($code, delete $self->{captures});
284}
285
286sub generate_use_default {
287 my $self = shift;
288 $self->{captures} = {};
289 my $code = $self->_generate_use_default(@_);
290 ($code, delete $self->{captures});
291}
292
293
# spent 238µs (46+193) within Method::Generate::Accessor::_generate_use_default which was called 3 times, avg 79µs/call: # 3 times (46µs+193µs) by Method::Generate::Accessor::_generate_get at line 255, avg 79µs/call
sub _generate_use_default {
29432µs my ($self, $me, $name, $spec, $test) = @_;
29537µs3116µs my $get_value = $self->_generate_get_default($me, $name, $spec);
# spent 116µs making 3 calls to Method::Generate::Accessor::_generate_get_default, avg 39µs/call
29632µs if ($spec->{coerce}) {
297 $get_value = $self->_generate_coerce(
298 $name, $get_value,
299 $spec->{coerce}
300 )
301 }
302325µs677µs $test." ? \n"
# spent 52µs making 3 calls to Method::Generate::Accessor::_generate_simple_set, avg 17µs/call # spent 24µs making 3 calls to Method::Generate::Accessor::_generate_simple_get, avg 8µs/call
303 .$self->_generate_simple_get($me, $name, $spec)."\n:"
304 .($spec->{isa} ?
305 " do {\n my \$value = ".$get_value.";\n"
306 ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n"
307 ." ".$self->_generate_simple_set($me, $name, $spec, '$value')."\n"
308 ." }\n"
309 : ' ('.$self->_generate_simple_set($me, $name, $spec, $get_value).")\n"
310 );
311}
312
313
# spent 125µs (29+95) within Method::Generate::Accessor::_generate_get_default which was called 4 times, avg 31µs/call: # 3 times (24µs+92µs) by Method::Generate::Accessor::_generate_use_default at line 295, avg 39µs/call # once (5µs+3µs) by Method::Generate::Accessor::_generate_populate_set at line 499
sub _generate_get_default {
31442µs my ($self, $me, $name, $spec) = @_;
315422µs495µs if (exists $spec->{default}) {
# spent 89µs making 2 calls to Method::Generate::Accessor::_generate_call_code, avg 45µs/call # spent 6µs making 2 calls to Sub::Quote::quotify, avg 3µs/call
316 ref $spec->{default}
317 ? $self->_generate_call_code($name, 'default', $me, $spec->{default})
318 : quotify $spec->{default};
319 }
320 else {
321 "${me}->${\$spec->{builder}}"
322 }
323}
324
325sub generate_simple_get {
326 my ($self, @args) = @_;
327 $self->{captures} = {};
328 my $code = $self->_generate_simple_get(@args);
329 ($code, delete $self->{captures});
330}
331
332
# spent 48µs (25+23) within Method::Generate::Accessor::_generate_simple_get which was called 6 times, avg 8µs/call: # 3 times (12µs+12µs) by Method::Generate::Accessor::_generate_use_default at line 302, avg 8µs/call # 3 times (13µs+11µs) by Method::Generate::Accessor::_generate_get at line 251, avg 8µs/call
sub _generate_simple_get {
33362µs my ($self, $me, $name) = @_;
33466µs623µs my $name_str = quotify $name;
# spent 23µs making 6 calls to Sub::Quote::quotify, avg 4µs/call
335627µs "${me}->{${name_str}}";
336}
337
338
# spent 117µs (30+87) within Method::Generate::Accessor::_generate_set which was called 2 times, avg 58µs/call: # once (18µs+55µs) by Method::Generate::Accessor::generate_method at line 156 # once (12µs+32µs) by Method::Generate::Accessor::_generate_getset at line 609
sub _generate_set {
33921µs my ($self, $name, $spec) = @_;
340216µs333µs if ($self->is_simple_set($name, $spec)) {
# spent 26µs making 1 call to Method::Generate::Accessor::_generate_simple_set # spent 7µs making 2 calls to Method::Generate::Accessor::is_simple_set, avg 4µs/call
341 $self->_generate_simple_set('$_[0]', $name, $spec, '$_[1]');
342 } else {
34311µs my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)};
3441400ns my $value_store = '$_[0]';
3451100ns my $code;
3461400ns if ($coerce) {
347 $value_store = '$value';
348 $code = "do { my (\$self, \$value) = \@_;\n"
349 ." \$value = "
350 .$self->_generate_coerce($name, $value_store, $coerce).";\n";
351 }
352 else {
3531400ns $code = "do { my \$self = shift;\n";
354 }
3551200ns if ($isa_check) {
356 $code .=
357 " ".$self->_generate_isa_check($name, $value_store, $isa_check).";\n";
358 }
35912µs114µs my $simple = $self->_generate_simple_set('$self', $name, $spec, $value_store);
# spent 14µs making 1 call to Method::Generate::Accessor::_generate_simple_set
3601600ns if ($trigger) {
36113µs140µs my $fire = $self->_generate_trigger($name, '$self', $value_store, $trigger);
# spent 40µs making 1 call to Method::Generate::Accessor::_generate_trigger
36212µs $code .=
363 " ".$simple.";\n ".$fire.";\n"
364 ." $value_store;\n";
365 } else {
366 $code .= " ".$simple.";\n";
367 }
3681200ns $code .= " }";
3691600ns $code;
370 }
371}
372
373sub generate_coerce {
374 my $self = shift;
375 $self->{captures} = {};
376 my $code = $self->_generate_coerce(@_);
377 ($code, delete $self->{captures});
378}
379
380
# spent 8µs (5+3) within Method::Generate::Accessor::_attr_desc which was called: # once (5µs+3µs) by Method::Generate::Accessor::_wrap_attr_exception at line 418
sub _attr_desc {
3811500ns my ($name, $init_arg) = @_;
38214µs13µs return quotify($name) if !defined($init_arg) or $init_arg eq $name;
# spent 3µs making 1 call to Sub::Quote::quotify
383 return quotify($name).' (constructor argument: '.quotify($init_arg).')';
384}
385
386sub _generate_coerce {
387 my ($self, $name, $value, $coerce, $init_arg) = @_;
388 $self->_wrap_attr_exception(
389 $name,
390 "coercion",
391 $init_arg,
392 $self->_generate_call_code($name, 'coerce', "${value}", $coerce),
393 1,
394 );
395}
396
397sub generate_trigger {
398 my $self = shift;
399 $self->{captures} = {};
400 my $code = $self->_generate_trigger(@_);
401 ($code, delete $self->{captures});
402}
403
404
# spent 40µs (5+34) within Method::Generate::Accessor::_generate_trigger which was called: # once (5µs+34µs) by Method::Generate::Accessor::_generate_set at line 361
sub _generate_trigger {
4051600ns my ($self, $name, $obj, $value, $trigger) = @_;
40615µs134µs $self->_generate_call_code($name, 'trigger', "${obj}, ${value}", $trigger);
# spent 34µs making 1 call to Method::Generate::Accessor::_generate_call_code
407}
408
409sub generate_isa_check {
410 my ($self, @args) = @_;
411 $self->{captures} = {};
412 my $code = $self->_generate_isa_check(@args);
413 ($code, delete $self->{captures});
414}
415
416
# spent 39µs (20+19) within Method::Generate::Accessor::_wrap_attr_exception which was called: # once (20µs+19µs) by Method::Generate::Accessor::_generate_isa_check at line 449
sub _wrap_attr_exception {
4171900ns my ($self, $name, $step, $arg, $code, $want_return) = @_;
41814µs212µs my $prefix = quotify("${step} for "._attr_desc($name, $arg).' failed: ');
# spent 8µs making 1 call to Method::Generate::Accessor::_attr_desc # spent 4µs making 1 call to Sub::Quote::quotify
419111µs37µs "do {\n"
# spent 7µs making 3 calls to Sub::Quote::quotify, avg 2µs/call
420 .' local $Method::Generate::Accessor::CurrentAttribute = {'."\n"
421 .' init_arg => '.quotify($arg).",\n"
422 .' name => '.quotify($name).",\n"
423 .' step => '.quotify($step).",\n"
424 ." };\n"
425 .($want_return ? ' my $_return;'."\n" : '')
426 .' my $_error;'."\n"
427 ." {\n"
428 .' my $_old_error = $@;'."\n"
429 ." if (!eval {\n"
430 .' $@ = $_old_error;'."\n"
431 .($want_return ? ' $_return ='."\n" : '')
432 .' '.$code.";\n"
433 ." 1;\n"
434 ." }) {\n"
435 .' $_error = $@;'."\n"
436 .' if (!ref $_error) {'."\n"
437 .' $_error = '.$prefix.'.$_error;'."\n"
438 ." }\n"
439 ." }\n"
440 .' $@ = $_old_error;'."\n"
441 ." }\n"
442 .' die $_error if $_error;'."\n"
443 .($want_return ? ' $_return;'."\n" : '')
444 ."}\n"
445}
446
447
# spent 85µs (9+76) within Method::Generate::Accessor::_generate_isa_check which was called: # once (9µs+76µs) by Method::Generate::Accessor::_generate_populate_set at line 533
sub _generate_isa_check {
4481600ns my ($self, $name, $value, $check, $init_arg) = @_;
44916µs276µs $self->_wrap_attr_exception(
# spent 39µs making 1 call to Method::Generate::Accessor::_wrap_attr_exception # spent 37µs making 1 call to Method::Generate::Accessor::_generate_call_code
450 $name,
451 "isa check",
452 $init_arg,
453 $self->_generate_call_code($name, 'isa_check', $value, $check)
454 );
455}
456
457
# spent 161µs (56+105) within Method::Generate::Accessor::_generate_call_code which was called 4 times, avg 40µs/call: # 2 times (33µs+56µs) by Method::Generate::Accessor::_generate_get_default at line 315, avg 45µs/call # once (12µs+25µs) by Method::Generate::Accessor::_generate_isa_check at line 449 # once (10µs+25µs) by Method::Generate::Accessor::_generate_trigger at line 406
sub _generate_call_code {
45842µs my ($self, $name, $type, $values, $sub) = @_;
459416µs44µs $sub = \&{$sub} if blessed($sub); # coderef if blessed
# spent 4µs making 4 calls to Scalar::Util::blessed, avg 1µs/call
460425µs429µs if (my $quoted = quoted_from_sub($sub)) {
# spent 29µs making 4 calls to Sub::Quote::quoted_from_sub, avg 7µs/call
46141µs my $local = 1;
46243µs if ($values eq '@_' || $values eq '$_[0]') {
4632500ns $local = 0;
4642900ns $values = '@_';
465 }
46642µs my $code = $quoted->[1];
46742µs if (my $captures = $quoted->[2]) {
468 my $cap_name = qq{\$${type}_captures_for_}.$self->_sanitize_name($name);
469 $self->{captures}->{$cap_name} = \$captures;
470 Sub::Quote::inlinify($code, $values,
471 Sub::Quote::capture_unroll($cap_name, $captures, 6), $local);
472 } else {
47349µs472µs Sub::Quote::inlinify($code, $values, undef, $local);
# spent 72µs making 4 calls to Sub::Quote::inlinify, avg 18µs/call
474 }
475 } else {
476 my $cap_name = qq{\$${type}_for_}.$self->_sanitize_name($name);
477 $self->{captures}->{$cap_name} = \$sub;
478 "${cap_name}->(${values})";
479 }
480}
481
482sub _sanitize_name {
483 my ($self, $name) = @_;
484 $name =~ s/([_\W])/sprintf('_%x', ord($1))/ge;
485 $name;
486}
487
488
# spent 398µs (52+345) within Method::Generate::Accessor::generate_populate_set which was called 11 times, avg 36µs/call: # 11 times (52µs+345µs) by Method::Generate::Constructor::_assign_new at line 181 of Method/Generate/Constructor.pm, avg 36µs/call
sub generate_populate_set {
489112µs my $self = shift;
4901110µs $self->{captures} = {};
4911112µs11345µs my $code = $self->_generate_populate_set(@_);
# spent 345µs making 11 calls to Method::Generate::Accessor::_generate_populate_set, avg 31µs/call
4921122µs ($code, delete $self->{captures});
493}
494
495
# spent 345µs (94+251) within Method::Generate::Accessor::_generate_populate_set which was called 11 times, avg 31µs/call: # 11 times (94µs+251µs) by Method::Generate::Accessor::generate_populate_set at line 491, avg 31µs/call
sub _generate_populate_set {
496116µs my ($self, $me, $name, $spec, $source, $test, $init_arg) = @_;
4971133µs1115µs if ($self->has_eager_default($name, $spec)) {
# spent 15µs making 11 calls to Method::Generate::Accessor::has_eager_default, avg 1µs/call
49812µs my $get_indent = ' ' x ($spec->{isa} ? 6 : 4);
49912µs18µs my $get_default = $self->_generate_get_default(
# spent 8µs making 1 call to Method::Generate::Accessor::_generate_get_default
500 '$new', $name, $spec
501 );
50214µs my $get_value =
503 defined($spec->{init_arg})
504 ? "(\n${get_indent} ${test}\n"
505 ."${get_indent} ? ${source}\n${get_indent} : "
506 .$get_default
507 ."\n${get_indent})"
508 : $get_default;
5091500ns if ($spec->{coerce}) {
510 $get_value = $self->_generate_coerce(
511 $name, $get_value,
512 $spec->{coerce}, $init_arg
513 )
514 }
51514µs118µs ($spec->{isa}
# spent 18µs making 1 call to Method::Generate::Accessor::_generate_simple_set
516 ? " {\n my \$value = ".$get_value.";\n "
517 .$self->_generate_isa_check(
518 $name, '$value', $spec->{isa}, $init_arg
519 ).";\n"
520 .' '.$self->_generate_simple_set($me, $name, $spec, '$value').";\n"
521 ." }\n"
522 : ' '.$self->_generate_simple_set($me, $name, $spec, $get_value).";\n"
523 )
524 .($spec->{trigger}
525 ? ' '
526 .$self->_generate_trigger(
527 $name, $me, $self->_generate_simple_get($me, $name, $spec),
528 $spec->{trigger}
529 )." if ${test};\n"
530 : ''
531 );
532 } else {
5331030µs11210µs " if (${test}) {\n"
# spent 124µs making 10 calls to Method::Generate::Accessor::_generate_simple_set, avg 12µs/call # spent 85µs making 1 call to Method::Generate::Accessor::_generate_isa_check
534 .($spec->{coerce}
535 ? " $source = "
536 .$self->_generate_coerce(
537 $name, $source,
538 $spec->{coerce}, $init_arg
539 ).";\n"
540 : ""
541 )
542 .($spec->{isa}
543 ? " "
544 .$self->_generate_isa_check(
545 $name, $source, $spec->{isa}, $init_arg
546 ).";\n"
547 : ""
548 )
549 ." ".$self->_generate_simple_set($me, $name, $spec, $source).";\n"
550 .($spec->{trigger}
551 ? " "
552 .$self->_generate_trigger(
553 $name, $me, $self->_generate_simple_get($me, $name, $spec),
554 $spec->{trigger}
555 ).";\n"
556 : ""
557 )
558 ." }\n";
559 }
560}
561
562
# spent 96µs (56+40) within Method::Generate::Accessor::_generate_core_set which was called 16 times, avg 6µs/call: # 16 times (56µs+40µs) by Method::Generate::Accessor::_generate_simple_set at line 571, avg 6µs/call
sub _generate_core_set {
563166µs my ($self, $me, $name, $spec, $value) = @_;
5641611µs1640µs my $name_str = quotify $name;
# spent 40µs making 16 calls to Sub::Quote::quotify, avg 2µs/call
5651642µs "${me}->{${name_str}} = ${value}";
566}
567
568
# spent 235µs (93+142) within Method::Generate::Accessor::_generate_simple_set which was called 16 times, avg 15µs/call: # 10 times (50µs+75µs) by Method::Generate::Accessor::_generate_populate_set at line 533, avg 12µs/call # 3 times (21µs+31µs) by Method::Generate::Accessor::_generate_use_default at line 302, avg 17µs/call # once (9µs+17µs) by Method::Generate::Accessor::_generate_set at line 340 # once (8µs+10µs) by Method::Generate::Accessor::_generate_populate_set at line 515 # once (5µs+9µs) by Method::Generate::Accessor::_generate_set at line 359
sub _generate_simple_set {
569167µs my ($self, $me, $name, $spec, $value) = @_;
5701613µs1646µs my $name_str = quotify $name;
# spent 46µs making 16 calls to Sub::Quote::quotify, avg 3µs/call
5711618µs1696µs my $simple = $self->_generate_core_set($me, $name, $spec, $value);
# spent 96µs making 16 calls to Method::Generate::Accessor::_generate_core_set, avg 6µs/call
572
5731639µs if ($spec->{weak_ref}) {
574 require Scalar::Util;
575 my $get = $self->_generate_simple_get($me, $name, $spec);
576
577 # Perl < 5.8.3 can't weaken refs to readonly vars
578 # (e.g. string constants). This *can* be solved by:
579 #
580 # &Internals::SvREADONLY($foo, 0);
581 # Scalar::Util::weaken($foo);
582 # &Internals::SvREADONLY($foo, 1);
583 #
584 # but requires Internal functions and is just too damn crazy
585 # so simply throw a better exception
586 my $weak_simple = "do { Scalar::Util::weaken(${simple}); no warnings 'void'; $get }";
587 Moo::_Utils::lt_5_8_3() ? <<"EOC" : $weak_simple;
588 eval { Scalar::Util::weaken($simple); 1 }
589 ? do { no warnings 'void'; $get }
590 : do {
591 if( \$@ =~ /Modification of a read-only value attempted/) {
592 require Carp;
593 Carp::croak( sprintf (
594 'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3',
595 $name_str,
596 ) );
597 } else {
598 die \$@;
599 }
600 }
601EOC
602 } else {
603165µs $simple;
604 }
605}
606
607
# spent 258µs (14+244) within Method::Generate::Accessor::_generate_getset which was called: # once (14µs+244µs) by Method::Generate::Accessor::generate_method at line 137
sub _generate_getset {
6081600ns my ($self, $name, $spec) = @_;
60919µs2244µs q{(@_ > 1}."\n ? ".$self->_generate_set($name, $spec)
# spent 200µs making 1 call to Method::Generate::Accessor::_generate_get # spent 44µs making 1 call to Method::Generate::Accessor::_generate_set
610 ."\n : ".$self->_generate_get($name, $spec)."\n )";
611}
612
613sub _generate_asserter {
614 my ($self, $name, $spec) = @_;
615
616 "do {\n"
617 ." my \$val = ".$self->_generate_get($name, $spec).";\n"
618 ." unless (".$self->_generate_simple_has('$_[0]', $name, $spec).") {\n"
619 .qq! die "Attempted to access '${name}' but it is not set";\n!
620 ." }\n"
621 ." \$val;\n"
622 ."}\n";
623}
624sub _generate_delegation {
625 my ($self, $asserter, $target, $args) = @_;
626 my $arg_string = do {
627 if (@$args) {
628 # I could, I reckon, linearise out non-refs here using quotify
629 # plus something to check for numbers but I'm unsure if it's worth it
630 $self->{captures}{'@curries'} = $args;
631 '@curries, @_';
632 } else {
633 '@_';
634 }
635 };
636 "shift->${asserter}->${target}(${arg_string});";
637}
638
639
# spent 292µs (32+260) within Method::Generate::Accessor::_generate_xs which was called 4 times, avg 73µs/call: # 4 times (32µs+260µs) by Method::Generate::Accessor::generate_method at line 110, avg 73µs/call
sub _generate_xs {
64042µs my ($self, $type, $into, $name, $slot) = @_;
641412µs4251µs Class::XSAccessor->import(
# spent 251µs making 4 calls to Class::XSAccessor::import, avg 63µs/call
642 class => $into,
643 $type => { $name => $slot },
644 replace => 1,
645 );
646425µs49µs $into->can($name);
# spent 9µs making 4 calls to UNIVERSAL::can, avg 2µs/call
647}
648
64915µs
# spent 2µs within Method::Generate::Accessor::default_construction_string which was called: # once (2µs+0s) by Method::Generate::Constructor::_build_construction_string at line 68 of Method/Generate/Constructor.pm
sub default_construction_string { '{}' }
650
651
# spent 34µs (26+8) within Method::Generate::Accessor::_validate_codulatable which was called 3 times, avg 11µs/call: # 2 times (16µs+4µs) by Method::Generate::Accessor::generate_method at line 89, avg 10µs/call # once (10µs+3µs) by Method::Generate::Accessor::generate_method at line 86
sub _validate_codulatable {
65231µs my ($self, $setting, $value, $into, $appended) = @_;
653320µs38µs my $invalid = "Invalid $setting '" . overload::StrVal($value)
# spent 8µs making 3 calls to overload::AddrRef, avg 3µs/call
654 . "' for $into not a coderef";
65532µs $invalid .= " $appended" if $appended;
656
65732µs unless (ref $value and (ref $value eq 'CODE' or blessed($value))) {
658 die "$invalid or code-convertible object";
659 }
660
66164µs unless (eval { \&$value }) {
662 die "$invalid and could not be converted to a coderef: $@";
663 }
664
66538µs 1;
666}
667
66816µs1;
 
# spent 2µs within Method::Generate::Accessor::CORE:qr which was called: # once (2µs+0s) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 25
sub Method::Generate::Accessor::CORE:qr; # opcode
# spent 18µs within Method::Generate::Accessor::CORE:regcomp which was called: # once (18µs+0s) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 25
sub Method::Generate::Accessor::CORE:regcomp; # opcode
# spent 2µs within Method::Generate::Accessor::CORE:subst which was called 7 times, avg 257ns/call: # 7 times (2µs+0s) by Method::Generate::Accessor::generate_method at line 36, avg 257ns/call
sub Method::Generate::Accessor::CORE:subst; # opcode