← Index
NYTProf Performance Profile   « line view »
For index.cgi
  Run on Sat May 9 17:18:47 2020
Reported on Sat May 9 17:19:07 2020

Filename/usr/local/share/perl/5.18.2/Method/Generate/Accessor.pm
StatementsExecuted 913 statements in 7.58ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
12217.58ms7.80msMethod::Generate::Accessor::::_generate_call_codeMethod::Generate::Accessor::_generate_call_code
1111.49ms2.14msMethod::Generate::Accessor::::BEGIN@9Method::Generate::Accessor::BEGIN@9
911302µs1.43msMethod::Generate::Accessor::::generate_methodMethod::Generate::Accessor::generate_method
1511279µs8.71msMethod::Generate::Accessor::::_generate_populate_setMethod::Generate::Accessor::_generate_populate_set
1511136µs380µsMethod::Generate::Accessor::::_generate_simple_setMethod::Generate::Accessor::_generate_simple_set
1211135µs186µsMethod::Generate::Accessor::::_sanitize_nameMethod::Generate::Accessor::_sanitize_name
1511108µs8.82msMethod::Generate::Accessor::::generate_populate_setMethod::Generate::Accessor::generate_populate_set
122199µs119µsMethod::Generate::Accessor::::_validate_codulatableMethod::Generate::Accessor::_validate_codulatable
151194µs166µsMethod::Generate::Accessor::::_generate_core_setMethod::Generate::Accessor::_generate_core_set
92191µs972µsMethod::Generate::Accessor::::_generate_xsMethod::Generate::Accessor::_generate_xs
31161µs138µsMethod::Generate::Accessor::::_wrap_attr_exceptionMethod::Generate::Accessor::_wrap_attr_exception
91148µs7.76msMethod::Generate::Accessor::::_generate_get_defaultMethod::Generate::Accessor::_generate_get_default
151138µs38µsMethod::Generate::Accessor::::has_eager_defaultMethod::Generate::Accessor::has_eager_default
212137µs37µsMethod::Generate::Accessor::::CORE:substMethod::Generate::Accessor::CORE:subst (opcode)
31125µs254µsMethod::Generate::Accessor::::_generate_isa_checkMethod::Generate::Accessor::_generate_isa_check
11124µs2.34msMethod::Generate::Accessor::::BEGIN@11Method::Generate::Accessor::BEGIN@11
11120µs20µsMethod::Generate::Accessor::::CORE:regcompMethod::Generate::Accessor::CORE:regcomp (opcode)
92120µs20µsMethod::Generate::Accessor::::is_simple_getMethod::Generate::Accessor::is_simple_get
141117µs17µsMethod::Generate::Accessor::::CORE:substcontMethod::Generate::Accessor::CORE:substcont (opcode)
31116µs30µsMethod::Generate::Accessor::::_attr_descMethod::Generate::Accessor::_attr_desc
11115µs48µsMethod::Generate::Accessor::::BEGIN@3Method::Generate::Accessor::BEGIN@3
41115µs15µsMethod::Generate::Accessor::::is_simple_setMethod::Generate::Accessor::is_simple_set
11111µs32µsMethod::Generate::Accessor::::BEGIN@10Method::Generate::Accessor::BEGIN@10
11111µs106µsMethod::Generate::Accessor::::BEGIN@4Method::Generate::Accessor::BEGIN@4
11110µs53µsMethod::Generate::Accessor::::BEGIN@7Method::Generate::Accessor::BEGIN@7
1119µs40µsMethod::Generate::Accessor::::BEGIN@8Method::Generate::Accessor::BEGIN@8
1118µs8µsMethod::Generate::Accessor::::BEGIN@5Method::Generate::Accessor::BEGIN@5
2113µs3µsMethod::Generate::Accessor::::default_construction_stringMethod::Generate::Accessor::default_construction_string
1112µs2µsMethod::Generate::Accessor::::CORE:qrMethod::Generate::Accessor::CORE:qr (opcode)
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::::_generate_getMethod::Generate::Accessor::_generate_get
0000s0sMethod::Generate::Accessor::::_generate_getsetMethod::Generate::Accessor::_generate_getset
0000s0sMethod::Generate::Accessor::::_generate_setMethod::Generate::Accessor::_generate_set
0000s0sMethod::Generate::Accessor::::_generate_simple_clearMethod::Generate::Accessor::_generate_simple_clear
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::::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::::has_defaultMethod::Generate::Accessor::has_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
3235µs280µs
# spent 48µs (15+32) within Method::Generate::Accessor::BEGIN@3 which was called: # once (15µs+32µs) by Moo::_accessor_maker_for at line 3
use Moo::_strictures;
# spent 48µs making 1 call to Method::Generate::Accessor::BEGIN@3 # spent 32µs making 1 call to Moo::_strictures::import
4247µs2202µs
# spent 106µs (11+96) within Method::Generate::Accessor::BEGIN@4 which was called: # once (11µs+96µs) by Moo::_accessor_maker_for at line 4
use Moo::_Utils;
# spent 106µs making 1 call to Method::Generate::Accessor::BEGIN@4 # spent 96µs making 1 call to Exporter::import
5259µs18µs
# spent 8µs within Method::Generate::Accessor::BEGIN@5 which was called: # once (8µs+0s) by Moo::_accessor_maker_for at line 5
use Moo::Object ();
# spent 8µs making 1 call to Method::Generate::Accessor::BEGIN@5
6110µsour @ISA = qw(Moo::Object);
7236µs297µs
# spent 53µs (10+44) within Method::Generate::Accessor::BEGIN@7 which was called: # once (10µs+44µs) by Moo::_accessor_maker_for at line 7
use Sub::Quote qw(quote_sub quoted_from_sub quotify);
# spent 53µs making 1 call to Method::Generate::Accessor::BEGIN@7 # spent 44µs making 1 call to Exporter::import
8230µs272µs
# spent 40µs (9+31) within Method::Generate::Accessor::BEGIN@8 which was called: # once (9µs+31µs) by Moo::_accessor_maker_for at line 8
use Scalar::Util 'blessed';
# spent 40µs making 1 call to Method::Generate::Accessor::BEGIN@8 # spent 31µs making 1 call to Exporter::import
92682µs12.14ms
# spent 2.14ms (1.49+652µs) within Method::Generate::Accessor::BEGIN@9 which was called: # once (1.49ms+652µs) by Moo::_accessor_maker_for at line 9
use overload ();
# spent 2.14ms making 1 call to Method::Generate::Accessor::BEGIN@9
102102µs253µs
# spent 32µs (11+21) within Method::Generate::Accessor::BEGIN@10 which was called: # once (11µs+21µs) by Moo::_accessor_maker_for at line 10
use Module::Runtime qw(use_module);
# spent 32µs making 1 call to Method::Generate::Accessor::BEGIN@10 # spent 21µs making 1 call to Module::Runtime::import
11
# spent 2.34ms (24µs+2.31) within Method::Generate::Accessor::BEGIN@11 which was called: # once (24µs+2.31ms) by Moo::_accessor_maker_for at line 23
BEGIN {
12 our $CAN_HAZ_XS =
13 !$ENV{MOO_XS_DISABLE}
14 &&
15 _maybe_load_module('Class::XSAccessor')
16 &&
17220µs22.31ms (eval { Class::XSAccessor->VERSION('1.07') })
# spent 2.30ms making 1 call to Moo::_Utils::_maybe_load_module # spent 7µs making 1 call to UNIVERSAL::VERSION
18 ;
19 our $CAN_HAZ_XS_PRED =
20 $CAN_HAZ_XS &&
21212µs14µs (eval { Class::XSAccessor->VERSION('1.17') })
# spent 4µs making 1 call to UNIVERSAL::VERSION
22 ;
2314.86ms12.34ms}
# spent 2.34ms making 1 call to Method::Generate::Accessor::BEGIN@11
24
25136µs222µsmy $module_name_only = qr/\A$Module::Runtime::module_name_rx\z/;
# spent 20µ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.43ms (302µs+1.13) within Method::Generate::Accessor::generate_method which was called 9 times, avg 159µs/call: # 9 times (302µs+1.13ms) by Moo::has at line 57 of Moo.pm, avg 159µs/call
sub generate_method {
3596µs my ($self, $into, $name, $spec, $quote_opts) = @_;
36924µs93µs $spec->{allow_overwrite}++ if $name =~ s/^\+//;
# spent 3µs making 9 calls to Method::Generate::Accessor::CORE:subst, avg 311ns/call
3796µs die "Must have an is" unless my $is = $spec->{is};
38913µ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 }
5394µ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 }
6494µs if (($spec->{predicate}||0) eq 1) {
65 $spec->{predicate} = $name =~ /^_/ ? "_has${name}" : "has_${name}";
66 }
6793µs if (($spec->{clearer}||0) eq 1) {
68 $spec->{clearer} = $name =~ /^_/ ? "_clear${name}" : "clear_${name}";
69 }
7093µs if (($spec->{trigger}||0) eq 1) {
71 $spec->{trigger} = quote_sub('shift->_trigger_'.$name.'(@_)');
72 }
7393µ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
84916µs foreach my $setting (qw( isa coerce )) {
85189µs next if !exists $spec->{$setting};
8637µs329µs $self->_validate_codulatable($setting, $spec->{$setting}, "$into->$name");
# spent 29µs making 3 calls to Method::Generate::Accessor::_validate_codulatable, avg 10µs/call
87 }
88
89923µs990µs if (exists $spec->{default}) {
# spent 90µs making 9 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
9694µs if (exists $spec->{moosify}) {
97 if (ref $spec->{moosify} ne 'ARRAY') {
98 $spec->{moosify} = [$spec->{moosify}];
99 }
100
101 foreach my $spec (@{$spec->{moosify}}) {
102 $self->_validate_codulatable('moosify', $spec, "$into->$name");
103 }
104 }
105
10692µs my %methods;
10796µs if (my $reader = $spec->{reader}) {
108 _die_overwrite($into, $reader, 'a reader')
109517µs if !$spec->{allow_overwrite} && defined &{"${into}::${reader}"};
110519µs10544µs if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) {
# spent 533µs making 5 calls to Method::Generate::Accessor::_generate_xs, avg 107µs/call # spent 11µs making 5 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 {
115 $self->{captures} = {};
116 $methods{$reader} =
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 }
12497µs if (my $accessor = $spec->{accessor}) {
125 _die_overwrite($into, $accessor, 'an accessor')
126414µs if !$spec->{allow_overwrite} && defined &{"${into}::${accessor}"};
127422µs12463µs if (
# spent 439µs making 4 calls to Method::Generate::Accessor::_generate_xs, avg 110µs/call # spent 15µs making 4 calls to Method::Generate::Accessor::is_simple_set, avg 4µs/call # spent 9µs making 4 calls to Method::Generate::Accessor::is_simple_get, avg 2µs/call
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 {
136 $self->{captures} = {};
137 $methods{$accessor} =
138 quote_sub "${into}::${accessor}"
139 => $self->_generate_getset($name, $spec)
140 => delete $self->{captures}
141 ;
142 }
143 }
14494µs if (my $writer = $spec->{writer}) {
145 _die_overwrite($into, $writer, 'a writer')
146 if !$spec->{allow_overwrite} && defined &{"${into}::${writer}"};
147 if (
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 {
155 $self->{captures} = {};
156 $methods{$writer} =
157 quote_sub "${into}::${writer}"
158 => $self->_generate_set($name, $spec)
159 => delete $self->{captures}
160 ;
161 }
162 }
16393µs if (my $pred = $spec->{predicate}) {
164 _die_overwrite($into, $pred, 'a predicate')
165 if !$spec->{allow_overwrite} && defined &{"${into}::${pred}"};
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 }
17793µs if (my $pred = $spec->{builder_sub}) {
178 _install_coderef( "${into}::$spec->{builder}" => $spec->{builder_sub} );
179 }
18093µs if (my $cl = $spec->{clearer}) {
181 _die_overwrite($into, $cl, 'a clearer')
182 if !$spec->{allow_overwrite} && defined &{"${into}::${cl}"};
183 $methods{$cl} =
184 quote_sub "${into}::${cl}" =>
185 $self->_generate_simple_clear('$_[0]', $name, $spec)."\n"
186 ;
187 }
18893µ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} && defined &{"${into}::${proxy}"};
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 }
21493µ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 }
223925µ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 20µs within Method::Generate::Accessor::is_simple_get which was called 9 times, avg 2µs/call: # 5 times (11µs+0s) by Method::Generate::Accessor::generate_method at line 110, avg 2µs/call # 4 times (9µs+0s) by Method::Generate::Accessor::generate_method at line 127, avg 2µs/call
sub is_simple_get {
23595µs my ($self, $name, $spec) = @_;
236936µs !($spec->{lazy} and (exists $spec->{default} or $spec->{builder}));
237}
238
239
# spent 15µs within Method::Generate::Accessor::is_simple_set which was called 4 times, avg 4µs/call: # 4 times (15µs+0s) by Method::Generate::Accessor::generate_method at line 127, avg 4µs/call
sub is_simple_set {
24042µs my ($self, $name, $spec) = @_;
241419µs !grep $spec->{$_}, qw(coerce isa trigger weak_ref);
242}
243
244sub has_default {
245 my ($self, $name, $spec) = @_;
246 $spec->{builder} or exists $spec->{default} or (($spec->{is}||'') eq 'lazy');
247}
248
249
# spent 38µs within Method::Generate::Accessor::has_eager_default which was called 15 times, avg 3µs/call: # 15 times (38µs+0s) by Method::Generate::Accessor::_generate_populate_set at line 494, avg 3µs/call
sub has_eager_default {
250156µs my ($self, $name, $spec) = @_;
2511562µs (!$spec->{lazy} and (exists $spec->{default} or $spec->{builder}));
252}
253
254sub _generate_get {
255 my ($self, $name, $spec) = @_;
256 my $simple = $self->_generate_simple_get('$_[0]', $name, $spec);
257 if ($self->is_simple_get($name, $spec)) {
258 $simple;
259 } else {
260 $self->_generate_use_default(
261 '$_[0]', $name, $spec,
262 $self->_generate_simple_has('$_[0]', $name, $spec),
263 );
264 }
265}
266
267sub generate_simple_has {
268 my $self = shift;
269 $self->{captures} = {};
270 my $code = $self->_generate_simple_has(@_);
271 ($code, delete $self->{captures});
272}
273
274sub _generate_simple_has {
275 my ($self, $me, $name) = @_;
276 "exists ${me}->{${\quotify $name}}";
277}
278
279sub _generate_simple_clear {
280 my ($self, $me, $name) = @_;
281 " delete ${me}->{${\quotify $name}}\n"
282}
283
284sub generate_get_default {
285 my $self = shift;
286 $self->{captures} = {};
287 my $code = $self->_generate_get_default(@_);
288 ($code, delete $self->{captures});
289}
290
291sub generate_use_default {
292 my $self = shift;
293 $self->{captures} = {};
294 my $code = $self->_generate_use_default(@_);
295 ($code, delete $self->{captures});
296}
297
298sub _generate_use_default {
299 my ($self, $me, $name, $spec, $test) = @_;
300 my $get_value = $self->_generate_get_default($me, $name, $spec);
301 if ($spec->{coerce}) {
302 $get_value = $self->_generate_coerce(
303 $name, $get_value,
304 $spec->{coerce}
305 )
306 }
307 $test." ? \n"
308 .$self->_generate_simple_get($me, $name, $spec)."\n:"
309 .($spec->{isa} ?
310 " do {\n my \$value = ".$get_value.";\n"
311 ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n"
312 ." ".$self->_generate_simple_set($me, $name, $spec, '$value')."\n"
313 ." }\n"
314 : ' ('.$self->_generate_simple_set($me, $name, $spec, $get_value).")\n"
315 );
316}
317
318
# spent 7.76ms (48µs+7.71) within Method::Generate::Accessor::_generate_get_default which was called 9 times, avg 862µs/call: # 9 times (48µs+7.71ms) by Method::Generate::Accessor::_generate_populate_set at line 499, avg 862µs/call
sub _generate_get_default {
31995µs my ($self, $me, $name, $spec) = @_;
320940µs97.71ms if (exists $spec->{default}) {
# spent 7.71ms making 9 calls to Method::Generate::Accessor::_generate_call_code, avg 857µs/call
321 ref $spec->{default}
322 ? $self->_generate_call_code($name, 'default', $me, $spec->{default})
323 : quotify $spec->{default};
324 }
325 else {
326 "${me}->${\$spec->{builder}}"
327 }
328}
329
330sub generate_simple_get {
331 my ($self, @args) = @_;
332 $self->{captures} = {};
333 my $code = $self->_generate_simple_get(@args);
334 ($code, delete $self->{captures});
335}
336
337sub _generate_simple_get {
338 my ($self, $me, $name) = @_;
339 my $name_str = quotify $name;
340 "${me}->{${name_str}}";
341}
342
343sub _generate_set {
344 my ($self, $name, $spec) = @_;
345 my ($me, $source) = ('$_[0]', '$_[1]');
346 if ($self->is_simple_set($name, $spec)) {
347 return $self->_generate_simple_set($me, $name, $spec, $source);
348 }
349
350 my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)};
351 if ($coerce) {
352 $source = $self->_generate_coerce($name, $source, $coerce);
353 }
354 if ($isa_check) {
355 $source = 'scalar do { my $value = '.$source.";\n"
356 .' ('.$self->_generate_isa_check($name, '$value', $isa_check)."),\n"
357 .($trigger
358 ? '('.$self->_generate_trigger($name, $me, '$value', $trigger).'),'
359 : '')
360 ." \$value\n"
361 ."}";
362 }
363 my $set = $self->_generate_simple_set($me, $name, $spec, $source);
364 if (!$isa_check && $trigger) {
365 "scalar (\n"
366 . ' ('.$self->_generate_trigger($name, $me, "($set)", $trigger)."),\n"
367 . ' ('.$self->_generate_simple_get($me, $name, $spec)."),\n"
368 . ")";
369 }
370 else {
371 "($set)";
372 }
373}
374
375sub generate_coerce {
376 my $self = shift;
377 $self->{captures} = {};
378 my $code = $self->_generate_coerce(@_);
379 ($code, delete $self->{captures});
380}
381
382
# spent 30µs (16+15) within Method::Generate::Accessor::_attr_desc which was called 3 times, avg 10µs/call: # 3 times (16µs+15µs) by Method::Generate::Accessor::_wrap_attr_exception at line 420, avg 10µs/call
sub _attr_desc {
38331µs my ($name, $init_arg) = @_;
384314µs315µs return quotify($name) if !defined($init_arg) or $init_arg eq $name;
# spent 15µs making 3 calls to Sub::Quote::quotify, avg 5µs/call
385 return quotify($name).' (constructor argument: '.quotify($init_arg).')';
386}
387
388sub _generate_coerce {
389 my ($self, $name, $value, $coerce, $init_arg) = @_;
390 $self->_wrap_attr_exception(
391 $name,
392 "coercion",
393 $init_arg,
394 $self->_generate_call_code($name, 'coerce', "${value}", $coerce),
395 1,
396 );
397}
398
399sub generate_trigger {
400 my $self = shift;
401 $self->{captures} = {};
402 my $code = $self->_generate_trigger(@_);
403 ($code, delete $self->{captures});
404}
405
406sub _generate_trigger {
407 my ($self, $name, $obj, $value, $trigger) = @_;
408 $self->_generate_call_code($name, 'trigger', "${obj}, ${value}", $trigger);
409}
410
411sub generate_isa_check {
412 my ($self, @args) = @_;
413 $self->{captures} = {};
414 my $code = $self->_generate_isa_check(@args);
415 ($code, delete $self->{captures});
416}
417
418
# spent 138µs (61+77) within Method::Generate::Accessor::_wrap_attr_exception which was called 3 times, avg 46µs/call: # 3 times (61µs+77µs) by Method::Generate::Accessor::_generate_isa_check at line 445, avg 46µs/call
sub _wrap_attr_exception {
41933µs my ($self, $name, $step, $arg, $code, $want_return) = @_;
420312µs645µs my $prefix = quotify("${step} for "._attr_desc($name, $arg).' failed: ');
# spent 30µs making 3 calls to Method::Generate::Accessor::_attr_desc, avg 10µs/call # spent 14µs making 3 calls to Sub::Quote::quotify, avg 5µs/call
421329µs932µs "do {\n"
# spent 32µs making 9 calls to Sub::Quote::quotify, avg 4µs/call
422 .' local $Method::Generate::Accessor::CurrentAttribute = {'."\n"
423 .' init_arg => '.quotify($arg).",\n"
424 .' name => '.quotify($name).",\n"
425 .' step => '.quotify($step).",\n"
426 ." };\n"
427 .($want_return ? ' (my $_return),'."\n" : '')
428 .' (my $_error), (my $_old_error = $@);'."\n"
429 ." (eval {\n"
430 .' ($@ = $_old_error),'."\n"
431 .' ('
432 .($want_return ? '$_return ='."\n" : '')
433 .$code."),\n"
434 ." 1\n"
435 ." } or\n"
436 .' $_error = ref $@ ? $@ : '.$prefix.'.$@);'."\n"
437 .' ($@ = $_old_error),'."\n"
438 .' (defined $_error and die $_error);'."\n"
439 .($want_return ? ' $_return;'."\n" : '')
440 ."}\n"
441}
442
443
# spent 254µs (25+229) within Method::Generate::Accessor::_generate_isa_check which was called 3 times, avg 85µs/call: # 3 times (25µs+229µs) by Method::Generate::Accessor::_generate_populate_set at line 514, avg 85µs/call
sub _generate_isa_check {
44432µs my ($self, $name, $value, $check, $init_arg) = @_;
445321µs6229µs $self->_wrap_attr_exception(
# spent 138µs making 3 calls to Method::Generate::Accessor::_wrap_attr_exception, avg 46µs/call # spent 91µs making 3 calls to Method::Generate::Accessor::_generate_call_code, avg 30µs/call
446 $name,
447 "isa check",
448 $init_arg,
449 $self->_generate_call_code($name, 'isa_check', $value, $check)
450 );
451}
452
453
# spent 7.80ms (7.58+226µs) within Method::Generate::Accessor::_generate_call_code which was called 12 times, avg 650µs/call: # 9 times (7.54ms+170µs) by Method::Generate::Accessor::_generate_get_default at line 320, avg 857µs/call # 3 times (36µs+56µs) by Method::Generate::Accessor::_generate_isa_check at line 445, avg 30µs/call
sub _generate_call_code {
454127µs my ($self, $name, $type, $values, $sub) = @_;
4551239µs129µs $sub = \&{$sub} if blessed($sub); # coderef if blessed
# spent 9µs making 12 calls to Scalar::Util::blessed, avg 783ns/call
4561253µs1230µs if (my $quoted = quoted_from_sub($sub)) {
# spent 30µs making 12 calls to Sub::Quote::quoted_from_sub, avg 3µs/call
457 my $local = 1;
458 if ($values eq '@_' || $values eq '$_[0]') {
459 $local = 0;
460 $values = '@_';
461 }
462 my $code = $quoted->[1];
463 if (my $captures = $quoted->[2]) {
464 my $cap_name = qq{\$${type}_captures_for_}.$self->_sanitize_name($name);
465 $self->{captures}->{$cap_name} = \$captures;
466 Sub::Quote::inlinify($code, $values,
467 Sub::Quote::capture_unroll($cap_name, $captures, 6), $local);
468 } else {
469 Sub::Quote::inlinify($code, $values, undef, $local);
470 }
471 } else {
4721232µs12186µs my $cap_name = qq{\$${type}_for_}.$self->_sanitize_name($name);
# spent 186µs making 12 calls to Method::Generate::Accessor::_sanitize_name, avg 16µs/call
4731219µs $self->{captures}->{$cap_name} = \$sub;
4741211µs "${cap_name}->(${values})";
475 }
476}
477
478
# spent 186µs (135+51) within Method::Generate::Accessor::_sanitize_name which was called 12 times, avg 16µs/call: # 12 times (135µs+51µs) by Method::Generate::Accessor::_generate_call_code at line 472, avg 16µs/call
sub _sanitize_name {
4791215µs my ($self, $name) = @_;
48012148µs2651µs $name =~ s/([_\W])/sprintf('_%x', ord($1))/ge;
# spent 34µs making 12 calls to Method::Generate::Accessor::CORE:subst, avg 3µs/call # spent 17µs making 14 calls to Method::Generate::Accessor::CORE:substcont, avg 1µs/call
4811234µs $name;
482}
483
484
# spent 8.82ms (108µs+8.71) within Method::Generate::Accessor::generate_populate_set which was called 15 times, avg 588µs/call: # 15 times (108µs+8.71ms) by Method::Generate::Constructor::_assign_new at line 217 of Method/Generate/Constructor.pm, avg 588µs/call
sub generate_populate_set {
485155µs my $self = shift;
4861521µs $self->{captures} = {};
4871525µs158.71ms my $code = $self->_generate_populate_set(@_);
# spent 8.71ms making 15 calls to Method::Generate::Accessor::_generate_populate_set, avg 581µs/call
4881553µs ($code, delete $self->{captures});
489}
490
491
# spent 8.71ms (279µs+8.43) within Method::Generate::Accessor::_generate_populate_set which was called 15 times, avg 581µs/call: # 15 times (279µs+8.43ms) by Method::Generate::Accessor::generate_populate_set at line 487, avg 581µs/call
sub _generate_populate_set {
4921538µs my ($self, $me, $name, $spec, $source, $test, $init_arg) = @_;
493
4941523µs1538µs my $has_default = $self->has_eager_default($name, $spec);
# spent 38µs making 15 calls to Method::Generate::Accessor::has_eager_default, avg 3µs/call
495154µs if (!($has_default || $test)) {
496 return '';
497 }
498155µs if ($has_default) {
499916µs97.76ms my $get_default = $self->_generate_get_default($me, $name, $spec);
# spent 7.76ms making 9 calls to Method::Generate::Accessor::_generate_get_default, avg 862µs/call
500916µs $source =
501 $test
502 ? "(\n ${test}\n"
503 ." ? ${source}\n : "
504 .$get_default
505 .")"
506 : $get_default;
507 }
508157µs if ($spec->{coerce}) {
509 $source = $self->_generate_coerce(
510 $name, $source,
511 $spec->{coerce}, $init_arg
512 )
513 }
5141522µs3254µs if ($spec->{isa}) {
# spent 254µs making 3 calls to Method::Generate::Accessor::_generate_isa_check, avg 85µs/call
515 $source = 'scalar do { my $value = '.$source.";\n"
516 .' ('.$self->_generate_isa_check(
517 $name, '$value', $spec->{isa}, $init_arg
518 )."),\n"
519 ." \$value\n"
520 ."}\n";
521 }
5221528µs15380µs my $set = $self->_generate_simple_set($me, $name, $spec, $source);
# spent 380µs making 15 calls to Method::Generate::Accessor::_generate_simple_set, avg 25µs/call
523159µs my $trigger = $spec->{trigger} ? $self->_generate_trigger(
524 $name, $me, $self->_generate_simple_get($me, $name, $spec),
525 $spec->{trigger}
526 ) : undef;
5271558µs if ($has_default) {
528 "($set)," . ($trigger ? "($test and $trigger)," : '')
529 }
530 else {
53169µs "($test and ($set)" . ($trigger ? ", ($trigger)" : '') . "),";
532 }
533}
534
535
# spent 166µs (94+71) within Method::Generate::Accessor::_generate_core_set which was called 15 times, avg 11µs/call: # 15 times (94µs+71µs) by Method::Generate::Accessor::_generate_simple_set at line 544, avg 11µs/call
sub _generate_core_set {
5361511µs my ($self, $me, $name, $spec, $value) = @_;
5371518µs1571µs my $name_str = quotify $name;
# spent 71µs making 15 calls to Sub::Quote::quotify, avg 5µs/call
5381571µs "${me}->{${name_str}} = ${value}";
539}
540
541
# spent 380µs (136+244) within Method::Generate::Accessor::_generate_simple_set which was called 15 times, avg 25µs/call: # 15 times (136µs+244µs) by Method::Generate::Accessor::_generate_populate_set at line 522, avg 25µs/call
sub _generate_simple_set {
5421511µs my ($self, $me, $name, $spec, $value) = @_;
5431528µs1578µs my $name_str = quotify $name;
# spent 78µs making 15 calls to Sub::Quote::quotify, avg 5µs/call
5441525µs15166µs my $simple = $self->_generate_core_set($me, $name, $spec, $value);
# spent 166µs making 15 calls to Method::Generate::Accessor::_generate_core_set, avg 11µs/call
545
5461549µs if ($spec->{weak_ref}) {
547 require Scalar::Util;
548 my $get = $self->_generate_simple_get($me, $name, $spec);
549
550 # Perl < 5.8.3 can't weaken refs to readonly vars
551 # (e.g. string constants). This *can* be solved by:
552 #
553 # &Internals::SvREADONLY($foo, 0);
554 # Scalar::Util::weaken($foo);
555 # &Internals::SvREADONLY($foo, 1);
556 #
557 # but requires Internal functions and is just too damn crazy
558 # so simply throw a better exception
559 my $weak_simple = "do { Scalar::Util::weaken(${simple}); no warnings 'void'; $get }";
560 Moo::_Utils::lt_5_8_3() ? <<"EOC" : $weak_simple;
561 eval { Scalar::Util::weaken($simple); 1 }
562 ? do { no warnings 'void'; $get }
563 : do {
564 if( \$@ =~ /Modification of a read-only value attempted/) {
565 require Carp;
566 Carp::croak( sprintf (
567 'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3',
568 $name_str,
569 ) );
570 } else {
571 die \$@;
572 }
573 }
574EOC
575 } else {
576158µs $simple;
577 }
578}
579
580sub _generate_getset {
581 my ($self, $name, $spec) = @_;
582 q{(@_ > 1}."\n ? ".$self->_generate_set($name, $spec)
583 ."\n : ".$self->_generate_get($name, $spec)."\n )";
584}
585
586sub _generate_asserter {
587 my ($self, $name, $spec) = @_;
588
589 "do {\n"
590 ." my \$val = ".$self->_generate_get($name, $spec).";\n"
591 ." unless (".$self->_generate_simple_has('$_[0]', $name, $spec).") {\n"
592 .qq! die "Attempted to access '${name}' but it is not set";\n!
593 ." }\n"
594 ." \$val;\n"
595 ."}\n";
596}
597sub _generate_delegation {
598 my ($self, $asserter, $target, $args) = @_;
599 my $arg_string = do {
600 if (@$args) {
601 # I could, I reckon, linearise out non-refs here using quotify
602 # plus something to check for numbers but I'm unsure if it's worth it
603 $self->{captures}{'@curries'} = $args;
604 '@curries, @_';
605 } else {
606 '@_';
607 }
608 };
609 "shift->${asserter}->${target}(${arg_string});";
610}
611
612
# spent 972µs (91+880) within Method::Generate::Accessor::_generate_xs which was called 9 times, avg 108µs/call: # 5 times (52µs+481µs) by Method::Generate::Accessor::generate_method at line 110, avg 107µs/call # 4 times (39µs+399µs) by Method::Generate::Accessor::generate_method at line 127, avg 110µs/call
sub _generate_xs {
61396µs my ($self, $type, $into, $name, $slot) = @_;
614930µs9860µs Class::XSAccessor->import(
# spent 860µs making 9 calls to Class::XSAccessor::import, avg 96µs/call
615 class => $into,
616 $type => { $name => $slot },
617 replace => 1,
618 );
619967µs921µs $into->can($name);
# spent 21µs making 9 calls to UNIVERSAL::can, avg 2µs/call
620}
621
62227µs
# spent 3µs within Method::Generate::Accessor::default_construction_string which was called 2 times, avg 2µs/call: # 2 times (3µs+0s) by Method::Generate::Constructor::_build_construction_string at line 70 of Method/Generate/Constructor.pm, avg 2µs/call
sub default_construction_string { '{}' }
623
624
# spent 119µs (99+20) within Method::Generate::Accessor::_validate_codulatable which was called 12 times, avg 10µs/call: # 9 times (76µs+15µs) by Method::Generate::Accessor::generate_method at line 89, avg 10µs/call # 3 times (23µs+6µs) by Method::Generate::Accessor::generate_method at line 86, avg 10µs/call
sub _validate_codulatable {
625127µs my ($self, $setting, $value, $into, $appended) = @_;
6261231µs1220µs my $invalid = "Invalid $setting '" . overload::StrVal($value)
# spent 20µs making 12 calls to overload::AddrRef, avg 2µs/call
627 . "' for $into not a coderef";
628125µs $invalid .= " $appended" if $appended;
629
630127µs unless (ref $value and (ref $value eq 'CODE' or blessed($value))) {
631 die "$invalid or code-convertible object";
632 }
633
6342416µs unless (eval { \&$value }) {
635 die "$invalid and could not be converted to a coderef: $@";
636 }
637
6381231µs 1;
639}
640
64116µs1;
 
# spent 2µs within Method::Generate::Accessor::CORE:qr which was called: # once (2µs+0s) by Moo::_accessor_maker_for at line 25
sub Method::Generate::Accessor::CORE:qr; # opcode
# spent 20µs within Method::Generate::Accessor::CORE:regcomp which was called: # once (20µs+0s) by Moo::_accessor_maker_for at line 25
sub Method::Generate::Accessor::CORE:regcomp; # opcode
# spent 37µs within Method::Generate::Accessor::CORE:subst which was called 21 times, avg 2µs/call: # 12 times (34µs+0s) by Method::Generate::Accessor::_sanitize_name at line 480, avg 3µs/call # 9 times (3µs+0s) by Method::Generate::Accessor::generate_method at line 36, avg 311ns/call
sub Method::Generate::Accessor::CORE:subst; # opcode
# spent 17µs within Method::Generate::Accessor::CORE:substcont which was called 14 times, avg 1µs/call: # 14 times (17µs+0s) by Method::Generate::Accessor::_sanitize_name at line 480, avg 1µs/call
sub Method::Generate::Accessor::CORE:substcont; # opcode