← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:07 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Method/Generate/Accessor.pm
StatementsExecuted 4518 statements in 5.53ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
72221.28ms5.81msMethod::Generate::Accessor::::generate_methodMethod::Generate::Accessor::generate_method
7111395µs1.14msMethod::Generate::Accessor::::_generate_populate_setMethod::Generate::Accessor::_generate_populate_set
6341310µs2.67msMethod::Generate::Accessor::::_generate_xsMethod::Generate::Accessor::_generate_xs
8631274µs626µsMethod::Generate::Accessor::::_generate_simple_setMethod::Generate::Accessor::_generate_simple_set
8611151µs249µsMethod::Generate::Accessor::::_generate_core_setMethod::Generate::Accessor::_generate_core_set
7111151µs1.29msMethod::Generate::Accessor::::generate_populate_setMethod::Generate::Accessor::generate_populate_set
152191µs486µsMethod::Generate::Accessor::::_generate_getMethod::Generate::Accessor::_generate_get
422184µs202µsMethod::Generate::Accessor::::_generate_get_defaultMethod::Generate::Accessor::_generate_get_default
873181µs81µsMethod::Generate::Accessor::::is_simple_getMethod::Generate::Accessor::is_simple_get
151181µs261µsMethod::Generate::Accessor::::_generate_use_defaultMethod::Generate::Accessor::_generate_use_default
782261µs61µsMethod::Generate::Accessor::::has_eager_defaultMethod::Generate::Accessor::has_eager_default
302160µs111µsMethod::Generate::Accessor::::_generate_simple_getMethod::Generate::Accessor::_generate_simple_get
81154µs65µsMethod::Generate::Accessor::::_validate_codulatableMethod::Generate::Accessor::_validate_codulatable
51145µs88µsMethod::Generate::Accessor::::_generate_call_codeMethod::Generate::Accessor::_generate_call_code
172137µs59µsMethod::Generate::Accessor::::_generate_simple_hasMethod::Generate::Accessor::_generate_simple_has
181126µs26µsMethod::Generate::Accessor::::_generate_delegationMethod::Generate::Accessor::_generate_delegation
142126µs26µsMethod::Generate::Accessor::::CORE:regcompMethod::Generate::Accessor::CORE:regcomp (opcode)
191125µs25µsMethod::Generate::Accessor::::has_defaultMethod::Generate::Accessor::has_default
51122µs31µsMethod::Generate::Accessor::::_sanitize_nameMethod::Generate::Accessor::_sanitize_name
102122µs22µsMethod::Generate::Accessor::::is_simple_setMethod::Generate::Accessor::is_simple_set
772120µs20µsMethod::Generate::Accessor::::CORE:substMethod::Generate::Accessor::CORE:subst (opcode)
142118µs18µsMethod::Generate::Accessor::::CORE:matchMethod::Generate::Accessor::CORE:match (opcode)
11113µs1.19msMethod::Generate::Accessor::::BEGIN@11Method::Generate::Accessor::BEGIN@11
21111µs75µsMethod::Generate::Accessor::::_generate_asserterMethod::Generate::Accessor::_generate_asserter
11110µs28µsMethod::Generate::Accessor::::BEGIN@3Method::Generate::Accessor::BEGIN@3
10119µs9µsMethod::Generate::Accessor::::default_construction_stringMethod::Generate::Accessor::default_construction_string
1117µs63µsMethod::Generate::Accessor::::BEGIN@4Method::Generate::Accessor::BEGIN@4
1116µs18µsMethod::Generate::Accessor::::BEGIN@10Method::Generate::Accessor::BEGIN@10
1116µs21µsMethod::Generate::Accessor::::BEGIN@8Method::Generate::Accessor::BEGIN@8
1115µs28µsMethod::Generate::Accessor::::BEGIN@7Method::Generate::Accessor::BEGIN@7
1114µs6µsMethod::Generate::Accessor::::_generate_simple_clearMethod::Generate::Accessor::_generate_simple_clear
5113µs3µsMethod::Generate::Accessor::::CORE:substcontMethod::Generate::Accessor::CORE:substcont (opcode)
1112µs2µsMethod::Generate::Accessor::::BEGIN@9Method::Generate::Accessor::BEGIN@9
1112µs2µsMethod::Generate::Accessor::::BEGIN@5Method::Generate::Accessor::BEGIN@5
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::::_attr_descMethod::Generate::Accessor::_attr_desc
0000s0sMethod::Generate::Accessor::::_die_overwriteMethod::Generate::Accessor::_die_overwrite
0000s0sMethod::Generate::Accessor::::_generate_coerceMethod::Generate::Accessor::_generate_coerce
0000s0sMethod::Generate::Accessor::::_generate_getsetMethod::Generate::Accessor::_generate_getset
0000s0sMethod::Generate::Accessor::::_generate_isa_checkMethod::Generate::Accessor::_generate_isa_check
0000s0sMethod::Generate::Accessor::::_generate_setMethod::Generate::Accessor::_generate_set
0000s0sMethod::Generate::Accessor::::_generate_triggerMethod::Generate::Accessor::_generate_trigger
0000s0sMethod::Generate::Accessor::::_wrap_attr_exceptionMethod::Generate::Accessor::_wrap_attr_exception
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
3220µs246µs
# spent 28µs (10+18) within Method::Generate::Accessor::BEGIN@3 which was called: # once (10µs+18µs) by Moo::_accessor_maker_for at line 3
use Moo::_strictures;
# spent 28µs making 1 call to Method::Generate::Accessor::BEGIN@3 # spent 18µs making 1 call to Moo::_strictures::import
4217µs2119µs
# spent 63µs (7+56) within Method::Generate::Accessor::BEGIN@4 which was called: # once (7µs+56µs) by Moo::_accessor_maker_for at line 4
use Moo::_Utils;
# spent 63µs making 1 call to Method::Generate::Accessor::BEGIN@4 # spent 56µs making 1 call to Exporter::import
5226µs12µs
# spent 2µs within Method::Generate::Accessor::BEGIN@5 which was called: # once (2µs+0s) by Moo::_accessor_maker_for at line 5
use Moo::Object ();
# spent 2µs making 1 call to Method::Generate::Accessor::BEGIN@5
615µsour @ISA = qw(Moo::Object);
7218µs250µs
# spent 28µs (5+22) within Method::Generate::Accessor::BEGIN@7 which was called: # once (5µs+22µs) by Moo::_accessor_maker_for at line 7
use Sub::Quote qw(quote_sub quoted_from_sub quotify);
# spent 28µs making 1 call to Method::Generate::Accessor::BEGIN@7 # spent 22µs making 1 call to Exporter::import
8215µs236µs
# spent 21µs (6+15) within Method::Generate::Accessor::BEGIN@8 which was called: # once (6µs+15µs) by Moo::_accessor_maker_for at line 8
use Scalar::Util 'blessed';
# spent 21µs making 1 call to Method::Generate::Accessor::BEGIN@8 # spent 15µs making 1 call to Exporter::import
9215µs12µs
# spent 2µs within Method::Generate::Accessor::BEGIN@9 which was called: # once (2µs+0s) by Moo::_accessor_maker_for at line 9
use overload ();
# spent 2µs making 1 call to Method::Generate::Accessor::BEGIN@9
10251µs231µs
# spent 18µs (6+12) within Method::Generate::Accessor::BEGIN@10 which was called: # once (6µs+12µs) by Moo::_accessor_maker_for at line 10
use Module::Runtime qw(use_module);
# spent 18µs making 1 call to Method::Generate::Accessor::BEGIN@10 # spent 12µs making 1 call to Module::Runtime::import
11
# spent 1.19ms (13µs+1.18) within Method::Generate::Accessor::BEGIN@11 which was called: # once (13µs+1.18ms) 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 &&
17210µs21.18ms (eval { Class::XSAccessor->VERSION('1.07') })
# spent 1.18ms making 1 call to Moo::_Utils::_maybe_load_module # spent 3µs making 1 call to UNIVERSAL::VERSION
18 ;
19 our $CAN_HAZ_XS_PRED =
20 $CAN_HAZ_XS &&
2126µs12µs (eval { Class::XSAccessor->VERSION('1.17') })
# spent 2µs making 1 call to UNIVERSAL::VERSION
22 ;
2312.04ms11.19ms}
# spent 1.19ms making 1 call to Method::Generate::Accessor::BEGIN@11
24
25122µs214µsmy $module_name_only = qr/\A$Module::Runtime::module_name_rx\z/;
# spent 12µ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 5.81ms (1.28+4.53) within Method::Generate::Accessor::generate_method which was called 72 times, avg 81µs/call: # 51 times (926µs+3.24ms) by Moo::Role::has at line 55 of Moo/Role.pm, avg 82µs/call # 21 times (354µs+1.29ms) by Moo::has at line 57 of Moo.pm, avg 79µs/call
sub generate_method {
357222µs my ($self, $into, $name, $spec, $quote_opts) = @_;
367292µs7215µs $spec->{allow_overwrite}++ if $name =~ s/^\+//;
# spent 15µs making 72 calls to Method::Generate::Accessor::CORE:subst, avg 203ns/call
377220µs die "Must have an is" unless my $is = $spec->{is};
387256µ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') {
44136µs $spec->{reader} = $name unless exists $spec->{reader};
45134µs $spec->{lazy} = 1;
461310µs $spec->{builder} ||= '_build_'.$name unless exists $spec->{default};
47 } elsif ($is eq 'rwp') {
4831µs $spec->{reader} = $name unless exists $spec->{reader};
4932µs $spec->{writer} = "_set_${name}" unless exists $spec->{writer};
50 } elsif ($is ne 'bare') {
51 die "Unknown is ${is}";
52 }
537213µs if (exists $spec->{builder}) {
54132µs 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 }
60133µs $spec->{builder} = '_build_'.$name if ($spec->{builder}||0) eq 1;
61 die "Invalid builder for $into->$name - not a valid method name"
621362µs2631µs if $spec->{builder} !~ $module_name_only;
# spent 18µs making 13 calls to Method::Generate::Accessor::CORE:match, avg 1µs/call # spent 13µs making 13 calls to Method::Generate::Accessor::CORE:regcomp, avg 1µs/call
63 }
647230µs if (($spec->{predicate}||0) eq 1) {
65 $spec->{predicate} = $name =~ /^_/ ? "_has${name}" : "has_${name}";
66 }
677216µs if (($spec->{clearer}||0) eq 1) {
6812µs1300ns $spec->{clearer} = $name =~ /^_/ ? "_clear${name}" : "clear_${name}";
# spent 300ns making 1 call to Method::Generate::Accessor::CORE:match
69 }
707229µs if (($spec->{trigger}||0) eq 1) {
71 $spec->{trigger} = quote_sub('shift->_trigger_'.$name.'(@_)');
72 }
737218µ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
847245µs foreach my $setting (qw( isa coerce )) {
8514430µs next if !exists $spec->{$setting};
86 $self->_validate_codulatable($setting, $spec->{$setting}, "$into->$name");
87 }
88
897231µs865µs if (exists $spec->{default}) {
# spent 65µs making 8 calls to Method::Generate::Accessor::_validate_codulatable, avg 8µs/call
90 if (ref $spec->{default}) {
91 $self->_validate_codulatable('default', $spec->{default}, "$into->$name",
92 'or a non-ref');
93 }
94 }
95
96729µ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
1067210µs my %methods;
1077233µs if (my $reader = $spec->{reader}) {
108 _die_overwrite($into, $reader, 'a reader')
10965119µs if !$spec->{allow_overwrite} && defined &{"${into}::${reader}"};
11065130µs1172.34ms if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) {
# spent 2.27ms making 52 calls to Method::Generate::Accessor::_generate_xs, avg 44µs/call # spent 66µs making 65 calls to Method::Generate::Accessor::is_simple_get, avg 1µs/call
111 $methods{$reader} = $self->_generate_xs(
112 getters => $into, $reader, $name, $spec
113 );
114 } else {
115137µs $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}
1211339µs26925µs ;
# spent 498µs making 13 calls to Sub::Quote::quote_sub, avg 38µs/call # spent 428µs making 13 calls to Method::Generate::Accessor::_generate_get, avg 33µs/call
122 }
123 }
1247222µs if (my $accessor = $spec->{accessor}) {
125 _die_overwrite($into, $accessor, 'an accessor')
126714µs if !$spec->{allow_overwrite} && defined &{"${into}::${accessor}"};
127722µs21289µs if (
# spent 268µs making 7 calls to Method::Generate::Accessor::_generate_xs, avg 38µs/call # spent 15µs making 7 calls to Method::Generate::Accessor::is_simple_set, avg 2µs/call # spent 5µs making 7 calls to Method::Generate::Accessor::is_simple_get, avg 743ns/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 }
1447217µs if (my $writer = $spec->{writer}) {
145 _die_overwrite($into, $writer, 'a writer')
14634µs if !$spec->{allow_overwrite} && defined &{"${into}::${writer}"};
14736µs6106µs if (
# spent 99µs making 3 calls to Method::Generate::Accessor::_generate_xs, avg 33µs/call # spent 7µs making 3 calls to Method::Generate::Accessor::is_simple_set, avg 2µs/call
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 }
1637217µs if (my $pred = $spec->{predicate}) {
164 _die_overwrite($into, $pred, 'a predicate')
16512µs if !$spec->{allow_overwrite} && defined &{"${into}::${pred}"};
16611µs134µs if (our $CAN_HAZ_XS && our $CAN_HAZ_XS_PRED) {
# spent 34µs making 1 call to Method::Generate::Accessor::_generate_xs
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 }
1777215µs if (my $pred = $spec->{builder_sub}) {
178 _install_coderef( "${into}::$spec->{builder}" => $spec->{builder_sub} );
179 }
1807213µs if (my $cl = $spec->{clearer}) {
181 _die_overwrite($into, $cl, 'a clearer')
18212µs if !$spec->{allow_overwrite} && defined &{"${into}::${cl}"};
18314µs238µs $methods{$cl} =
# spent 32µs making 1 call to Sub::Quote::quote_sub # spent 6µ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 }
1887216µs if (my $hspec = $spec->{handles}) {
18922µs my $asserter = $spec->{asserter} ||= '_assert_'.$name;
19023µs my @specs = do {
19127µs 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 };
20223µs foreach my $delegation_spec (@specs) {
203187µs my ($proxy, $target, @args) = @$delegation_spec;
204 _die_overwrite($into, $proxy, 'a delegation')
2051837µs if !$spec->{allow_overwrite} && defined &{"${into}::${proxy}"};
206185µs $self->{captures} = {};
207 $methods{$proxy} =
208 quote_sub "${into}::${proxy}" =>
209 $self->_generate_delegation($asserter, $target, \@args),
210 delete $self->{captures}
2111839µs36550µs ;
# spent 524µs making 18 calls to Sub::Quote::quote_sub, avg 29µs/call # spent 26µs making 18 calls to Method::Generate::Accessor::_generate_delegation, avg 1µs/call
212 }
213 }
2147218µs if (my $asserter = $spec->{asserter}) {
21521µs $self->{captures} = {};
216
217
218 $methods{$asserter} =
219 quote_sub "${into}::${asserter}" =>
220 $self->_generate_asserter($name, $spec),
22128µs4142µs delete $self->{captures};
# spent 75µs making 2 calls to Method::Generate::Accessor::_generate_asserter, avg 37µs/call # spent 67µs making 2 calls to Sub::Quote::quote_sub, avg 34µs/call
222 }
22372100µ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 81µs within Method::Generate::Accessor::is_simple_get which was called 87 times, avg 936ns/call: # 65 times (66µs+0s) by Method::Generate::Accessor::generate_method at line 110, avg 1µs/call # 15 times (10µs+0s) by Method::Generate::Accessor::_generate_get at line 257, avg 647ns/call # 7 times (5µs+0s) by Method::Generate::Accessor::generate_method at line 127, avg 743ns/call
sub is_simple_get {
2358722µs my ($self, $name, $spec) = @_;
23687112µs !($spec->{lazy} and (exists $spec->{default} or $spec->{builder}));
237}
238
239
# spent 22µs within Method::Generate::Accessor::is_simple_set which was called 10 times, avg 2µs/call: # 7 times (15µs+0s) by Method::Generate::Accessor::generate_method at line 127, avg 2µs/call # 3 times (7µs+0s) by Method::Generate::Accessor::generate_method at line 147, avg 2µs/call
sub is_simple_set {
240103µs my ($self, $name, $spec) = @_;
2411027µs !grep $spec->{$_}, qw(coerce isa trigger weak_ref);
242}
243
244
# spent 25µs within Method::Generate::Accessor::has_default which was called 19 times, avg 1µs/call: # 19 times (25µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 30 of Method/Generate/Constructor.pm, avg 1µs/call
sub has_default {
245195µs my ($self, $name, $spec) = @_;
2461930µs $spec->{builder} or exists $spec->{default} or (($spec->{is}||'') eq 'lazy');
247}
248
249
# spent 61µs within Method::Generate::Accessor::has_eager_default which was called 78 times, avg 781ns/call: # 71 times (56µs+0s) by Method::Generate::Accessor::_generate_populate_set at line 502, avg 794ns/call # 7 times (4µs+0s) by Method::Generate::Constructor::_assign_new at line 210 of Method/Generate/Constructor.pm, avg 643ns/call
sub has_eager_default {
2507814µs my ($self, $name, $spec) = @_;
25178102µs (!$spec->{lazy} and (exists $spec->{default} or $spec->{builder}));
252}
253
254
# spent 486µs (91+395) within Method::Generate::Accessor::_generate_get which was called 15 times, avg 32µs/call: # 13 times (81µs+347µs) by Method::Generate::Accessor::generate_method at line 121, avg 33µs/call # 2 times (10µs+48µs) by Method::Generate::Accessor::_generate_asserter at line 621, avg 29µs/call
sub _generate_get {
255154µs my ($self, $name, $spec) = @_;
2561514µs1571µs my $simple = $self->_generate_simple_get('$_[0]', $name, $spec);
# spent 71µs making 15 calls to Method::Generate::Accessor::_generate_simple_get, avg 5µs/call
2571525µs1510µs if ($self->is_simple_get($name, $spec)) {
# spent 10µs making 15 calls to Method::Generate::Accessor::is_simple_get, avg 647ns/call
258 $simple;
259 } else {
2601523µs30314µs $self->_generate_use_default(
# spent 261µs making 15 calls to Method::Generate::Accessor::_generate_use_default, avg 17µs/call # spent 53µs making 15 calls to Method::Generate::Accessor::_generate_simple_has, avg 4µs/call
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
274
# spent 59µs (37+23) within Method::Generate::Accessor::_generate_simple_has which was called 17 times, avg 3µs/call: # 15 times (33µs+20µs) by Method::Generate::Accessor::_generate_get at line 260, avg 4µs/call # 2 times (4µs+2µs) by Method::Generate::Accessor::_generate_asserter at line 621, avg 3µs/call
sub _generate_simple_has {
275174µs my ($self, $me, $name) = @_;
2761734µs1722µs "exists ${me}->{${\quotify $name}}";
# spent 22µs making 17 calls to Sub::Quote::quotify, avg 1µs/call
277}
278
279
# spent 6µs (4+2) within Method::Generate::Accessor::_generate_simple_clear which was called: # once (4µs+2µs) by Method::Generate::Accessor::generate_method at line 183
sub _generate_simple_clear {
2801400ns my ($self, $me, $name) = @_;
28117µs12µs " delete ${me}->{${\quotify $name}}\n"
# spent 2µs making 1 call to Sub::Quote::quotify
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
298
# spent 261µs (81+180) within Method::Generate::Accessor::_generate_use_default which was called 15 times, avg 17µs/call: # 15 times (81µs+180µs) by Method::Generate::Accessor::_generate_get at line 260, avg 17µs/call
sub _generate_use_default {
299154µs my ($self, $me, $name, $spec, $test) = @_;
3001513µs1523µs my $get_value = $self->_generate_get_default($me, $name, $spec);
# spent 23µs making 15 calls to Method::Generate::Accessor::_generate_get_default, avg 2µs/call
301153µs 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"
3111542µs30157µs ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n"
# spent 117µs making 15 calls to Method::Generate::Accessor::_generate_simple_set, avg 8µs/call # spent 40µs making 15 calls to Method::Generate::Accessor::_generate_simple_get, avg 3µs/call
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 202µs (84+117) within Method::Generate::Accessor::_generate_get_default which was called 42 times, avg 5µs/call: # 27 times (62µs+117µs) by Method::Generate::Accessor::_generate_populate_set at line 504, avg 7µs/call # 15 times (23µs+0s) by Method::Generate::Accessor::_generate_use_default at line 300, avg 2µs/call
sub _generate_get_default {
3194210µs my ($self, $me, $name, $spec) = @_;
3204271µs27117µs if (exists $spec->{default}) {
# spent 88µs making 5 calls to Method::Generate::Accessor::_generate_call_code, avg 18µs/call # spent 29µs making 22 calls to Sub::Quote::quotify, avg 1µs/call
321 ref $spec->{default}
322 ? $self->_generate_call_code($name, 'default', $me, $spec->{default})
323 : quotify $spec->{default};
324 }
325 else {
326157µs "${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
337
# spent 111µs (60+52) within Method::Generate::Accessor::_generate_simple_get which was called 30 times, avg 4µs/call: # 15 times (38µs+33µs) by Method::Generate::Accessor::_generate_get at line 256, avg 5µs/call # 15 times (22µs+18µs) by Method::Generate::Accessor::_generate_use_default at line 311, avg 3µs/call
sub _generate_simple_get {
338306µs my ($self, $me, $name) = @_;
3393017µs3052µs my $name_str = quotify $name;
# spent 52µs making 30 calls to Sub::Quote::quotify, avg 2µs/call
3403038µs "${me}->{${name_str}}";
341}
342
343sub _generate_set {
344 my ($self, $name, $spec) = @_;
345 if ($self->is_simple_set($name, $spec)) {
346 $self->_generate_simple_set('$_[0]', $name, $spec, '$_[1]');
347 } else {
348 my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)};
349 my $value_store = '$_[0]';
350 my $code;
351 if ($coerce) {
352 $value_store = '$value';
353 $code = "do { my (\$self, \$value) = \@_;\n"
354 ." \$value = "
355 .$self->_generate_coerce($name, $value_store, $coerce).";\n";
356 }
357 else {
358 $code = "do { my \$self = shift;\n";
359 }
360 if ($isa_check) {
361 $code .=
362 " ".$self->_generate_isa_check($name, $value_store, $isa_check).";\n";
363 }
364 my $simple = $self->_generate_simple_set('$self', $name, $spec, $value_store);
365 if ($trigger) {
366 my $fire = $self->_generate_trigger($name, '$self', $value_store, $trigger);
367 $code .=
368 " ".$simple.";\n ".$fire.";\n"
369 ." $value_store;\n";
370 } else {
371 $code .= " ".$simple.";\n";
372 }
373 $code .= " }";
374 $code;
375 }
376}
377
378sub generate_coerce {
379 my $self = shift;
380 $self->{captures} = {};
381 my $code = $self->_generate_coerce(@_);
382 ($code, delete $self->{captures});
383}
384
385sub _attr_desc {
386 my ($name, $init_arg) = @_;
387 return quotify($name) if !defined($init_arg) or $init_arg eq $name;
388 return quotify($name).' (constructor argument: '.quotify($init_arg).')';
389}
390
391sub _generate_coerce {
392 my ($self, $name, $value, $coerce, $init_arg) = @_;
393 $self->_wrap_attr_exception(
394 $name,
395 "coercion",
396 $init_arg,
397 $self->_generate_call_code($name, 'coerce', "${value}", $coerce),
398 1,
399 );
400}
401
402sub generate_trigger {
403 my $self = shift;
404 $self->{captures} = {};
405 my $code = $self->_generate_trigger(@_);
406 ($code, delete $self->{captures});
407}
408
409sub _generate_trigger {
410 my ($self, $name, $obj, $value, $trigger) = @_;
411 $self->_generate_call_code($name, 'trigger', "${obj}, ${value}", $trigger);
412}
413
414sub generate_isa_check {
415 my ($self, @args) = @_;
416 $self->{captures} = {};
417 my $code = $self->_generate_isa_check(@args);
418 ($code, delete $self->{captures});
419}
420
421sub _wrap_attr_exception {
422 my ($self, $name, $step, $arg, $code, $want_return) = @_;
423 my $prefix = quotify("${step} for "._attr_desc($name, $arg).' failed: ');
424 "do {\n"
425 .' local $Method::Generate::Accessor::CurrentAttribute = {'."\n"
426 .' init_arg => '.quotify($arg).",\n"
427 .' name => '.quotify($name).",\n"
428 .' step => '.quotify($step).",\n"
429 ." };\n"
430 .($want_return ? ' my $_return;'."\n" : '')
431 .' my $_error;'."\n"
432 ." {\n"
433 .' my $_old_error = $@;'."\n"
434 ." if (!eval {\n"
435 .' $@ = $_old_error;'."\n"
436 .($want_return ? ' $_return ='."\n" : '')
437 .' '.$code.";\n"
438 ." 1;\n"
439 ." }) {\n"
440 .' $_error = $@;'."\n"
441 .' if (!ref $_error) {'."\n"
442 .' $_error = '.$prefix.'.$_error;'."\n"
443 ." }\n"
444 ." }\n"
445 .' $@ = $_old_error;'."\n"
446 ." }\n"
447 .' die $_error if $_error;'."\n"
448 .($want_return ? ' $_return;'."\n" : '')
449 ."}\n"
450}
451
452sub _generate_isa_check {
453 my ($self, $name, $value, $check, $init_arg) = @_;
454 $self->_wrap_attr_exception(
455 $name,
456 "isa check",
457 $init_arg,
458 $self->_generate_call_code($name, 'isa_check', $value, $check)
459 );
460}
461
462
# spent 88µs (45+43) within Method::Generate::Accessor::_generate_call_code which was called 5 times, avg 18µs/call: # 5 times (45µs+43µs) by Method::Generate::Accessor::_generate_get_default at line 320, avg 18µs/call
sub _generate_call_code {
46352µs my ($self, $name, $type, $values, $sub) = @_;
464512µs52µs $sub = \&{$sub} if blessed($sub); # coderef if blessed
# spent 2µs making 5 calls to Scalar::Util::blessed, avg 380ns/call
465514µs511µs if (my $quoted = quoted_from_sub($sub)) {
# spent 11µs making 5 calls to Sub::Quote::quoted_from_sub, avg 2µs/call
466 my $local = 1;
467 if ($values eq '@_' || $values eq '$_[0]') {
468 $local = 0;
469 $values = '@_';
470 }
471 my $code = $quoted->[1];
472 if (my $captures = $quoted->[2]) {
473 my $cap_name = qq{\$${type}_captures_for_}.$self->_sanitize_name($name);
474 $self->{captures}->{$cap_name} = \$captures;
475 Sub::Quote::inlinify($code, $values,
476 Sub::Quote::capture_unroll($cap_name, $captures, 6), $local);
477 } else {
478 Sub::Quote::inlinify($code, $values, undef, $local);
479 }
480 } else {
48158µs531µs my $cap_name = qq{\$${type}_for_}.$self->_sanitize_name($name);
# spent 31µs making 5 calls to Method::Generate::Accessor::_sanitize_name, avg 6µs/call
48255µs $self->{captures}->{$cap_name} = \$sub;
48353µs "${cap_name}->(${values})";
484 }
485}
486
487
# spent 31µs (22+8) within Method::Generate::Accessor::_sanitize_name which was called 5 times, avg 6µs/call: # 5 times (22µs+8µs) by Method::Generate::Accessor::_generate_call_code at line 481, avg 6µs/call
sub _sanitize_name {
48851µs my ($self, $name) = @_;
489525µs108µs $name =~ s/([_\W])/sprintf('_%x', ord($1))/ge;
# spent 5µs making 5 calls to Method::Generate::Accessor::CORE:subst, avg 1µs/call # spent 3µs making 5 calls to Method::Generate::Accessor::CORE:substcont, avg 660ns/call
49058µs $name;
491}
492
493
# spent 1.29ms (151µs+1.14) within Method::Generate::Accessor::generate_populate_set which was called 71 times, avg 18µs/call: # 71 times (151µs+1.14ms) by Method::Generate::Constructor::_assign_new at line 219 of Method/Generate/Constructor.pm, avg 18µs/call
sub generate_populate_set {
494717µs my $self = shift;
4957119µs $self->{captures} = {};
4967145µs711.14ms my $code = $self->_generate_populate_set(@_);
# spent 1.14ms making 71 calls to Method::Generate::Accessor::_generate_populate_set, avg 16µs/call
4977179µs ($code, delete $self->{captures});
498}
499
500
# spent 1.14ms (395µs+744µs) within Method::Generate::Accessor::_generate_populate_set which was called 71 times, avg 16µs/call: # 71 times (395µs+744µs) by Method::Generate::Accessor::generate_populate_set at line 496, avg 16µs/call
sub _generate_populate_set {
5017125µs my ($self, $me, $name, $spec, $source, $test, $init_arg) = @_;
50271122µs7156µs if ($self->has_eager_default($name, $spec)) {
# spent 56µs making 71 calls to Method::Generate::Accessor::has_eager_default, avg 794ns/call
5032714µs my $get_indent = ' ' x ($spec->{isa} ? 6 : 4);
5042724µs27179µs my $get_default = $self->_generate_get_default(
# spent 179µs making 27 calls to Method::Generate::Accessor::_generate_get_default, avg 7µs/call
505 '$new', $name, $spec
506 );
507 my $get_value =
508 defined($spec->{init_arg})
5092735µs ? "(\n${get_indent} ${test}\n"
510 ."${get_indent} ? ${source}\n${get_indent} : "
511 .$get_default
512 ."\n${get_indent})"
513 : $get_default;
514274µs if ($spec->{coerce}) {
515 $get_value = $self->_generate_coerce(
516 $name, $get_value,
517 $spec->{coerce}, $init_arg
518 )
519 }
520 ($spec->{isa}
521 ? " {\n my \$value = ".$get_value.";\n "
522 .$self->_generate_isa_check(
523 $name, '$value', $spec->{isa}, $init_arg
524 ).";\n"
525 .' '.$self->_generate_simple_set($me, $name, $spec, '$value').";\n"
526 ." }\n"
527 : ' '.$self->_generate_simple_set($me, $name, $spec, $get_value).";\n"
528 )
529 .($spec->{trigger}
530 ? ' '
531 .$self->_generate_trigger(
532 $name, $me, $self->_generate_simple_get($me, $name, $spec),
533 $spec->{trigger}
5342742µs27207µs )." if ${test};\n"
# spent 207µs making 27 calls to Method::Generate::Accessor::_generate_simple_set, avg 8µs/call
535 : ''
536 );
537 } else {
538 " if (${test}) {\n"
539 .($spec->{coerce}
540 ? " $source = "
541 .$self->_generate_coerce(
542 $name, $source,
543 $spec->{coerce}, $init_arg
544 ).";\n"
545 : ""
546 )
547 .($spec->{isa}
548 ? " "
549 .$self->_generate_isa_check(
550 $name, $source, $spec->{isa}, $init_arg
551 ).";\n"
552 : ""
553 )
554 ." ".$self->_generate_simple_set($me, $name, $spec, $source).";\n"
555 .($spec->{trigger}
556 ? " "
557 .$self->_generate_trigger(
558 $name, $me, $self->_generate_simple_get($me, $name, $spec),
559 $spec->{trigger}
5604467µs44302µs ).";\n"
# spent 302µs making 44 calls to Method::Generate::Accessor::_generate_simple_set, avg 7µs/call
561 : ""
562 )
563 ." }\n";
564 }
565}
566
567
# spent 249µs (151+97) within Method::Generate::Accessor::_generate_core_set which was called 86 times, avg 3µs/call: # 86 times (151µs+97µs) by Method::Generate::Accessor::_generate_simple_set at line 576, avg 3µs/call
sub _generate_core_set {
5688615µs my ($self, $me, $name, $spec, $value) = @_;
5698634µs8697µs my $name_str = quotify $name;
# spent 97µs making 86 calls to Sub::Quote::quotify, avg 1µs/call
57086110µs "${me}->{${name_str}} = ${value}";
571}
572
573
# spent 626µs (274+352) within Method::Generate::Accessor::_generate_simple_set which was called 86 times, avg 7µs/call: # 44 times (129µs+173µs) by Method::Generate::Accessor::_generate_populate_set at line 560, avg 7µs/call # 27 times (91µs+116µs) by Method::Generate::Accessor::_generate_populate_set at line 534, avg 8µs/call # 15 times (53µs+64µs) by Method::Generate::Accessor::_generate_use_default at line 311, avg 8µs/call
sub _generate_simple_set {
5748621µs my ($self, $me, $name, $spec, $value) = @_;
5758636µs86103µs my $name_str = quotify $name;
# spent 103µs making 86 calls to Sub::Quote::quotify, avg 1µs/call
5768648µs86249µs my $simple = $self->_generate_core_set($me, $name, $spec, $value);
# spent 249µs making 86 calls to Method::Generate::Accessor::_generate_core_set, avg 3µs/call
577
57886102µs if ($spec->{weak_ref}) {
579 require Scalar::Util;
580 my $get = $self->_generate_simple_get($me, $name, $spec);
581
582 # Perl < 5.8.3 can't weaken refs to readonly vars
583 # (e.g. string constants). This *can* be solved by:
584 #
585 # &Internals::SvREADONLY($foo, 0);
586 # Scalar::Util::weaken($foo);
587 # &Internals::SvREADONLY($foo, 1);
588 #
589 # but requires Internal functions and is just too damn crazy
590 # so simply throw a better exception
591 my $weak_simple = "do { Scalar::Util::weaken(${simple}); no warnings 'void'; $get }";
592 Moo::_Utils::lt_5_8_3() ? <<"EOC" : $weak_simple;
593 eval { Scalar::Util::weaken($simple); 1 }
594 ? do { no warnings 'void'; $get }
595 : do {
596 if( \$@ =~ /Modification of a read-only value attempted/) {
597 require Carp;
598 Carp::croak( sprintf (
599 'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3',
600 $name_str,
601 ) );
602 } else {
603 die \$@;
604 }
605 }
606EOC
607 } else {
6088615µs $simple;
609 }
610}
611
612sub _generate_getset {
613 my ($self, $name, $spec) = @_;
614 q{(@_ > 1}."\n ? ".$self->_generate_set($name, $spec)
615 ."\n : ".$self->_generate_get($name, $spec)."\n )";
616}
617
618
# spent 75µs (11+64) within Method::Generate::Accessor::_generate_asserter which was called 2 times, avg 37µs/call: # 2 times (11µs+64µs) by Method::Generate::Accessor::generate_method at line 221, avg 37µs/call
sub _generate_asserter {
61921µs my ($self, $name, $spec) = @_;
620
62128µs464µs "do {\n"
# spent 58µs making 2 calls to Method::Generate::Accessor::_generate_get, avg 29µs/call # spent 6µs making 2 calls to Method::Generate::Accessor::_generate_simple_has, avg 3µs/call
622 ." my \$val = ".$self->_generate_get($name, $spec).";\n"
623 ." unless (".$self->_generate_simple_has('$_[0]', $name, $spec).") {\n"
624 .qq! die "Attempted to access '${name}' but it is not set";\n!
625 ." }\n"
626 ." \$val;\n"
627 ."}\n";
628}
629
# spent 26µs within Method::Generate::Accessor::_generate_delegation which was called 18 times, avg 1µs/call: # 18 times (26µs+0s) by Method::Generate::Accessor::generate_method at line 211, avg 1µs/call
sub _generate_delegation {
630184µs my ($self, $asserter, $target, $args) = @_;
631183µs my $arg_string = do {
632184µs if (@$args) {
633 # I could, I reckon, linearise out non-refs here using quotify
634 # plus something to check for numbers but I'm unsure if it's worth it
635 $self->{captures}{'@curries'} = $args;
636 '@curries, @_';
637 } else {
638183µs '@_';
639 }
640 };
6411824µs "shift->${asserter}->${target}(${arg_string});";
642}
643
644
# spent 2.67ms (310µs+2.36) within Method::Generate::Accessor::_generate_xs which was called 63 times, avg 42µs/call: # 52 times (271µs+2.00ms) by Method::Generate::Accessor::generate_method at line 110, avg 44µs/call # 7 times (26µs+243µs) by Method::Generate::Accessor::generate_method at line 127, avg 38µs/call # 3 times (10µs+89µs) by Method::Generate::Accessor::generate_method at line 147, avg 33µs/call # once (3µs+31µs) by Method::Generate::Accessor::generate_method at line 166
sub _generate_xs {
6456320µs my ($self, $type, $into, $name, $slot) = @_;
64663128µs632.31ms Class::XSAccessor->import(
# spent 2.31ms making 63 calls to Class::XSAccessor::import, avg 37µs/call
647 class => $into,
648 $type => { $name => $slot },
649 replace => 1,
650 );
65163217µs6348µs $into->can($name);
# spent 48µs making 63 calls to UNIVERSAL::can, avg 768ns/call
652}
653
6541014µs
# spent 9µs within Method::Generate::Accessor::default_construction_string which was called 10 times, avg 860ns/call: # 10 times (9µs+0s) by Method::Generate::Constructor::_build_construction_string at line 69 of Method/Generate/Constructor.pm, avg 860ns/call
sub default_construction_string { '{}' }
655
656
# spent 65µs (54+11) within Method::Generate::Accessor::_validate_codulatable which was called 8 times, avg 8µs/call: # 8 times (54µs+11µs) by Method::Generate::Accessor::generate_method at line 89, avg 8µs/call
sub _validate_codulatable {
65783µs my ($self, $setting, $value, $into, $appended) = @_;
658821µs811µs my $invalid = "Invalid $setting '" . overload::StrVal($value)
# spent 11µs making 8 calls to overload::AddrRef, avg 1µs/call
659 . "' for $into not a coderef";
66084µs $invalid .= " $appended" if $appended;
661
66284µs unless (ref $value and (ref $value eq 'CODE' or blessed($value))) {
663 die "$invalid or code-convertible object";
664 }
665
666166µs unless (eval { \&$value }) {
667 die "$invalid and could not be converted to a coderef: $@";
668 }
669
670810µs 1;
671}
672
67313µs1;
 
# spent 18µs within Method::Generate::Accessor::CORE:match which was called 14 times, avg 1µs/call: # 13 times (18µs+0s) by Method::Generate::Accessor::generate_method at line 62, avg 1µs/call # once (300ns+0s) by Method::Generate::Accessor::generate_method at line 68
sub Method::Generate::Accessor::CORE:match; # opcode
# 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 26µs within Method::Generate::Accessor::CORE:regcomp which was called 14 times, avg 2µs/call: # 13 times (13µs+0s) by Method::Generate::Accessor::generate_method at line 62, avg 1µs/call # once (12µs+0s) by Moo::_accessor_maker_for at line 25
sub Method::Generate::Accessor::CORE:regcomp; # opcode
# spent 20µs within Method::Generate::Accessor::CORE:subst which was called 77 times, avg 257ns/call: # 72 times (15µs+0s) by Method::Generate::Accessor::generate_method at line 36, avg 203ns/call # 5 times (5µs+0s) by Method::Generate::Accessor::_sanitize_name at line 489, avg 1µs/call
sub Method::Generate::Accessor::CORE:subst; # opcode
# spent 3µs within Method::Generate::Accessor::CORE:substcont which was called 5 times, avg 660ns/call: # 5 times (3µs+0s) by Method::Generate::Accessor::_sanitize_name at line 489, avg 660ns/call
sub Method::Generate::Accessor::CORE:substcont; # opcode