← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:09 2016

Filename/usr/share/perl5/Method/Generate/Accessor.pm
StatementsExecuted 4578 statements in 15.7ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
30215.24ms5.27msMethod::Generate::Accessor::::_generate_simple_getMethod::Generate::Accessor::_generate_simple_get
74222.05ms20.5msMethod::Generate::Accessor::::generate_methodMethod::Generate::Accessor::generate_method
7611679µs1.97msMethod::Generate::Accessor::::_generate_populate_setMethod::Generate::Accessor::_generate_populate_set
9131568µs1.03msMethod::Generate::Accessor::::_generate_simple_setMethod::Generate::Accessor::_generate_simple_set
6441561µs10.0msMethod::Generate::Accessor::::_generate_xsMethod::Generate::Accessor::_generate_xs
7611353µs2.32msMethod::Generate::Accessor::::generate_populate_setMethod::Generate::Accessor::generate_populate_set
9111327µs393µsMethod::Generate::Accessor::::_generate_core_setMethod::Generate::Accessor::_generate_core_set
8931175µs175µsMethod::Generate::Accessor::::is_simple_getMethod::Generate::Accessor::is_simple_get
1521162µs5.89msMethod::Generate::Accessor::::_generate_getMethod::Generate::Accessor::_generate_get
4721158µs356µsMethod::Generate::Accessor::::_generate_get_defaultMethod::Generate::Accessor::_generate_get_default
1511147µs416µsMethod::Generate::Accessor::::_generate_use_defaultMethod::Generate::Accessor::_generate_use_default
8222120µs120µsMethod::Generate::Accessor::::has_eager_defaultMethod::Generate::Accessor::has_eager_default
61172µs174µsMethod::Generate::Accessor::::_generate_call_codeMethod::Generate::Accessor::_generate_call_code
172167µs80µsMethod::Generate::Accessor::::_generate_simple_hasMethod::Generate::Accessor::_generate_simple_has
61158µs86µsMethod::Generate::Accessor::::_sanitize_nameMethod::Generate::Accessor::_sanitize_name
802157µs57µsMethod::Generate::Accessor::::CORE:substMethod::Generate::Accessor::CORE:subst (opcode)
181153µs53µsMethod::Generate::Accessor::::_generate_delegationMethod::Generate::Accessor::_generate_delegation
61151µs65µsMethod::Generate::Accessor::::_validate_codulatableMethod::Generate::Accessor::_validate_codulatable
142139µs39µsMethod::Generate::Accessor::::CORE:matchMethod::Generate::Accessor::CORE:match (opcode)
142139µs39µsMethod::Generate::Accessor::::is_simple_setMethod::Generate::Accessor::is_simple_set
11123µs1.98msMethod::Generate::Accessor::::BEGIN@11Method::Generate::Accessor::BEGIN@11
11118µs70µsMethod::Generate::Accessor::::BEGIN@3Method::Generate::Accessor::BEGIN@3
21117µs120µsMethod::Generate::Accessor::::_generate_asserterMethod::Generate::Accessor::_generate_asserter
11112µs89µsMethod::Generate::Accessor::::BEGIN@4Method::Generate::Accessor::BEGIN@4
101111µs11µsMethod::Generate::Accessor::::CORE:substcontMethod::Generate::Accessor::CORE:substcont (opcode)
101110µs10µsMethod::Generate::Accessor::::default_construction_stringMethod::Generate::Accessor::default_construction_string
11110µs32µsMethod::Generate::Accessor::::BEGIN@10Method::Generate::Accessor::BEGIN@10
1119µs45µsMethod::Generate::Accessor::::BEGIN@6Method::Generate::Accessor::BEGIN@6
1119µs77µsMethod::Generate::Accessor::::BEGIN@5Method::Generate::Accessor::BEGIN@5
1118µs35µsMethod::Generate::Accessor::::BEGIN@8Method::Generate::Accessor::BEGIN@8
1118µs31µsMethod::Generate::Accessor::::BEGIN@7Method::Generate::Accessor::BEGIN@7
1116µs7µsMethod::Generate::Accessor::::_generate_simple_clearMethod::Generate::Accessor::_generate_simple_clear
1115µs5µsMethod::Generate::Accessor::::BEGIN@9Method::Generate::Accessor::BEGIN@9
0000s0sMethod::Generate::Accessor::::_SIGDIEMethod::Generate::Accessor::_SIGDIE
0000s0sMethod::Generate::Accessor::::__ANON__[:30]Method::Generate::Accessor::__ANON__[:30]
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_die_prefixMethod::Generate::Accessor::_generate_die_prefix
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::::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
3339µs3122µs
# spent 70µs (18+52) within Method::Generate::Accessor::BEGIN@3 which was called: # once (18µs+52µs) by Moo::_accessor_maker_for at line 3
use strictures 1;
# spent 70µs making 1 call to Method::Generate::Accessor::BEGIN@3 # spent 36µs making 1 call to strictures::import # spent 16µs making 1 call to strictures::VERSION
4234µs2165µs
# spent 89µs (12+77) within Method::Generate::Accessor::BEGIN@4 which was called: # once (12µs+77µs) by Moo::_accessor_maker_for at line 4
use Moo::_Utils;
# spent 89µs making 1 call to Method::Generate::Accessor::BEGIN@4 # spent 77µs making 1 call to Exporter::import
5233µs2145µs
# spent 77µs (9+68) within Method::Generate::Accessor::BEGIN@5 which was called: # once (9µs+68µs) by Moo::_accessor_maker_for at line 5
use base qw(Moo::Object);
# spent 77µs making 1 call to Method::Generate::Accessor::BEGIN@5 # spent 68µs making 1 call to base::import
6231µs280µs
# spent 45µs (9+36) within Method::Generate::Accessor::BEGIN@6 which was called: # once (9µs+36µs) by Moo::_accessor_maker_for at line 6
use Sub::Quote;
# spent 45µs making 1 call to Method::Generate::Accessor::BEGIN@6 # spent 36µs making 1 call to Exporter::import
7236µs255µs
# spent 31µs (8+23) within Method::Generate::Accessor::BEGIN@7 which was called: # once (8µs+23µs) by Moo::_accessor_maker_for at line 7
use B 'perlstring';
# spent 31µs making 1 call to Method::Generate::Accessor::BEGIN@7 # spent 23µs making 1 call to Exporter::import
8230µs262µs
# spent 35µs (8+27) within Method::Generate::Accessor::BEGIN@8 which was called: # once (8µs+27µs) by Moo::_accessor_maker_for at line 8
use Scalar::Util 'blessed';
# spent 35µs making 1 call to Method::Generate::Accessor::BEGIN@8 # spent 27µs making 1 call to Exporter::import
9228µs15µs
# spent 5µs within Method::Generate::Accessor::BEGIN@9 which was called: # once (5µs+0s) by Moo::_accessor_maker_for at line 9
use overload ();
# spent 5µs making 1 call to Method::Generate::Accessor::BEGIN@9
102102µs254µs
# spent 32µs (10+22) within Method::Generate::Accessor::BEGIN@10 which was called: # once (10µs+22µ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 22µs making 1 call to Module::Runtime::import
11
# spent 1.98ms (23µs+1.95) within Method::Generate::Accessor::BEGIN@11 which was called: # once (23µs+1.95ms) 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µs21.95ms (eval { Class::XSAccessor->VERSION('1.07') })
# spent 1.94ms making 1 call to Moo::_Utils::_maybe_load_module # spent 6µs making 1 call to UNIVERSAL::VERSION
18 ;
19 our $CAN_HAZ_XS_PRED =
20 $CAN_HAZ_XS &&
21211µs14µs (eval { Class::XSAccessor->VERSION('1.17') })
# spent 4µs making 1 call to UNIVERSAL::VERSION
22 ;
2314.09ms11.98ms}
# spent 1.98ms making 1 call to Method::Generate::Accessor::BEGIN@11
24
25sub _SIGDIE
26{
27 our ($CurrentAttribute, $OrigSigDie);
28 my $sigdie = $OrigSigDie && $OrigSigDie != \&_SIGDIE
29 ? $OrigSigDie
30 : sub { die $_[0] };
31
32 return $sigdie->(@_) if ref($_[0]);
33
34 my $attr_desc = _attr_desc(@$CurrentAttribute{qw(name init_arg)});
35 $sigdie->("$CurrentAttribute->{step} for $attr_desc failed: $_[0]");
36}
37
38sub _die_overwrite
39{
40 my ($pkg, $method, $type) = @_;
41 die "You cannot overwrite a locally defined method ($method) with @{[ $type || 'an accessor' ]}";
42}
43
44
# spent 20.5ms (2.05+18.4) within Method::Generate::Accessor::generate_method which was called 74 times, avg 277µs/call: # 69 times (1.92ms+12.9ms) by Moo::Role::has at line 47 of Moo/Role.pm, avg 215µs/call # 5 times (129µs+5.55ms) by Moo::has at line 56 of Moo.pm, avg 1.14ms/call
sub generate_method {
457436µs my ($self, $into, $name, $spec, $quote_opts) = @_;
4674193µs7441µs $spec->{allow_overwrite}++ if $name =~ s/^\+//;
# spent 41µs making 74 calls to Method::Generate::Accessor::CORE:subst, avg 549ns/call
477434µs die "Must have an is" unless my $is = $spec->{is};
487478µs if ($is eq 'ro') {
49 $spec->{reader} = $name unless exists $spec->{reader};
50 } elsif ($is eq 'rw') {
51 $spec->{accessor} = $name unless exists $spec->{accessor}
52 or ( $spec->{reader} and $spec->{writer} );
53 } elsif ($is eq 'lazy') {
541311µs $spec->{reader} = $name unless exists $spec->{reader};
55136µs $spec->{lazy} = 1;
561315µs $spec->{builder} ||= '_build_'.$name unless $spec->{default};
57 } elsif ($is eq 'rwp') {
5822µs $spec->{reader} = $name unless exists $spec->{reader};
5922µs $spec->{writer} = "_set_${name}" unless exists $spec->{writer};
60 } elsif ($is ne 'bare') {
61 die "Unknown is ${is}";
62 }
637422µs if (exists $spec->{builder}) {
64134µs if(ref $spec->{builder}) {
65 $self->_validate_codulatable('builder', $spec->{builder},
66 "$into->$name", 'or a method name');
67 $spec->{builder_sub} = $spec->{builder};
68 $spec->{builder} = 1;
69 }
70135µs $spec->{builder} = '_build_'.$name if ($spec->{builder}||0) eq 1;
711372µs1339µs die "Invalid builder for $into->$name - not a valid method name"
# spent 39µs making 13 calls to Method::Generate::Accessor::CORE:match, avg 3µs/call
72 if $spec->{builder} !~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/;
73 }
747429µs if (($spec->{predicate}||0) eq 1) {
75 $spec->{predicate} = $name =~ /^_/ ? "_has${name}" : "has_${name}";
76 }
777421µs if (($spec->{clearer}||0) eq 1) {
7814µs1300ns $spec->{clearer} = $name =~ /^_/ ? "_clear${name}" : "clear_${name}";
# spent 300ns making 1 call to Method::Generate::Accessor::CORE:match
79 }
807417µs if (($spec->{trigger}||0) eq 1) {
81 $spec->{trigger} = quote_sub('shift->_trigger_'.$name.'(@_)');
82 }
83
847494µs for my $setting (qw( isa coerce )) {
8514846µs next if !exists $spec->{$setting};
86 $self->_validate_codulatable($setting, $spec->{$setting}, "$into->$name");
87 }
88
897450µs665µs if (exists $spec->{default}) {
# spent 65µs making 6 calls to Method::Generate::Accessor::_validate_codulatable, avg 11µs/call
90 if (!defined $spec->{default} || ref $spec->{default}) {
91 $self->_validate_codulatable('default', $spec->{default}, "$into->$name", 'or a non-ref');
92 }
93 }
94
957417µs if (exists $spec->{moosify}) {
96 if (ref $spec->{moosify} ne 'ARRAY') {
97 $spec->{moosify} = [$spec->{moosify}];
98 }
99
100 for my $spec (@{$spec->{moosify}}) {
101 $self->_validate_codulatable('moosify', $spec, "$into->$name");
102 }
103 }
104
105749µs my %methods;
1067454µs if (my $reader = $spec->{reader}) {
107 _die_overwrite($into, $reader, 'a reader')
10862117µs62208µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${reader}")}{CODE};
# spent 208µs making 62 calls to Moo::_Utils::_getglob, avg 3µs/call
10962197µs1119.01ms if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) {
# spent 8.88ms making 49 calls to Method::Generate::Accessor::_generate_xs, avg 181µs/call # spent 128µs making 62 calls to Method::Generate::Accessor::is_simple_get, avg 2µs/call
110 $methods{$reader} = $self->_generate_xs(
111 getters => $into, $reader, $name, $spec
112 );
113 } else {
1141311µs $self->{captures} = {};
1151359µs266.53ms $methods{$reader} =
# spent 5.79ms making 13 calls to Method::Generate::Accessor::_generate_get, avg 445µs/call # spent 743µs making 13 calls to Sub::Quote::quote_sub, avg 57µs/call
116 quote_sub "${into}::${reader}"
117 => ' die "'.$reader.' is a read-only accessor" if @_ > 1;'."\n"
118 .$self->_generate_get($name, $spec)
119 => delete $self->{captures}
120 ;
121 }
122 }
1237435µs if (my $accessor = $spec->{accessor}) {
124 _die_overwrite($into, $accessor, 'an accessor')
1251223µs1238µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${accessor}")}{CODE};
# spent 38µs making 12 calls to Moo::_Utils::_getglob, avg 3µs/call
1261254µs36963µs if (
# spent 909µs making 12 calls to Method::Generate::Accessor::_generate_xs, avg 76µs/call # spent 33µs making 12 calls to Method::Generate::Accessor::is_simple_set, avg 3µs/call # spent 22µs making 12 calls to Method::Generate::Accessor::is_simple_get, avg 2µs/call
127 our $CAN_HAZ_XS
128 && $self->is_simple_get($name, $spec)
129 && $self->is_simple_set($name, $spec)
130 ) {
131 $methods{$accessor} = $self->_generate_xs(
132 accessors => $into, $accessor, $name, $spec
133 );
134 } else {
135 $self->{captures} = {};
136 $methods{$accessor} =
137 quote_sub "${into}::${accessor}"
138 => $self->_generate_getset($name, $spec)
139 => delete $self->{captures}
140 ;
141 }
142 }
1437423µs if (my $writer = $spec->{writer}) {
144 _die_overwrite($into, $writer, 'a writer')
14524µs25µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${writer}")}{CODE};
# spent 5µs making 2 calls to Moo::_Utils::_getglob, avg 3µs/call
14627µs4162µs if (
# spent 155µs making 2 calls to Method::Generate::Accessor::_generate_xs, avg 78µs/call # spent 6µs making 2 calls to Method::Generate::Accessor::is_simple_set, avg 3µs/call
147 our $CAN_HAZ_XS
148 && $self->is_simple_set($name, $spec)
149 ) {
150 $methods{$writer} = $self->_generate_xs(
151 setters => $into, $writer, $name, $spec
152 );
153 } else {
154 $self->{captures} = {};
155 $methods{$writer} =
156 quote_sub "${into}::${writer}"
157 => $self->_generate_set($name, $spec)
158 => delete $self->{captures}
159 ;
160 }
161 }
1627419µs if (my $pred = $spec->{predicate}) {
163 _die_overwrite($into, $pred, 'a predicate')
16413µs13µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${pred}")}{CODE};
# spent 3µs making 1 call to Moo::_Utils::_getglob
16512µs184µs if (our $CAN_HAZ_XS && our $CAN_HAZ_XS_PRED) {
# spent 84µs making 1 call to Method::Generate::Accessor::_generate_xs
166 $methods{$pred} = $self->_generate_xs(
167 exists_predicates => $into, $pred, $name, $spec
168 );
169 } else {
170 $methods{$pred} =
171 quote_sub "${into}::${pred}" =>
172 ' '.$self->_generate_simple_has('$_[0]', $name, $spec)."\n"
173 ;
174 }
175 }
1767419µs if (my $pred = $spec->{builder_sub}) {
177 _install_coderef( "${into}::$spec->{builder}" => $spec->{builder_sub} );
178 }
1797419µs if (my $cl = $spec->{clearer}) {
180 _die_overwrite($into, $cl, 'a clearer')
18112µs12µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${cl}")}{CODE};
# spent 2µs making 1 call to Moo::_Utils::_getglob
18214µs253µs $methods{$cl} =
# spent 46µs making 1 call to Sub::Quote::quote_sub # spent 7µs making 1 call to Method::Generate::Accessor::_generate_simple_clear
183 quote_sub "${into}::${cl}" =>
184 $self->_generate_simple_clear('$_[0]', $name, $spec)."\n"
185 ;
186 }
1877420µs if (my $hspec = $spec->{handles}) {
18823µs my $asserter = $spec->{asserter} ||= '_assert_'.$name;
18923µs my @specs = do {
190215µs if (ref($hspec) eq 'ARRAY') {
191 map [ $_ => $_ ], @$hspec;
192 } elsif (ref($hspec) eq 'HASH') {
193 map [ $_ => ref($hspec->{$_}) ? @{$hspec->{$_}} : $hspec->{$_} ],
194 keys %$hspec;
195 } elsif (!ref($hspec)) {
196 map [ $_ => $_ ], use_module('Moo::Role')->methods_provided_by(use_module($hspec))
197 } else {
198 die "You gave me a handles of ${hspec} and I have no idea why";
199 }
200 };
20125µs foreach my $delegation_spec (@specs) {
2021813µs my ($proxy, $target, @args) = @$delegation_spec;
203 _die_overwrite($into, $proxy, 'a delegation')
2041835µs1854µs if !$spec->{allow_overwrite} && *{_getglob("${into}::${proxy}")}{CODE};
# spent 54µs making 18 calls to Moo::_Utils::_getglob, avg 3µs/call
2051813µs $self->{captures} = {};
2061880µs36948µs $methods{$proxy} =
# spent 895µs making 18 calls to Sub::Quote::quote_sub, avg 50µs/call # spent 53µs making 18 calls to Method::Generate::Accessor::_generate_delegation, avg 3µs/call
207 quote_sub "${into}::${proxy}" =>
208 $self->_generate_delegation($asserter, $target, \@args),
209 delete $self->{captures}
210 ;
211 }
212 }
2137420µs if (my $asserter = $spec->{asserter}) {
21421µs $self->{captures} = {};
215
216
21728µs4232µs $methods{$asserter} =
# spent 120µs making 2 calls to Method::Generate::Accessor::_generate_asserter, avg 60µs/call # spent 112µs making 2 calls to Sub::Quote::quote_sub, avg 56µs/call
218 quote_sub "${into}::${asserter}" => $self->_generate_asserter($name, $spec),
219 delete $self->{captures}
220 ;
221 }
22274187µs \%methods;
223}
224
225sub is_simple_attribute {
226 my ($self, $name, $spec) = @_;
227 # clearer doesn't have to be listed because it doesn't
228 # affect whether defined/exists makes a difference
229 !grep $spec->{$_},
230 qw(lazy default builder coerce isa trigger predicate weak_ref);
231}
232
233
# spent 175µs within Method::Generate::Accessor::is_simple_get which was called 89 times, avg 2µs/call: # 62 times (128µs+0s) by Method::Generate::Accessor::generate_method at line 109, avg 2µs/call # 15 times (25µs+0s) by Method::Generate::Accessor::_generate_get at line 251, avg 2µs/call # 12 times (22µs+0s) by Method::Generate::Accessor::generate_method at line 126, avg 2µs/call
sub is_simple_get {
2348947µs my ($self, $name, $spec) = @_;
23589236µs !($spec->{lazy} and ($spec->{default} or $spec->{builder}));
236}
237
238
# spent 39µs within Method::Generate::Accessor::is_simple_set which was called 14 times, avg 3µs/call: # 12 times (33µs+0s) by Method::Generate::Accessor::generate_method at line 126, avg 3µs/call # 2 times (6µs+0s) by Method::Generate::Accessor::generate_method at line 146, avg 3µs/call
sub is_simple_set {
239145µs my ($self, $name, $spec) = @_;
2401452µs !grep $spec->{$_}, qw(coerce isa trigger weak_ref);
241}
242
243
# spent 120µs within Method::Generate::Accessor::has_eager_default which was called 82 times, avg 1µs/call: # 76 times (112µs+0s) by Method::Generate::Accessor::_generate_populate_set at line 476, avg 1µs/call # 6 times (8µs+0s) by Method::Generate::Constructor::_assign_new at line 167 of Method/Generate/Constructor.pm, avg 1µs/call
sub has_eager_default {
2448221µs my ($self, $name, $spec) = @_;
24582218µs (!$spec->{lazy} and (exists $spec->{default} or $spec->{builder}));
246}
247
248
# spent 5.89ms (162µs+5.72) within Method::Generate::Accessor::_generate_get which was called 15 times, avg 392µs/call: # 13 times (142µs+5.65ms) by Method::Generate::Accessor::generate_method at line 115, avg 445µs/call # 2 times (20µs+75µs) by Method::Generate::Accessor::_generate_asserter at line 594, avg 47µs/call
sub _generate_get {
249155µs my ($self, $name, $spec) = @_;
2501518µs155.21ms my $simple = $self->_generate_simple_get('$_[0]', $name, $spec);
# spent 5.21ms making 15 calls to Method::Generate::Accessor::_generate_simple_get, avg 347µs/call
2511548µs1525µs if ($self->is_simple_get($name, $spec)) {
# spent 25µs making 15 calls to Method::Generate::Accessor::is_simple_get, avg 2µs/call
252 $simple;
253 } else {
2541535µs30488µs $self->_generate_use_default(
# spent 416µs making 15 calls to Method::Generate::Accessor::_generate_use_default, avg 28µs/call # spent 72µs making 15 calls to Method::Generate::Accessor::_generate_simple_has, avg 5µs/call
255 '$_[0]', $name, $spec,
256 $self->_generate_simple_has('$_[0]', $name, $spec),
257 );
258 }
259}
260
261sub generate_simple_has {
262 my $self = shift;
263 $self->{captures} = {};
264 my $code = $self->_generate_simple_has(@_);
265 ($code, delete $self->{captures});
266}
267
268
# spent 80µs (67+13) within Method::Generate::Accessor::_generate_simple_has which was called 17 times, avg 5µs/call: # 15 times (60µs+11µs) by Method::Generate::Accessor::_generate_get at line 254, avg 5µs/call # 2 times (7µs+1µs) by Method::Generate::Accessor::_generate_asserter at line 594, avg 4µs/call
sub _generate_simple_has {
269176µs my ($self, $me, $name) = @_;
2701793µs1713µs "exists ${me}->{${\perlstring $name}}";
# spent 13µs making 17 calls to B::perlstring, avg 753ns/call
271}
272
273
# spent 7µs (6+800ns) within Method::Generate::Accessor::_generate_simple_clear which was called: # once (6µs+800ns) by Method::Generate::Accessor::generate_method at line 182
sub _generate_simple_clear {
2741700ns my ($self, $me, $name) = @_;
27518µs1800ns " delete ${me}->{${\perlstring $name}}\n"
# spent 800ns making 1 call to B::perlstring
276}
277
278sub generate_get_default {
279 my $self = shift;
280 $self->{captures} = {};
281 my $code = $self->_generate_get_default(@_);
282 ($code, delete $self->{captures});
283}
284
285sub generate_use_default {
286 my $self = shift;
287 $self->{captures} = {};
288 my $code = $self->_generate_use_default(@_);
289 ($code, delete $self->{captures});
290}
291
292
# spent 416µs (147+270) within Method::Generate::Accessor::_generate_use_default which was called 15 times, avg 28µs/call: # 15 times (147µs+270µs) by Method::Generate::Accessor::_generate_get at line 254, avg 28µs/call
sub _generate_use_default {
293157µs my ($self, $me, $name, $spec, $test) = @_;
2941519µs1537µs my $get_value = $self->_generate_get_default($me, $name, $spec);
# spent 37µs making 15 calls to Method::Generate::Accessor::_generate_get_default, avg 2µs/call
295154µs if ($spec->{coerce}) {
296 $get_value = $self->_generate_coerce(
297 $name, $get_value,
298 $spec->{coerce}
299 )
300 }
3011579µs30232µs $test." ? \n"
# spent 171µs making 15 calls to Method::Generate::Accessor::_generate_simple_set, avg 11µs/call # spent 61µs making 15 calls to Method::Generate::Accessor::_generate_simple_get, avg 4µs/call
302 .$self->_generate_simple_get($me, $name, $spec)."\n:"
303 .($spec->{isa}
304 ? " do {\n my \$value = ".$get_value.";\n"
305 ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n"
306 ." ".$self->_generate_simple_set($me, $name, $spec, '$value')."\n"
307 ." }\n"
308 : ' ('.$self->_generate_simple_set($me, $name, $spec, $get_value).")\n");
309}
310
311
# spent 356µs (158+197) within Method::Generate::Accessor::_generate_get_default which was called 47 times, avg 8µs/call: # 32 times (121µs+197µs) by Method::Generate::Accessor::_generate_populate_set at line 478, avg 10µs/call # 15 times (37µs+0s) by Method::Generate::Accessor::_generate_use_default at line 294, avg 2µs/call
sub _generate_get_default {
3124717µs my ($self, $me, $name, $spec) = @_;
31347199µs32197µs if (exists $spec->{default}) {
# spent 174µs making 6 calls to Method::Generate::Accessor::_generate_call_code, avg 29µs/call # spent 23µs making 26 calls to B::perlstring, avg 885ns/call
314 ref $spec->{default}
315 ? $self->_generate_call_code($name, 'default', $me, $spec->{default})
316 : perlstring $spec->{default};
317 }
318 else {
3191512µs "${me}->${\$spec->{builder}}"
320 }
321}
322
323sub generate_simple_get {
324 my ($self, @args) = @_;
325 $self->_generate_simple_get(@args);
326}
327
328
# spent 5.27ms (5.24+29µs) within Method::Generate::Accessor::_generate_simple_get which was called 30 times, avg 176µs/call: # 15 times (5.19ms+19µs) by Method::Generate::Accessor::_generate_get at line 250, avg 347µs/call # 15 times (51µs+10µs) by Method::Generate::Accessor::_generate_use_default at line 301, avg 4µs/call
sub _generate_simple_get {
3293010µs my ($self, $me, $name) = @_;
330305.22ms3029µs my $name_str = perlstring $name;
# spent 29µs making 30 calls to B::perlstring, avg 980ns/call
3313078µs "${me}->{${name_str}}";
332}
333
334sub _generate_set {
335 my ($self, $name, $spec) = @_;
336 if ($self->is_simple_set($name, $spec)) {
337 $self->_generate_simple_set('$_[0]', $name, $spec, '$_[1]');
338 } else {
339 my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)};
340 my $value_store = '$_[0]';
341 my $code;
342 if ($coerce) {
343 $value_store = '$value';
344 $code = "do { my (\$self, \$value) = \@_;\n"
345 ." \$value = "
346 .$self->_generate_coerce($name, $value_store, $coerce).";\n";
347 }
348 else {
349 $code = "do { my \$self = shift;\n";
350 }
351 if ($isa_check) {
352 $code .=
353 " ".$self->_generate_isa_check($name, $value_store, $isa_check).";\n";
354 }
355 my $simple = $self->_generate_simple_set('$self', $name, $spec, $value_store);
356 if ($trigger) {
357 my $fire = $self->_generate_trigger($name, '$self', $value_store, $trigger);
358 $code .=
359 " ".$simple.";\n ".$fire.";\n"
360 ." $value_store;\n";
361 } else {
362 $code .= " ".$simple.";\n";
363 }
364 $code .= " }";
365 $code;
366 }
367}
368
369sub generate_coerce {
370 my $self = shift;
371 $self->{captures} = {};
372 my $code = $self->_generate_coerce(@_);
373 ($code, delete $self->{captures});
374}
375
376sub _attr_desc {
377 my ($name, $init_arg) = @_;
378 return perlstring($name) if !defined($init_arg) or $init_arg eq $name;
379 return perlstring($name).' (constructor argument: '.perlstring($init_arg).')';
380}
381
382sub _generate_coerce {
383 my ($self, $name, $value, $coerce, $init_arg) = @_;
384 $self->_generate_die_prefix(
385 $name,
386 "coercion",
387 $init_arg,
388 $self->_generate_call_code($name, 'coerce', "${value}", $coerce)
389 );
390}
391
392sub generate_trigger {
393 my $self = shift;
394 $self->{captures} = {};
395 my $code = $self->_generate_trigger(@_);
396 ($code, delete $self->{captures});
397}
398
399sub _generate_trigger {
400 my ($self, $name, $obj, $value, $trigger) = @_;
401 $self->_generate_call_code($name, 'trigger', "${obj}, ${value}", $trigger);
402}
403
404sub generate_isa_check {
405 my ($self, @args) = @_;
406 $self->{captures} = {};
407 my $code = $self->_generate_isa_check(@args);
408 ($code, delete $self->{captures});
409}
410
411sub _generate_die_prefix {
412 my ($self, $name, $prefix, $arg, $inside) = @_;
413 "do {\n"
414 .' local $Method::Generate::Accessor::CurrentAttribute = {'
415 .' init_arg => '.(defined $arg ? B::perlstring($arg) : 'undef') . ",\n"
416 .' name => '.B::perlstring($name).",\n"
417 .' step => '.B::perlstring($prefix).",\n"
418 ." };\n"
419 .' local $Method::Generate::Accessor::OrigSigDie = $SIG{__DIE__};'."\n"
420 .' local $SIG{__DIE__} = \&Method::Generate::Accessor::_SIGDIE;'."\n"
421 .$inside
422 ."}\n"
423}
424
425sub _generate_isa_check {
426 my ($self, $name, $value, $check, $init_arg) = @_;
427 $self->_generate_die_prefix(
428 $name,
429 "isa check",
430 $init_arg,
431 $self->_generate_call_code($name, 'isa_check', $value, $check)
432 );
433}
434
435
# spent 174µs (72+102) within Method::Generate::Accessor::_generate_call_code which was called 6 times, avg 29µs/call: # 6 times (72µs+102µs) by Method::Generate::Accessor::_generate_get_default at line 313, avg 29µs/call
sub _generate_call_code {
43663µs my ($self, $name, $type, $values, $sub) = @_;
437618µs64µs $sub = \&{$sub} if blessed($sub); # coderef if blessed
# spent 4µs making 6 calls to Scalar::Util::blessed, avg 633ns/call
438624µs613µs if (my $quoted = quoted_from_sub($sub)) {
# spent 13µs making 6 calls to Sub::Quote::quoted_from_sub, avg 2µs/call
439 my $local = 1;
440 if ($values eq '@_' || $values eq '$_[0]') {
441 $local = 0;
442 $values = '@_';
443 }
444 my $code = $quoted->[1];
445 if (my $captures = $quoted->[2]) {
446 my $cap_name = qq{\$${type}_captures_for_}.$self->_sanitize_name($name);
447 $self->{captures}->{$cap_name} = \$captures;
448 Sub::Quote::inlinify(
449 $code, $values, Sub::Quote::capture_unroll($cap_name, $captures, 6), $local
450 );
451 } else {
452 Sub::Quote::inlinify($code, $values, undef, $local);
453 }
454 } else {
455613µs686µs my $cap_name = qq{\$${type}_for_}.$self->_sanitize_name($name);
# spent 86µs making 6 calls to Method::Generate::Accessor::_sanitize_name, avg 14µs/call
45668µs $self->{captures}->{$cap_name} = \$sub;
45765µs "${cap_name}->(${values})";
458 }
459}
460
461
# spent 86µs (58+27) within Method::Generate::Accessor::_sanitize_name which was called 6 times, avg 14µs/call: # 6 times (58µs+27µs) by Method::Generate::Accessor::_generate_call_code at line 455, avg 14µs/call
sub _sanitize_name {
46263µs my ($self, $name) = @_;
463674µs1627µs $name =~ s/([_\W])/sprintf('_%x', ord($1))/ge;
# spent 16µs making 6 calls to Method::Generate::Accessor::CORE:subst, avg 3µs/call # spent 11µs making 10 calls to Method::Generate::Accessor::CORE:substcont, avg 1µs/call
464617µs $name;
465}
466
467
# spent 2.32ms (353µs+1.97) within Method::Generate::Accessor::generate_populate_set which was called 76 times, avg 31µs/call: # 76 times (353µs+1.97ms) by Method::Generate::Constructor::_assign_new at line 176 of Method/Generate/Constructor.pm, avg 31µs/call
sub generate_populate_set {
4687616µs my $self = shift;
4697650µs $self->{captures} = {};
4707690µs761.97ms my $code = $self->_generate_populate_set(@_);
# spent 1.97ms making 76 calls to Method::Generate::Accessor::_generate_populate_set, avg 26µs/call
47176193µs ($code, delete $self->{captures});
472}
473
474
# spent 1.97ms (679µs+1.29) within Method::Generate::Accessor::_generate_populate_set which was called 76 times, avg 26µs/call: # 76 times (679µs+1.29ms) by Method::Generate::Accessor::generate_populate_set at line 470, avg 26µs/call
sub _generate_populate_set {
4757639µs my ($self, $me, $name, $spec, $source, $test, $init_arg) = @_;
47676217µs76112µs if ($self->has_eager_default($name, $spec)) {
# spent 112µs making 76 calls to Method::Generate::Accessor::has_eager_default, avg 1µs/call
4773221µs my $get_indent = ' ' x ($spec->{isa} ? 6 : 4);
4783237µs32318µs my $get_default = $self->_generate_get_default(
# spent 318µs making 32 calls to Method::Generate::Accessor::_generate_get_default, avg 10µs/call
479 '$new', $name, $spec
480 );
4813255µs my $get_value =
482 defined($spec->{init_arg})
483 ? "(\n${get_indent} ${test}\n${get_indent} ? ${source}\n${get_indent} : "
484 .$get_default
485 ."\n${get_indent})"
486 : $get_default;
487326µs if ($spec->{coerce}) {
488 $get_value = $self->_generate_coerce(
489 $name, $get_value,
490 $spec->{coerce}, $init_arg
491 )
492 }
4933266µs32369µs ($spec->{isa}
# spent 369µs making 32 calls to Method::Generate::Accessor::_generate_simple_set, avg 12µs/call
494 ? " {\n my \$value = ".$get_value.";\n "
495 .$self->_generate_isa_check(
496 $name, '$value', $spec->{isa}, $init_arg
497 ).";\n"
498 .' '.$self->_generate_simple_set($me, $name, $spec, '$value').";\n"
499 ." }\n"
500 : ' '.$self->_generate_simple_set($me, $name, $spec, $get_value).";\n"
501 )
502 .($spec->{trigger}
503 ? ' '
504 .$self->_generate_trigger(
505 $name, $me, $self->_generate_simple_get($me, $name, $spec),
506 $spec->{trigger}
507 )." if ${test};\n"
508 : ''
509 );
510 } else {
51144101µs44490µs " if (${test}) {\n"
# spent 490µs making 44 calls to Method::Generate::Accessor::_generate_simple_set, avg 11µs/call
512 .($spec->{coerce}
513 ? " $source = "
514 .$self->_generate_coerce(
515 $name, $source,
516 $spec->{coerce}, $init_arg
517 ).";\n"
518 : ""
519 )
520 .($spec->{isa}
521 ? " "
522 .$self->_generate_isa_check(
523 $name, $source, $spec->{isa}, $init_arg
524 ).";\n"
525 : ""
526 )
527 ." ".$self->_generate_simple_set($me, $name, $spec, $source).";\n"
528 .($spec->{trigger}
529 ? " "
530 .$self->_generate_trigger(
531 $name, $me, $self->_generate_simple_get($me, $name, $spec),
532 $spec->{trigger}
533 ).";\n"
534 : ""
535 )
536 ." }\n";
537 }
538}
539
540
# spent 393µs (327+66) within Method::Generate::Accessor::_generate_core_set which was called 91 times, avg 4µs/call: # 91 times (327µs+66µs) by Method::Generate::Accessor::_generate_simple_set at line 549, avg 4µs/call
sub _generate_core_set {
5419133µs my ($self, $me, $name, $spec, $value) = @_;
54291231µs9166µs my $name_str = perlstring $name;
# spent 66µs making 91 calls to B::perlstring, avg 726ns/call
54391233µs "${me}->{${name_str}} = ${value}";
544}
545
546
# spent 1.03ms (568µs+462µs) within Method::Generate::Accessor::_generate_simple_set which was called 91 times, avg 11µs/call: # 44 times (265µs+225µs) by Method::Generate::Accessor::_generate_populate_set at line 511, avg 11µs/call # 32 times (205µs+164µs) by Method::Generate::Accessor::_generate_populate_set at line 493, avg 12µs/call # 15 times (98µs+73µs) by Method::Generate::Accessor::_generate_use_default at line 301, avg 11µs/call
sub _generate_simple_set {
5479140µs my ($self, $me, $name, $spec, $value) = @_;
54891245µs9168µs my $name_str = perlstring $name;
# spent 68µs making 91 calls to B::perlstring, avg 753ns/call
5499198µs91393µs my $simple = $self->_generate_core_set($me, $name, $spec, $value);
# spent 393µs making 91 calls to Method::Generate::Accessor::_generate_core_set, avg 4µs/call
550
55191203µs if ($spec->{weak_ref}) {
552 require Scalar::Util;
553 my $get = $self->_generate_simple_get($me, $name, $spec);
554
555 # Perl < 5.8.3 can't weaken refs to readonly vars
556 # (e.g. string constants). This *can* be solved by:
557 #
558 #Internals::SetReadWrite($foo);
559 #Scalar::Util::weaken ($foo);
560 #Internals::SetReadOnly($foo);
561 #
562 # but requires XS and is just too damn crazy
563 # so simply throw a better exception
564 my $weak_simple = "do { Scalar::Util::weaken(${simple}); no warnings 'void'; $get }";
565 Moo::_Utils::lt_5_8_3() ? <<"EOC" : $weak_simple;
566 eval { Scalar::Util::weaken($simple); 1 }
567 ? do { no warnings 'void'; $get }
568 : do {
569 if( \$@ =~ /Modification of a read-only value attempted/) {
570 require Carp;
571 Carp::croak( sprintf (
572 'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3',
573 $name_str,
574 ) );
575 } else {
576 die \$@;
577 }
578 }
579EOC
580 } else {
5819137µs $simple;
582 }
583}
584
585sub _generate_getset {
586 my ($self, $name, $spec) = @_;
587 q{(@_ > 1}."\n ? ".$self->_generate_set($name, $spec)
588 ."\n : ".$self->_generate_get($name, $spec)."\n )";
589}
590
591
# spent 120µs (17+103) within Method::Generate::Accessor::_generate_asserter which was called 2 times, avg 60µs/call: # 2 times (17µs+103µs) by Method::Generate::Accessor::generate_method at line 217, avg 60µs/call
sub _generate_asserter {
59221µs my ($self, $name, $spec) = @_;
593
594212µs4103µs "do {\n"
# spent 95µs making 2 calls to Method::Generate::Accessor::_generate_get, avg 47µs/call # spent 8µs making 2 calls to Method::Generate::Accessor::_generate_simple_has, avg 4µs/call
595 ." my \$val = ".$self->_generate_get($name, $spec).";\n"
596 ." unless (".$self->_generate_simple_has('$_[0]', $name, $spec).") {\n"
597 .qq! die "Attempted to access '${name}' but it is not set";\n!
598 ." }\n"
599 ." \$val;\n"
600 ."}\n";
601}
602
# spent 53µs within Method::Generate::Accessor::_generate_delegation which was called 18 times, avg 3µs/call: # 18 times (53µs+0s) by Method::Generate::Accessor::generate_method at line 206, avg 3µs/call
sub _generate_delegation {
603188µs my ($self, $asserter, $target, $args) = @_;
604185µs my $arg_string = do {
605187µs if (@$args) {
606 # I could, I reckon, linearise out non-refs here using perlstring
607 # plus something to check for numbers but I'm unsure if it's worth it
608 $self->{captures}{'@curries'} = $args;
609 '@curries, @_';
610 } else {
611183µs '@_';
612 }
613 };
6141850µs "shift->${asserter}->${target}(${arg_string});";
615}
616
617
# spent 10.0ms (561µs+9.47) within Method::Generate::Accessor::_generate_xs which was called 64 times, avg 157µs/call: # 49 times (445µs+8.44ms) by Method::Generate::Accessor::generate_method at line 109, avg 181µs/call # 12 times (93µs+816µs) by Method::Generate::Accessor::generate_method at line 126, avg 76µs/call # 2 times (15µs+140µs) by Method::Generate::Accessor::generate_method at line 146, avg 78µs/call # once (8µs+76µs) by Method::Generate::Accessor::generate_method at line 165
sub _generate_xs {
6186430µs my ($self, $type, $into, $name, $slot) = @_;
61964199µs649.34ms Class::XSAccessor->import(
# spent 9.34ms making 64 calls to Class::XSAccessor::import, avg 146µs/call
620 class => $into,
621 $type => { $name => $slot },
622 replace => 1,
623 );
62464436µs64123µs $into->can($name);
# spent 123µs making 64 calls to UNIVERSAL::can, avg 2µs/call
625}
626
6271021µs
# spent 10µs within Method::Generate::Accessor::default_construction_string which was called 10 times, avg 1µs/call: # 10 times (10µs+0s) by Method::Generate::Constructor::_build_construction_string at line 63 of Method/Generate/Constructor.pm, avg 1µs/call
sub default_construction_string { '{}' }
628
629
# spent 65µs (51+14) within Method::Generate::Accessor::_validate_codulatable which was called 6 times, avg 11µs/call: # 6 times (51µs+14µs) by Method::Generate::Accessor::generate_method at line 89, avg 11µs/call
sub _validate_codulatable {
63064µs my ($self, $setting, $value, $into, $appended) = @_;
631618µs614µs my $invalid = "Invalid $setting '" . overload::StrVal($value)
# spent 14µs making 6 calls to overload::AddrRef, avg 2µs/call
632 . "' for $into not a coderef";
63364µs $invalid .= " $appended" if $appended;
634
63563µs unless (ref $value and (ref $value eq 'CODE' or blessed($value))) {
636 die "$invalid or code-convertible object";
637 }
638
639126µs unless (eval { \&$value }) {
640 die "$invalid and could not be converted to a coderef: $@";
641 }
642
643615µs 1;
644}
645
64612µs1;
 
# spent 39µs within Method::Generate::Accessor::CORE:match which was called 14 times, avg 3µs/call: # 13 times (39µs+0s) by Method::Generate::Accessor::generate_method at line 71, avg 3µs/call # once (300ns+0s) by Method::Generate::Accessor::generate_method at line 78
sub Method::Generate::Accessor::CORE:match; # opcode
# spent 57µs within Method::Generate::Accessor::CORE:subst which was called 80 times, avg 709ns/call: # 74 times (41µs+0s) by Method::Generate::Accessor::generate_method at line 46, avg 549ns/call # 6 times (16µs+0s) by Method::Generate::Accessor::_sanitize_name at line 463, avg 3µs/call
sub Method::Generate::Accessor::CORE:subst; # opcode
# spent 11µs within Method::Generate::Accessor::CORE:substcont which was called 10 times, avg 1µs/call: # 10 times (11µs+0s) by Method::Generate::Accessor::_sanitize_name at line 463, avg 1µs/call
sub Method::Generate::Accessor::CORE:substcont; # opcode