Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Method/Generate/Accessor.pm |
Statements | Executed 5105 statements in 14.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 4.51ms | 6.91ms | BEGIN@8 | Method::Generate::Accessor::
49 | 1 | 1 | 3.10ms | 85.9ms | generate_method | Method::Generate::Accessor::
49 | 1 | 1 | 885µs | 17.6ms | _generate_populate_set | Method::Generate::Accessor::
88 | 3 | 1 | 733µs | 16.6ms | _validate_codulatable | Method::Generate::Accessor::
76 | 3 | 1 | 605µs | 1.74ms | _generate_simple_set | Method::Generate::Accessor::
37 | 2 | 1 | 518µs | 1.08ms | _generate_call_code | Method::Generate::Accessor::
51 | 3 | 1 | 501µs | 17.8ms | _generate_get | Method::Generate::Accessor::
82 | 4 | 1 | 379µs | 922µs | _generate_simple_get | Method::Generate::Accessor::
17 | 1 | 1 | 346µs | 16.4ms | _generate_use_default | Method::Generate::Accessor::
76 | 1 | 1 | 345µs | 633µs | _generate_core_set | Method::Generate::Accessor::
20 | 1 | 1 | 284µs | 797µs | _wrap_attr_exception | Method::Generate::Accessor::
49 | 1 | 1 | 250µs | 17.9ms | generate_populate_set | Method::Generate::Accessor::
10 | 2 | 1 | 247µs | 3.56ms | _generate_set | Method::Generate::Accessor::
14 | 1 | 1 | 218µs | 15.6ms | _generate_asserter | Method::Generate::Accessor::
31 | 2 | 1 | 162µs | 303µs | _generate_simple_has | Method::Generate::Accessor::
41 | 1 | 1 | 159µs | 159µs | _generate_delegation | Method::Generate::Accessor::
51 | 1 | 1 | 137µs | 137µs | is_simple_get | Method::Generate::Accessor::
20 | 1 | 1 | 117µs | 1.38ms | _generate_coerce | Method::Generate::Accessor::
23 | 2 | 1 | 110µs | 760µs | _generate_get_default | Method::Generate::Accessor::
55 | 2 | 2 | 103µs | 103µs | has_eager_default | Method::Generate::Accessor::
20 | 1 | 1 | 69µs | 163µs | _attr_desc | Method::Generate::Accessor::
10 | 1 | 1 | 62µs | 76µs | is_simple_set | Method::Generate::Accessor::
1 | 1 | 1 | 53µs | 84µs | BEGIN@5 | Method::Generate::Accessor::
1 | 1 | 1 | 33µs | 36µs | BEGIN@2 | Method::Generate::Accessor::
2 | 1 | 1 | 33µs | 33µs | merge_specs | Method::Generate::Accessor::
3 | 1 | 1 | 32µs | 770µs | _generate_getset | Method::Generate::Accessor::
13 | 1 | 1 | 30µs | 30µs | has_default | Method::Generate::Accessor::
49 | 1 | 1 | 22µs | 22µs | CORE:subst (opcode) | Method::Generate::Accessor::
1 | 1 | 1 | 20µs | 61µs | BEGIN@685 | Method::Generate::Accessor::
1 | 1 | 1 | 15µs | 36µs | BEGIN@9 | Method::Generate::Accessor::
1 | 1 | 1 | 12µs | 226µs | BEGIN@18 | Method::Generate::Accessor::
5 | 1 | 1 | 10µs | 10µs | default_construction_string | Method::Generate::Accessor::
1 | 1 | 1 | 9µs | 70µs | BEGIN@3 | Method::Generate::Accessor::
1 | 1 | 1 | 7µs | 7µs | BEGIN@7 | Method::Generate::Accessor::
1 | 1 | 1 | 6µs | 30µs | BEGIN@10 | Method::Generate::Accessor::
1 | 1 | 1 | 4µs | 4µs | BEGIN@34 | Method::Generate::Accessor::
1 | 1 | 1 | 3µs | 3µs | BEGIN@11 | Method::Generate::Accessor::
1 | 1 | 1 | 2µs | 2µs | BEGIN@6 | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | __ANON__[:95] | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | _die_overwrite | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | _generate_isa_check | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | _generate_simple_clear | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | _generate_trigger | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | _generate_xs | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | _sanitize_name | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | generate_coerce | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | generate_get_default | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | generate_isa_check | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | generate_simple_get | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | generate_simple_has | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | generate_trigger | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | generate_use_default | Method::Generate::Accessor::
0 | 0 | 0 | 0s | 0s | is_simple_attribute | Method::Generate::Accessor::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Method::Generate::Accessor; | ||||
2 | 2 | 36µs | 2 | 39µs | # spent 36µs (33+3) within Method::Generate::Accessor::BEGIN@2 which was called:
# once (33µs+3µs) by Moo::_accessor_maker_for at line 2 # spent 36µs making 1 call to Method::Generate::Accessor::BEGIN@2
# spent 3µs making 1 call to strict::import |
3 | 2 | 40µs | 2 | 131µs | # spent 70µs (9+61) within Method::Generate::Accessor::BEGIN@3 which was called:
# once (9µs+61µs) by Moo::_accessor_maker_for at line 3 # spent 70µs making 1 call to Method::Generate::Accessor::BEGIN@3
# spent 61µs making 1 call to warnings::import |
4 | |||||
5 | 2 | 64µs | 2 | 115µs | # spent 84µs (53+31) within Method::Generate::Accessor::BEGIN@5 which was called:
# once (53µs+31µs) by Moo::_accessor_maker_for at line 5 # spent 84µs making 1 call to Method::Generate::Accessor::BEGIN@5
# spent 31µs making 1 call to Exporter::import |
6 | 2 | 35µs | 1 | 2µs | # spent 2µs within Method::Generate::Accessor::BEGIN@6 which was called:
# once (2µs+0s) by Moo::_accessor_maker_for at line 6 # spent 2µs making 1 call to Method::Generate::Accessor::BEGIN@6 |
7 | 1 | 25µs | 1 | 7µs | # spent 7µs within Method::Generate::Accessor::BEGIN@7 which was called:
# once (7µs+0s) by Moo::_accessor_maker_for at line 7 # spent 7µs making 1 call to Method::Generate::Accessor::BEGIN@7 |
8 | 2 | 572µs | 2 | 7.00ms | # spent 6.91ms (4.51+2.40) within Method::Generate::Accessor::BEGIN@8 which was called:
# once (4.51ms+2.40ms) by Moo::_accessor_maker_for at line 8 # spent 6.91ms making 1 call to Method::Generate::Accessor::BEGIN@8
# spent 86µs making 1 call to Exporter::import |
9 | 2 | 35µs | 2 | 57µs | # spent 36µs (15+21) within Method::Generate::Accessor::BEGIN@9 which was called:
# once (15µs+21µs) by Moo::_accessor_maker_for at line 9 # spent 36µs making 1 call to Method::Generate::Accessor::BEGIN@9
# spent 21µs making 1 call to Exporter::import |
10 | 2 | 48µs | 2 | 54µs | # spent 30µs (6+24) within Method::Generate::Accessor::BEGIN@10 which was called:
# once (6µs+24µs) by Moo::_accessor_maker_for at line 10 # spent 30µs making 1 call to Method::Generate::Accessor::BEGIN@10
# spent 24µs making 1 call to Exporter::import |
11 | # spent 3µs within Method::Generate::Accessor::BEGIN@11 which was called:
# once (3µs+0s) by Moo::_accessor_maker_for at line 17 | ||||
12 | 1 | 3µs | our @CARP_NOT = qw( | ||
13 | Moo::_Utils | ||||
14 | Moo::Object | ||||
15 | Moo::Role | ||||
16 | ); | ||||
17 | 1 | 126µs | 1 | 3µs | } # spent 3µs making 1 call to Method::Generate::Accessor::BEGIN@11 |
18 | # spent 226µs (12+214) within Method::Generate::Accessor::BEGIN@18 which was called:
# once (12µs+214µs) by Moo::_accessor_maker_for at line 33 | ||||
19 | *_CAN_WEAKEN_READONLY = ( | ||||
20 | "$]" < 5.008_003 or $ENV{MOO_TEST_PRE_583} | ||||
21 | 1 | 4µs | ) ? sub(){0} : sub(){1}; | ||
22 | our $CAN_HAZ_XS = | ||||
23 | !$ENV{MOO_XS_DISABLE} | ||||
24 | && | ||||
25 | _maybe_load_module('Class::XSAccessor') | ||||
26 | && | ||||
27 | 1 | 2µs | 1 | 214µs | (eval { Class::XSAccessor->VERSION('1.07') }) # spent 214µs making 1 call to Moo::_Utils::_maybe_load_module |
28 | ; | ||||
29 | our $CAN_HAZ_XS_PRED = | ||||
30 | $CAN_HAZ_XS && | ||||
31 | 1 | 4µs | (eval { Class::XSAccessor->VERSION('1.17') }) | ||
32 | ; | ||||
33 | 1 | 66µs | 1 | 226µs | } # spent 226µs making 1 call to Method::Generate::Accessor::BEGIN@18 |
34 | # spent 4µs within Method::Generate::Accessor::BEGIN@34 which was called:
# once (4µs+0s) by Moo::_accessor_maker_for at line 38 | ||||
35 | package | ||||
36 | Method::Generate::Accessor::_Generated; | ||||
37 | 1 | 4µs | $Carp::Internal{+__PACKAGE__} = 1; | ||
38 | 1 | 4.42ms | 1 | 4µs | } # spent 4µs making 1 call to Method::Generate::Accessor::BEGIN@34 |
39 | |||||
40 | sub _die_overwrite { | ||||
41 | my ($pkg, $method, $type) = @_; | ||||
42 | croak "You cannot overwrite a locally defined method ($method) with " | ||||
43 | . ( $type || 'an accessor' ); | ||||
44 | } | ||||
45 | |||||
46 | # spent 85.9ms (3.10+82.8) within Method::Generate::Accessor::generate_method which was called 49 times, avg 1.75ms/call:
# 49 times (3.10ms+82.8ms) by Moo::has at line 121 of Moo.pm, avg 1.75ms/call | ||||
47 | 49 | 36µs | my ($self, $into, $name, $spec, $quote_opts) = @_; | ||
48 | $quote_opts = { | ||||
49 | no_defer => 1, | ||||
50 | package => 'Method::Generate::Accessor::_Generated', | ||||
51 | 49 | 202µs | %{ $quote_opts||{} }, | ||
52 | }; | ||||
53 | 49 | 109µs | 49 | 22µs | $spec->{allow_overwrite}++ if $name =~ s/^\+//; # spent 22µs making 49 calls to Method::Generate::Accessor::CORE:subst, avg 449ns/call |
54 | 49 | 39µs | croak "Must have an is" unless my $is = $spec->{is}; | ||
55 | 49 | 87µs | if ($is eq 'ro') { | ||
56 | $spec->{reader} = $name unless exists $spec->{reader}; | ||||
57 | } elsif ($is eq 'rw') { | ||||
58 | $spec->{accessor} = $name unless exists $spec->{accessor} | ||||
59 | or ( $spec->{reader} and $spec->{writer} ); | ||||
60 | } elsif ($is eq 'lazy') { | ||||
61 | $spec->{reader} = $name unless exists $spec->{reader}; | ||||
62 | $spec->{lazy} = 1; | ||||
63 | $spec->{builder} ||= '_build_'.$name unless exists $spec->{default}; | ||||
64 | } elsif ($is eq 'rwp') { | ||||
65 | 6 | 7µs | $spec->{reader} = $name unless exists $spec->{reader}; | ||
66 | 6 | 4µs | $spec->{writer} = "_set_${name}" unless exists $spec->{writer}; | ||
67 | } elsif ($is ne 'bare') { | ||||
68 | croak "Unknown is ${is}"; | ||||
69 | } | ||||
70 | 49 | 11µs | if (exists $spec->{builder}) { | ||
71 | if(ref $spec->{builder}) { | ||||
72 | $self->_validate_codulatable('builder', $spec->{builder}, | ||||
73 | "$into->$name", 'or a method name'); | ||||
74 | $spec->{builder_sub} = $spec->{builder}; | ||||
75 | $spec->{builder} = 1; | ||||
76 | } | ||||
77 | $spec->{builder} = '_build_'.$name if ($spec->{builder}||0) eq 1; | ||||
78 | croak "Invalid builder for $into->$name - not a valid method name" | ||||
79 | if $spec->{builder} !~ _module_name_rx; | ||||
80 | } | ||||
81 | 49 | 40µs | if (($spec->{predicate}||0) eq 1) { | ||
82 | $spec->{predicate} = $name =~ /^_/ ? "_has${name}" : "has_${name}"; | ||||
83 | } | ||||
84 | 49 | 30µs | if (($spec->{clearer}||0) eq 1) { | ||
85 | $spec->{clearer} = $name =~ /^_/ ? "_clear${name}" : "clear_${name}"; | ||||
86 | } | ||||
87 | 49 | 25µs | if (($spec->{trigger}||0) eq 1) { | ||
88 | $spec->{trigger} = quote_sub('shift->_trigger_'.$name.'(@_)'); | ||||
89 | } | ||||
90 | 49 | 27µs | if (($spec->{coerce}||0) eq 1) { | ||
91 | my $isa = $spec->{isa}; | ||||
92 | if (blessed $isa and $isa->can('coercion')) { | ||||
93 | $spec->{coerce} = $isa->coercion; | ||||
94 | } elsif (blessed $isa and $isa->can('coerce')) { | ||||
95 | $spec->{coerce} = sub { $isa->coerce(@_) }; | ||||
96 | } else { | ||||
97 | croak "Invalid coercion for $into->$name - no appropriate type constraint"; | ||||
98 | } | ||||
99 | } | ||||
100 | |||||
101 | 49 | 34µs | foreach my $setting (qw( isa coerce )) { | ||
102 | 98 | 32µs | next if !exists $spec->{$setting}; | ||
103 | 59 | 169µs | 59 | 16.5ms | $self->_validate_codulatable($setting, $spec->{$setting}, "$into->$name"); # spent 16.5ms making 59 calls to Method::Generate::Accessor::_validate_codulatable, avg 279µs/call |
104 | } | ||||
105 | |||||
106 | 49 | 79µs | 17 | 72µs | if (exists $spec->{default}) { # spent 72µs making 17 calls to Method::Generate::Accessor::_validate_codulatable, avg 4µs/call |
107 | if (ref $spec->{default}) { | ||||
108 | $self->_validate_codulatable('default', $spec->{default}, "$into->$name", | ||||
109 | 'or a non-ref'); | ||||
110 | } | ||||
111 | } | ||||
112 | |||||
113 | 49 | 21µs | if (exists $spec->{moosify}) { | ||
114 | 12 | 17µs | if (ref $spec->{moosify} ne 'ARRAY') { | ||
115 | $spec->{moosify} = [$spec->{moosify}]; | ||||
116 | } | ||||
117 | |||||
118 | 12 | 15µs | foreach my $spec (@{$spec->{moosify}}) { | ||
119 | 12 | 22µs | 12 | 55µs | $self->_validate_codulatable('moosify', $spec, "$into->$name"); # spent 55µs making 12 calls to Method::Generate::Accessor::_validate_codulatable, avg 5µs/call |
120 | } | ||||
121 | } | ||||
122 | |||||
123 | 49 | 7µs | my %methods; | ||
124 | 49 | 59µs | if (my $reader = $spec->{reader}) { | ||
125 | _die_overwrite($into, $reader, 'a reader') | ||||
126 | 34 | 138µs | if !$spec->{allow_overwrite} && defined &{"${into}::${reader}"}; | ||
127 | 34 | 24µs | if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) { | ||
128 | $methods{$reader} = $self->_generate_xs( | ||||
129 | getters => $into, $reader, $name, $spec | ||||
130 | ); | ||||
131 | } else { | ||||
132 | 34 | 25µs | $self->{captures} = {}; | ||
133 | $methods{$reader} = | ||||
134 | quote_sub "${into}::${reader}" | ||||
135 | => ' Carp::croak("'.$reader.' is a read-only accessor") if @_ > 1;'."\n" | ||||
136 | .$self->_generate_get($name, $spec) | ||||
137 | => delete $self->{captures} | ||||
138 | 34 | 168µs | 68 | 17.5ms | => $quote_opts # spent 14.9ms making 34 calls to Sub::Quote::quote_sub, avg 438µs/call
# spent 2.58ms making 34 calls to Method::Generate::Accessor::_generate_get, avg 76µs/call |
139 | ; | ||||
140 | } | ||||
141 | } | ||||
142 | 49 | 34µs | if (my $accessor = $spec->{accessor}) { | ||
143 | _die_overwrite($into, $accessor, 'an accessor') | ||||
144 | 3 | 13µs | if !$spec->{allow_overwrite} && defined &{"${into}::${accessor}"}; | ||
145 | 3 | 4µs | if ( | ||
146 | our $CAN_HAZ_XS | ||||
147 | && $self->is_simple_get($name, $spec) | ||||
148 | && $self->is_simple_set($name, $spec) | ||||
149 | ) { | ||||
150 | $methods{$accessor} = $self->_generate_xs( | ||||
151 | accessors => $into, $accessor, $name, $spec | ||||
152 | ); | ||||
153 | } else { | ||||
154 | 3 | 2µs | $self->{captures} = {}; | ||
155 | $methods{$accessor} = | ||||
156 | quote_sub "${into}::${accessor}" | ||||
157 | => $self->_generate_getset($name, $spec) | ||||
158 | => delete $self->{captures} | ||||
159 | 3 | 20µs | 6 | 2.60ms | => $quote_opts # spent 1.83ms making 3 calls to Sub::Quote::quote_sub, avg 609µs/call
# spent 770µs making 3 calls to Method::Generate::Accessor::_generate_getset, avg 257µs/call |
160 | ; | ||||
161 | } | ||||
162 | } | ||||
163 | 49 | 39µs | if (my $writer = $spec->{writer}) { | ||
164 | _die_overwrite($into, $writer, 'a writer') | ||||
165 | 7 | 15µs | if !$spec->{allow_overwrite} && defined &{"${into}::${writer}"}; | ||
166 | 7 | 8µs | if ( | ||
167 | our $CAN_HAZ_XS | ||||
168 | && $self->is_simple_set($name, $spec) | ||||
169 | ) { | ||||
170 | $methods{$writer} = $self->_generate_xs( | ||||
171 | setters => $into, $writer, $name, $spec | ||||
172 | ); | ||||
173 | } else { | ||||
174 | 7 | 4µs | $self->{captures} = {}; | ||
175 | $methods{$writer} = | ||||
176 | quote_sub "${into}::${writer}" | ||||
177 | => $self->_generate_set($name, $spec) | ||||
178 | => delete $self->{captures} | ||||
179 | 7 | 72µs | 14 | 7.10ms | => $quote_opts # spent 4.25ms making 7 calls to Sub::Quote::quote_sub, avg 607µs/call
# spent 2.86ms making 7 calls to Method::Generate::Accessor::_generate_set, avg 408µs/call |
180 | ; | ||||
181 | } | ||||
182 | } | ||||
183 | 49 | 31µs | if (my $pred = $spec->{predicate}) { | ||
184 | _die_overwrite($into, $pred, 'a predicate') | ||||
185 | if !$spec->{allow_overwrite} && defined &{"${into}::${pred}"}; | ||||
186 | if (our $CAN_HAZ_XS && our $CAN_HAZ_XS_PRED) { | ||||
187 | $methods{$pred} = $self->_generate_xs( | ||||
188 | exists_predicates => $into, $pred, $name, $spec | ||||
189 | ); | ||||
190 | } else { | ||||
191 | $self->{captures} = {}; | ||||
192 | $methods{$pred} = | ||||
193 | quote_sub "${into}::${pred}" | ||||
194 | => $self->_generate_simple_has('$_[0]', $name, $spec)."\n" | ||||
195 | => delete $self->{captures} | ||||
196 | => $quote_opts | ||||
197 | ; | ||||
198 | } | ||||
199 | } | ||||
200 | 49 | 90µs | if (my $builder = delete $spec->{builder_sub}) { | ||
201 | _install_coderef( "${into}::$spec->{builder}" => $builder ); | ||||
202 | } | ||||
203 | 49 | 28µs | if (my $cl = $spec->{clearer}) { | ||
204 | _die_overwrite($into, $cl, 'a clearer') | ||||
205 | if !$spec->{allow_overwrite} && defined &{"${into}::${cl}"}; | ||||
206 | $self->{captures} = {}; | ||||
207 | $methods{$cl} = | ||||
208 | quote_sub "${into}::${cl}" | ||||
209 | => $self->_generate_simple_clear('$_[0]', $name, $spec)."\n" | ||||
210 | => delete $self->{captures} | ||||
211 | => $quote_opts | ||||
212 | ; | ||||
213 | } | ||||
214 | 49 | 27µs | if (my $hspec = $spec->{handles}) { | ||
215 | 14 | 32µs | my $asserter = $spec->{asserter} ||= '_assert_'.$name; | ||
216 | 14 | 43µs | my @specs = do { | ||
217 | 14 | 68µs | if (ref($hspec) eq 'ARRAY') { | ||
218 | map [ $_ => $_ ], @$hspec; | ||||
219 | } elsif (ref($hspec) eq 'HASH') { | ||||
220 | map [ $_ => ref($hspec->{$_}) ? @{$hspec->{$_}} : $hspec->{$_} ], | ||||
221 | keys %$hspec; | ||||
222 | } elsif (!ref($hspec)) { | ||||
223 | require Moo::Role; | ||||
224 | map [ $_ => $_ ], Moo::Role->methods_provided_by($hspec) | ||||
225 | } else { | ||||
226 | croak "You gave me a handles of ${hspec} and I have no idea why"; | ||||
227 | } | ||||
228 | }; | ||||
229 | 14 | 22µs | foreach my $delegation_spec (@specs) { | ||
230 | 41 | 22µs | my ($proxy, $target, @args) = @$delegation_spec; | ||
231 | _die_overwrite($into, $proxy, 'a delegation') | ||||
232 | 41 | 141µs | if !$spec->{allow_overwrite} && defined &{"${into}::${proxy}"}; | ||
233 | 41 | 29µs | $self->{captures} = {}; | ||
234 | $methods{$proxy} = | ||||
235 | quote_sub "${into}::${proxy}" | ||||
236 | => $self->_generate_delegation($asserter, $target, \@args) | ||||
237 | => delete $self->{captures} | ||||
238 | 41 | 274µs | 82 | 14.0ms | => $quote_opts # spent 13.9ms making 41 calls to Sub::Quote::quote_sub, avg 338µs/call
# spent 159µs making 41 calls to Method::Generate::Accessor::_generate_delegation, avg 4µs/call |
239 | ; | ||||
240 | } | ||||
241 | } | ||||
242 | 49 | 87µs | if (my $asserter = $spec->{asserter}) { | ||
243 | _die_overwrite($into, $asserter, 'an asserter') | ||||
244 | 14 | 41µs | if !$spec->{allow_overwrite} && defined &{"${into}::${asserter}"}; | ||
245 | 14 | 12µs | local $self->{captures} = {}; | ||
246 | $methods{$asserter} = | ||||
247 | quote_sub "${into}::${asserter}" | ||||
248 | => $self->_generate_asserter($name, $spec) | ||||
249 | => delete $self->{captures} | ||||
250 | 14 | 102µs | 28 | 25.0ms | => $quote_opts # spent 15.6ms making 14 calls to Method::Generate::Accessor::_generate_asserter, avg 1.12ms/call
# spent 9.36ms making 14 calls to Sub::Quote::quote_sub, avg 669µs/call |
251 | ; | ||||
252 | } | ||||
253 | 49 | 253µs | \%methods; | ||
254 | } | ||||
255 | |||||
256 | # spent 33µs within Method::Generate::Accessor::merge_specs which was called 2 times, avg 16µs/call:
# 2 times (33µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 27 of Method/Generate/Constructor.pm, avg 16µs/call | ||||
257 | 2 | 1µs | my ($self, @specs) = @_; | ||
258 | 2 | 1µs | my $spec = shift @specs; | ||
259 | 2 | 2µs | for my $old_spec (@specs) { | ||
260 | 2 | 5µs | foreach my $key (keys %$old_spec) { | ||
261 | 12 | 20µs | if ($key eq 'handles') { | ||
262 | } | ||||
263 | elsif ($key eq 'moosify') { | ||||
264 | $spec->{$key} = [ | ||||
265 | map { ref $_ eq 'ARRAY' ? @$_ : $_ } | ||||
266 | grep defined, | ||||
267 | ($old_spec->{$key}, $spec->{$key}) | ||||
268 | ]; | ||||
269 | } | ||||
270 | elsif ($key eq 'builder' || $key eq 'default') { | ||||
271 | $spec->{$key} = $old_spec->{$key} | ||||
272 | if !(exists $spec->{builder} || exists $spec->{default}); | ||||
273 | } | ||||
274 | elsif (!exists $spec->{$key}) { | ||||
275 | $spec->{$key} = $old_spec->{$key}; | ||||
276 | } | ||||
277 | } | ||||
278 | } | ||||
279 | 2 | 6µs | $spec; | ||
280 | } | ||||
281 | |||||
282 | sub is_simple_attribute { | ||||
283 | my ($self, $name, $spec) = @_; | ||||
284 | # clearer doesn't have to be listed because it doesn't | ||||
285 | # affect whether defined/exists makes a difference | ||||
286 | !grep $spec->{$_}, | ||||
287 | qw(lazy default builder coerce isa trigger predicate weak_ref); | ||||
288 | } | ||||
289 | |||||
290 | # spent 137µs within Method::Generate::Accessor::is_simple_get which was called 51 times, avg 3µs/call:
# 51 times (137µs+0s) by Method::Generate::Accessor::_generate_get at line 313, avg 3µs/call | ||||
291 | 51 | 24µs | my ($self, $name, $spec) = @_; | ||
292 | 51 | 107µs | !($spec->{lazy} and (exists $spec->{default} or $spec->{builder})); | ||
293 | } | ||||
294 | |||||
295 | # spent 76µs (62+14) within Method::Generate::Accessor::is_simple_set which was called 10 times, avg 8µs/call:
# 10 times (62µs+14µs) by Method::Generate::Accessor::_generate_set at line 402, avg 8µs/call | ||||
296 | 10 | 5µs | my ($self, $name, $spec) = @_; | ||
297 | 10 | 60µs | 10 | 14µs | !grep $spec->{$_}, qw(coerce isa trigger weak_ref); # spent 14µs making 10 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 1µs/call |
298 | } | ||||
299 | |||||
300 | # spent 30µs within Method::Generate::Accessor::has_default which was called 13 times, avg 2µs/call:
# 13 times (30µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 29 of Method/Generate/Constructor.pm, avg 2µs/call | ||||
301 | 13 | 10µs | my ($self, $name, $spec) = @_; | ||
302 | 13 | 28µs | $spec->{builder} or exists $spec->{default} or (($spec->{is}||'') eq 'lazy'); | ||
303 | } | ||||
304 | |||||
305 | # spent 103µs within Method::Generate::Accessor::has_eager_default which was called 55 times, avg 2µs/call:
# 49 times (96µs+0s) by Method::Generate::Accessor::_generate_populate_set at line 547, avg 2µs/call
# 6 times (7µs+0s) by Method::Generate::Constructor::_assign_new at line 214 of Method/Generate/Constructor.pm, avg 1µs/call | ||||
306 | 55 | 42µs | my ($self, $name, $spec) = @_; | ||
307 | 55 | 104µs | (!$spec->{lazy} and (exists $spec->{default} or $spec->{builder})); | ||
308 | } | ||||
309 | |||||
310 | # spent 17.8ms (501µs+17.3) within Method::Generate::Accessor::_generate_get which was called 51 times, avg 349µs/call:
# 34 times (276µs+2.31ms) by Method::Generate::Accessor::generate_method at line 138, avg 76µs/call
# 14 times (212µs+15.0ms) by Method::Generate::Accessor::_generate_asserter at line 644, avg 1.09ms/call
# 3 times (13µs+21µs) by Method::Generate::Accessor::_generate_getset at line 637, avg 11µs/call | ||||
311 | 51 | 21µs | my ($self, $name, $spec) = @_; | ||
312 | 51 | 105µs | 51 | 637µs | my $simple = $self->_generate_simple_get('$_[0]', $name, $spec); # spent 637µs making 51 calls to Method::Generate::Accessor::_generate_simple_get, avg 12µs/call |
313 | 51 | 245µs | 51 | 137µs | if ($self->is_simple_get($name, $spec)) { # spent 137µs making 51 calls to Method::Generate::Accessor::is_simple_get, avg 3µs/call |
314 | $simple; | ||||
315 | } else { | ||||
316 | 17 | 100µs | 34 | 16.5ms | $self->_generate_use_default( # spent 16.4ms making 17 calls to Method::Generate::Accessor::_generate_use_default, avg 963µs/call
# spent 176µs making 17 calls to Method::Generate::Accessor::_generate_simple_has, avg 10µs/call |
317 | '$_[0]', $name, $spec, | ||||
318 | $self->_generate_simple_has('$_[0]', $name, $spec), | ||||
319 | ); | ||||
320 | } | ||||
321 | } | ||||
322 | |||||
323 | sub generate_simple_has { | ||||
324 | my $self = shift; | ||||
325 | $self->{captures} = {}; | ||||
326 | my $code = $self->_generate_simple_has(@_); | ||||
327 | ($code, delete $self->{captures}); | ||||
328 | } | ||||
329 | |||||
330 | # spent 303µs (162+141) within Method::Generate::Accessor::_generate_simple_has which was called 31 times, avg 10µs/call:
# 17 times (99µs+77µs) by Method::Generate::Accessor::_generate_get at line 316, avg 10µs/call
# 14 times (63µs+64µs) by Method::Generate::Accessor::_generate_asserter at line 644, avg 9µs/call | ||||
331 | 31 | 19µs | my ($self, $me, $name) = @_; | ||
332 | 31 | 113µs | 31 | 141µs | "exists ${me}->{${\quotify $name}}"; # spent 141µs making 31 calls to Sub::Quote::quotify, avg 5µs/call |
333 | } | ||||
334 | |||||
335 | sub _generate_simple_clear { | ||||
336 | my ($self, $me, $name) = @_; | ||||
337 | " delete ${me}->{${\quotify $name}}\n" | ||||
338 | } | ||||
339 | |||||
340 | sub generate_get_default { | ||||
341 | my $self = shift; | ||||
342 | $self->{captures} = {}; | ||||
343 | my $code = $self->_generate_get_default(@_); | ||||
344 | ($code, delete $self->{captures}); | ||||
345 | } | ||||
346 | |||||
347 | sub generate_use_default { | ||||
348 | my $self = shift; | ||||
349 | $self->{captures} = {}; | ||||
350 | my $code = $self->_generate_use_default(@_); | ||||
351 | ($code, delete $self->{captures}); | ||||
352 | } | ||||
353 | |||||
354 | # spent 16.4ms (346µs+16.0) within Method::Generate::Accessor::_generate_use_default which was called 17 times, avg 963µs/call:
# 17 times (346µs+16.0ms) by Method::Generate::Accessor::_generate_get at line 316, avg 963µs/call | ||||
355 | 17 | 12µs | my ($self, $me, $name, $spec, $test) = @_; | ||
356 | 17 | 38µs | 17 | 698µs | my $get_value = $self->_generate_get_default($me, $name, $spec); # spent 698µs making 17 calls to Method::Generate::Accessor::_generate_get_default, avg 41µs/call |
357 | 17 | 21µs | 4 | 399µs | if ($spec->{coerce}) { # spent 399µs making 4 calls to Method::Generate::Accessor__WITH__MooX::TypeTiny::Role::GenerateAccessor::_generate_coerce, avg 100µs/call |
358 | $get_value = $self->_generate_coerce( | ||||
359 | $name, $get_value, | ||||
360 | $spec->{coerce} | ||||
361 | ) | ||||
362 | } | ||||
363 | $test." ? \n" | ||||
364 | .$self->_generate_simple_get($me, $name, $spec)."\n:" | ||||
365 | .($spec->{isa} ? | ||||
366 | " do {\n my \$value = ".$get_value.";\n" | ||||
367 | 17 | 283µs | 68 | 14.9ms | ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n" # spent 14.3ms making 17 calls to Method::Generate::Accessor__WITH__MooX::TypeTiny::Role::GenerateAccessor::_generate_isa_check, avg 839µs/call
# spent 475µs making 17 calls to Method::Generate::Accessor::_generate_simple_set, avg 28µs/call
# spent 156µs making 17 calls to Method::Generate::Accessor::_generate_simple_get, avg 9µs/call
# spent 34µs making 17 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 2µs/call |
368 | ." ".$self->_generate_simple_set($me, $name, $spec, '$value')."\n" | ||||
369 | ." }\n" | ||||
370 | : ' ('.$self->_generate_simple_set($me, $name, $spec, $get_value).")\n" | ||||
371 | ); | ||||
372 | } | ||||
373 | |||||
374 | # spent 760µs (110+650) within Method::Generate::Accessor::_generate_get_default which was called 23 times, avg 33µs/call:
# 17 times (90µs+608µs) by Method::Generate::Accessor::_generate_use_default at line 356, avg 41µs/call
# 6 times (20µs+42µs) by Method::Generate::Accessor::_generate_populate_set at line 552, avg 10µs/call | ||||
375 | 23 | 16µs | my ($self, $me, $name, $spec) = @_; | ||
376 | 23 | 96µs | 23 | 650µs | if (exists $spec->{default}) { # spent 608µs making 17 calls to Method::Generate::Accessor::_generate_call_code, avg 36µs/call
# spent 42µs making 6 calls to Sub::Quote::quotify, avg 7µs/call |
377 | ref $spec->{default} | ||||
378 | ? $self->_generate_call_code($name, 'default', $me, $spec->{default}) | ||||
379 | : quotify $spec->{default}; | ||||
380 | } | ||||
381 | else { | ||||
382 | "${me}->${\$spec->{builder}}" | ||||
383 | } | ||||
384 | } | ||||
385 | |||||
386 | sub generate_simple_get { | ||||
387 | my ($self, @args) = @_; | ||||
388 | $self->{captures} = {}; | ||||
389 | my $code = $self->_generate_simple_get(@args); | ||||
390 | ($code, delete $self->{captures}); | ||||
391 | } | ||||
392 | |||||
393 | # spent 922µs (379+543) within Method::Generate::Accessor::_generate_simple_get which was called 82 times, avg 11µs/call:
# 51 times (246µs+391µs) by Method::Generate::Accessor::_generate_get at line 312, avg 12µs/call
# 17 times (48µs+108µs) by Method::Generate::Accessor::_generate_use_default at line 367, avg 9µs/call
# 10 times (64µs+27µs) by Method::Generate::Accessor::_generate_set at line 410, avg 9µs/call
# 4 times (21µs+17µs) by Method::Generate::Accessor::_generate_simple_set at line 601, avg 10µs/call | ||||
394 | 82 | 36µs | my ($self, $me, $name) = @_; | ||
395 | 82 | 129µs | 82 | 543µs | my $name_str = quotify $name; # spent 543µs making 82 calls to Sub::Quote::quotify, avg 7µs/call |
396 | 82 | 230µs | "${me}->{${name_str}}"; | ||
397 | } | ||||
398 | |||||
399 | # spent 3.56ms (247µs+3.31) within Method::Generate::Accessor::_generate_set which was called 10 times, avg 356µs/call:
# 7 times (197µs+2.66ms) by Method::Generate::Accessor::generate_method at line 179, avg 408µs/call
# 3 times (50µs+654µs) by Method::Generate::Accessor::_generate_getset at line 637, avg 235µs/call | ||||
400 | 10 | 3µs | my ($self, $name, $spec) = @_; | ||
401 | 10 | 6µs | my ($me, $source) = ('$_[0]', '$_[1]'); | ||
402 | 10 | 16µs | 10 | 76µs | if ($self->is_simple_set($name, $spec)) { # spent 76µs making 10 calls to Method::Generate::Accessor::is_simple_set, avg 8µs/call |
403 | return $self->_generate_simple_set($me, $name, $spec, $source); | ||||
404 | } | ||||
405 | |||||
406 | 10 | 10µs | my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)}; | ||
407 | 10 | 11µs | 4 | 545µs | if ($coerce) { # spent 545µs making 4 calls to Method::Generate::Accessor__WITH__MooX::TypeTiny::Role::GenerateAccessor::_generate_coerce, avg 136µs/call |
408 | $source = $self->_generate_coerce($name, $source, $coerce); | ||||
409 | } | ||||
410 | 10 | 143µs | 40 | 2.69ms | if ($isa_check) { # spent 2.26ms making 10 calls to Method::Generate::Accessor__WITH__MooX::TypeTiny::Role::GenerateAccessor::_generate_isa_check, avg 226µs/call
# spent 335µs making 10 calls to Method::Generate::Accessor::_generate_simple_set, avg 34µs/call
# spent 91µs making 10 calls to Method::Generate::Accessor::_generate_simple_get, avg 9µs/call
# spent 6µs making 10 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 600ns/call |
411 | 'scalar do { my $value = '.$source.";\n" | ||||
412 | .' ('.$self->_generate_isa_check($name, '$value', $isa_check)."),\n" | ||||
413 | .' ('.$self->_generate_simple_set($me, $name, $spec, '$value')."),\n" | ||||
414 | .($trigger | ||||
415 | ? '('.$self->_generate_trigger($name, $me, '$value', $trigger)."),\n" | ||||
416 | : '') | ||||
417 | .' ('.$self->_generate_simple_get($me, $name, $spec)."),\n" | ||||
418 | ."}"; | ||||
419 | } | ||||
420 | elsif ($trigger) { | ||||
421 | my $set = $self->_generate_simple_set($me, $name, $spec, $source); | ||||
422 | "scalar (\n" | ||||
423 | . ' ('.$self->_generate_trigger($name, $me, "($set)", $trigger)."),\n" | ||||
424 | . ' ('.$self->_generate_simple_get($me, $name, $spec)."),\n" | ||||
425 | . ")"; | ||||
426 | } | ||||
427 | else { | ||||
428 | '('.$self->_generate_simple_set($me, $name, $spec, $source).')'; | ||||
429 | } | ||||
430 | } | ||||
431 | |||||
432 | sub generate_coerce { | ||||
433 | my $self = shift; | ||||
434 | $self->{captures} = {}; | ||||
435 | my $code = $self->_generate_coerce(@_); | ||||
436 | ($code, delete $self->{captures}); | ||||
437 | } | ||||
438 | |||||
439 | # spent 163µs (69+94) within Method::Generate::Accessor::_attr_desc which was called 20 times, avg 8µs/call:
# 20 times (69µs+94µs) by Method::Generate::Accessor::_wrap_attr_exception at line 477, avg 8µs/call | ||||
440 | 20 | 6µs | my ($name, $init_arg) = @_; | ||
441 | 20 | 60µs | 20 | 94µs | return quotify($name) if !defined($init_arg) or $init_arg eq $name; # spent 94µs making 20 calls to Sub::Quote::quotify, avg 5µs/call |
442 | return quotify($name).' (constructor argument: '.quotify($init_arg).')'; | ||||
443 | } | ||||
444 | |||||
445 | # spent 1.38ms (117µs+1.27) within Method::Generate::Accessor::_generate_coerce which was called 20 times, avg 69µs/call:
# 20 times (117µs+1.27ms) by MooX::TypeTiny::Role::GenerateAccessor::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/MooX/TypeTiny/Role/GenerateAccessor.pm:63] at line 42 of MooX/TypeTiny/Role/GenerateAccessor.pm, avg 69µs/call | ||||
446 | 20 | 8µs | my ($self, $name, $value, $coerce, $init_arg) = @_; | ||
447 | 20 | 101µs | 40 | 1.27ms | $self->_wrap_attr_exception( # spent 797µs making 20 calls to Method::Generate::Accessor::_wrap_attr_exception, avg 40µs/call
# spent 468µs making 20 calls to Method::Generate::Accessor::_generate_call_code, avg 23µs/call |
448 | $name, | ||||
449 | "coercion", | ||||
450 | $init_arg, | ||||
451 | $self->_generate_call_code($name, 'coerce', "${value}", $coerce), | ||||
452 | 1, | ||||
453 | ); | ||||
454 | } | ||||
455 | |||||
456 | sub generate_trigger { | ||||
457 | my $self = shift; | ||||
458 | $self->{captures} = {}; | ||||
459 | my $code = $self->_generate_trigger(@_); | ||||
460 | ($code, delete $self->{captures}); | ||||
461 | } | ||||
462 | |||||
463 | sub _generate_trigger { | ||||
464 | my ($self, $name, $obj, $value, $trigger) = @_; | ||||
465 | $self->_generate_call_code($name, 'trigger', "${obj}, ${value}", $trigger); | ||||
466 | } | ||||
467 | |||||
468 | sub generate_isa_check { | ||||
469 | my ($self, @args) = @_; | ||||
470 | $self->{captures} = {}; | ||||
471 | my $code = $self->_generate_isa_check(@args); | ||||
472 | ($code, delete $self->{captures}); | ||||
473 | } | ||||
474 | |||||
475 | # spent 797µs (284+513) within Method::Generate::Accessor::_wrap_attr_exception which was called 20 times, avg 40µs/call:
# 20 times (284µs+513µs) by Method::Generate::Accessor::_generate_coerce at line 447, avg 40µs/call | ||||
476 | 20 | 15µs | my ($self, $name, $step, $arg, $code, $want_return) = @_; | ||
477 | 20 | 85µs | 40 | 297µs | my $prefix = quotify("${step} for "._attr_desc($name, $arg).' failed: '); # spent 163µs making 20 calls to Method::Generate::Accessor::_attr_desc, avg 8µs/call
# spent 134µs making 20 calls to Sub::Quote::quotify, avg 7µs/call |
478 | 20 | 113µs | 60 | 216µs | "do {\n" # spent 216µs making 60 calls to Sub::Quote::quotify, avg 4µs/call |
479 | .' local $Method::Generate::Accessor::CurrentAttribute = {'."\n" | ||||
480 | .' init_arg => '.quotify($arg).",\n" | ||||
481 | .' name => '.quotify($name).",\n" | ||||
482 | .' step => '.quotify($step).",\n" | ||||
483 | ." };\n" | ||||
484 | .($want_return ? ' (my $_return),'."\n" : '') | ||||
485 | .' (my $_error), (my $_old_error = $@);'."\n" | ||||
486 | ." (eval {\n" | ||||
487 | .' ($@ = $_old_error),'."\n" | ||||
488 | .' (' | ||||
489 | .($want_return ? '$_return ='."\n" : '') | ||||
490 | .$code."),\n" | ||||
491 | ." 1\n" | ||||
492 | ." } or\n" | ||||
493 | .' $_error = CORE::ref $@ ? $@ : '.$prefix.'.$@);'."\n" | ||||
494 | .' ($@ = $_old_error),'."\n" | ||||
495 | .' (defined $_error and CORE::die $_error);'."\n" | ||||
496 | .($want_return ? ' $_return;'."\n" : '') | ||||
497 | ."}\n" | ||||
498 | } | ||||
499 | |||||
500 | sub _generate_isa_check { | ||||
501 | my ($self, $name, $value, $check, $init_arg) = @_; | ||||
502 | $self->_wrap_attr_exception( | ||||
503 | $name, | ||||
504 | "isa check", | ||||
505 | $init_arg, | ||||
506 | $self->_generate_call_code($name, 'isa_check', $value, $check) | ||||
507 | ); | ||||
508 | } | ||||
509 | |||||
510 | # spent 1.08ms (518µs+558µs) within Method::Generate::Accessor::_generate_call_code which was called 37 times, avg 29µs/call:
# 20 times (236µs+232µs) by Method::Generate::Accessor::_generate_coerce at line 447, avg 23µs/call
# 17 times (282µs+326µs) by Method::Generate::Accessor::_generate_get_default at line 376, avg 36µs/call | ||||
511 | 37 | 22µs | my ($self, $name, $type, $values, $sub) = @_; | ||
512 | 37 | 78µs | 37 | 15µs | $sub = \&{$sub} if blessed($sub); # coderef if blessed # spent 15µs making 37 calls to Scalar::Util::blessed, avg 405ns/call |
513 | 37 | 171µs | 37 | 128µs | if (my $quoted = quoted_from_sub($sub)) { # spent 128µs making 37 calls to Sub::Quote::quoted_from_sub, avg 3µs/call |
514 | my $local = 1; | ||||
515 | if ($values eq '@_' || $values eq '$_[0]') { | ||||
516 | $local = 0; | ||||
517 | $values = '@_'; | ||||
518 | } | ||||
519 | my $code = $quoted->[1]; | ||||
520 | if (my $captures = $quoted->[2]) { | ||||
521 | my $cap_name = qq{\$${type}_captures_for_}.sanitize_identifier($name); | ||||
522 | $self->{captures}->{$cap_name} = \$captures; | ||||
523 | Sub::Quote::inlinify($code, $values, | ||||
524 | Sub::Quote::capture_unroll($cap_name, $captures, 6), $local); | ||||
525 | } else { | ||||
526 | Sub::Quote::inlinify($code, $values, undef, $local); | ||||
527 | } | ||||
528 | } else { | ||||
529 | 37 | 65µs | 37 | 415µs | my $cap_name = qq{\$${type}_for_}.sanitize_identifier($name); # spent 415µs making 37 calls to Sub::Quote::sanitize_identifier, avg 11µs/call |
530 | 37 | 39µs | $self->{captures}->{$cap_name} = \$sub; | ||
531 | 37 | 16µs | "${cap_name}->(${values})"; | ||
532 | } | ||||
533 | } | ||||
534 | |||||
535 | sub _sanitize_name { sanitize_identifier($_[1]) } | ||||
536 | |||||
537 | # spent 17.9ms (250µs+17.6) within Method::Generate::Accessor::generate_populate_set which was called 49 times, avg 365µs/call:
# 49 times (250µs+17.6ms) by Method::Generate::Constructor::_assign_new at line 223 of Method/Generate/Constructor.pm, avg 365µs/call | ||||
538 | 49 | 12µs | my $self = shift; | ||
539 | 49 | 16µs | $self->{captures} = {}; | ||
540 | 49 | 66µs | 49 | 17.6ms | my $code = $self->_generate_populate_set(@_); # spent 17.6ms making 49 calls to Method::Generate::Accessor::_generate_populate_set, avg 360µs/call |
541 | 49 | 112µs | ($code, delete $self->{captures}); | ||
542 | } | ||||
543 | |||||
544 | # spent 17.6ms (885µs+16.8) within Method::Generate::Accessor::_generate_populate_set which was called 49 times, avg 360µs/call:
# 49 times (885µs+16.8ms) by Method::Generate::Accessor::generate_populate_set at line 540, avg 360µs/call | ||||
545 | 49 | 26µs | my ($self, $me, $name, $spec, $source, $test, $init_arg) = @_; | ||
546 | |||||
547 | 49 | 54µs | 49 | 96µs | my $has_default = $self->has_eager_default($name, $spec); # spent 96µs making 49 calls to Method::Generate::Accessor::has_eager_default, avg 2µs/call |
548 | 49 | 13µs | if (!($has_default || $test)) { | ||
549 | return ''; | ||||
550 | } | ||||
551 | 49 | 5µs | if ($has_default) { | ||
552 | 6 | 9µs | 6 | 62µs | my $get_default = $self->_generate_get_default($me, $name, $spec); # spent 62µs making 6 calls to Method::Generate::Accessor::_generate_get_default, avg 10µs/call |
553 | 6 | 7µs | $source = | ||
554 | $test | ||||
555 | ? "(\n ${test}\n" | ||||
556 | ." ? ${source}\n : " | ||||
557 | .$get_default | ||||
558 | .")" | ||||
559 | : $get_default; | ||||
560 | } | ||||
561 | 49 | 70µs | 12 | 1.01ms | if ($spec->{coerce}) { # spent 1.01ms making 12 calls to Method::Generate::Accessor__WITH__MooX::TypeTiny::Role::GenerateAccessor::_generate_coerce, avg 84µs/call |
562 | $source = $self->_generate_coerce( | ||||
563 | $name, $source, | ||||
564 | $spec->{coerce}, $init_arg | ||||
565 | ) | ||||
566 | } | ||||
567 | 49 | 307µs | 82 | 14.7ms | if ($spec->{isa}) { # spent 14.6ms making 41 calls to Method::Generate::Accessor__WITH__MooX::TypeTiny::Role::GenerateAccessor::_generate_isa_check, avg 356µs/call
# spent 72µs making 41 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 2µs/call |
568 | $source = 'scalar do { my $value = '.$source.";\n" | ||||
569 | .' ('.$self->_generate_isa_check( | ||||
570 | $name, '$value', $spec->{isa}, $init_arg | ||||
571 | )."),\n" | ||||
572 | ." \$value\n" | ||||
573 | ."}\n"; | ||||
574 | } | ||||
575 | 49 | 72µs | 49 | 925µs | my $set = $self->_generate_simple_set($me, $name, $spec, $source); # spent 925µs making 49 calls to Method::Generate::Accessor::_generate_simple_set, avg 19µs/call |
576 | my $trigger = $spec->{trigger} ? $self->_generate_trigger( | ||||
577 | $name, $me, $self->_generate_simple_get($me, $name, $spec), | ||||
578 | $spec->{trigger} | ||||
579 | 49 | 18µs | ) : undef; | ||
580 | 49 | 179µs | if ($has_default) { | ||
581 | "($set)," . ($trigger && $test ? "($test and $trigger)," : '') . "\n"; | ||||
582 | } | ||||
583 | else { | ||||
584 | 43 | 67µs | "($test and ($set)" . ($trigger ? ", ($trigger)" : '') . "),\n"; | ||
585 | } | ||||
586 | } | ||||
587 | |||||
588 | # spent 633µs (345+288) within Method::Generate::Accessor::_generate_core_set which was called 76 times, avg 8µs/call:
# 76 times (345µs+288µs) by Method::Generate::Accessor::_generate_simple_set at line 597, avg 8µs/call | ||||
589 | 76 | 39µs | my ($self, $me, $name, $spec, $value) = @_; | ||
590 | 76 | 114µs | 76 | 288µs | my $name_str = quotify $name; # spent 288µs making 76 calls to Sub::Quote::quotify, avg 4µs/call |
591 | 76 | 228µs | "${me}->{${name_str}} = ${value}"; | ||
592 | } | ||||
593 | |||||
594 | # spent 1.74ms (605µs+1.13) within Method::Generate::Accessor::_generate_simple_set which was called 76 times, avg 23µs/call:
# 49 times (312µs+613µs) by Method::Generate::Accessor::_generate_populate_set at line 575, avg 19µs/call
# 17 times (165µs+310µs) by Method::Generate::Accessor::_generate_use_default at line 367, avg 28µs/call
# 10 times (128µs+207µs) by Method::Generate::Accessor::_generate_set at line 410, avg 34µs/call | ||||
595 | 76 | 68µs | my ($self, $me, $name, $spec, $value) = @_; | ||
596 | 76 | 87µs | 76 | 459µs | my $name_str = quotify $name; # spent 459µs making 76 calls to Sub::Quote::quotify, avg 6µs/call |
597 | 76 | 86µs | 76 | 633µs | my $simple = $self->_generate_core_set($me, $name, $spec, $value); # spent 633µs making 76 calls to Method::Generate::Accessor::_generate_core_set, avg 8µs/call |
598 | |||||
599 | 76 | 226µs | if ($spec->{weak_ref}) { | ||
600 | 4 | 4µs | require Scalar::Util; | ||
601 | 4 | 8µs | 4 | 38µs | my $get = $self->_generate_simple_get($me, $name, $spec); # spent 38µs making 4 calls to Method::Generate::Accessor::_generate_simple_get, avg 10µs/call |
602 | |||||
603 | # Perl < 5.8.3 can't weaken refs to readonly vars | ||||
604 | # (e.g. string constants). This *can* be solved by: | ||||
605 | # | ||||
606 | # &Internals::SvREADONLY($foo, 0); | ||||
607 | # Scalar::Util::weaken($foo); | ||||
608 | # &Internals::SvREADONLY($foo, 1); | ||||
609 | # | ||||
610 | # but requires Internal functions and is just too damn crazy | ||||
611 | # so simply throw a better exception | ||||
612 | 4 | 4µs | my $weak_simple = _CAN_WEAKEN_READONLY | ||
613 | ? "do { Scalar::Util::weaken(${simple}); no warnings 'void'; $get }" | ||||
614 | : <<"EOC" | ||||
615 | ( eval { Scalar::Util::weaken($simple); 1 } | ||||
616 | ? do { no warnings 'void'; $get } | ||||
617 | : do { | ||||
618 | if( \$@ =~ /Modification of a read-only value attempted/) { | ||||
619 | require Carp; | ||||
620 | Carp::croak( sprintf ( | ||||
621 | 'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3', | ||||
622 | $name_str, | ||||
623 | ) ); | ||||
624 | } else { | ||||
625 | die \$@; | ||||
626 | } | ||||
627 | } | ||||
628 | ) | ||||
629 | EOC | ||||
630 | } else { | ||||
631 | 72 | 19µs | $simple; | ||
632 | } | ||||
633 | } | ||||
634 | |||||
635 | # spent 770µs (32+738) within Method::Generate::Accessor::_generate_getset which was called 3 times, avg 257µs/call:
# 3 times (32µs+738µs) by Method::Generate::Accessor::generate_method at line 159, avg 257µs/call | ||||
636 | 3 | 1µs | my ($self, $name, $spec) = @_; | ||
637 | 3 | 27µs | 6 | 738µs | q{(@_ > 1}."\n ? ".$self->_generate_set($name, $spec) # spent 704µs making 3 calls to Method::Generate::Accessor::_generate_set, avg 235µs/call
# spent 34µs making 3 calls to Method::Generate::Accessor::_generate_get, avg 11µs/call |
638 | ."\n : ".$self->_generate_get($name, $spec)."\n )"; | ||||
639 | } | ||||
640 | |||||
641 | # spent 15.6ms (218µs+15.4) within Method::Generate::Accessor::_generate_asserter which was called 14 times, avg 1.12ms/call:
# 14 times (218µs+15.4ms) by Method::Generate::Accessor::generate_method at line 250, avg 1.12ms/call | ||||
642 | 14 | 9µs | my ($self, $name, $spec) = @_; | ||
643 | 14 | 19µs | 14 | 83µs | my $name_str = quotify($name); # spent 83µs making 14 calls to Sub::Quote::quotify, avg 6µs/call |
644 | 14 | 125µs | 28 | 15.3ms | "do {\n" # spent 15.2ms making 14 calls to Method::Generate::Accessor::_generate_get, avg 1.09ms/call
# spent 127µs making 14 calls to Method::Generate::Accessor::_generate_simple_has, avg 9µs/call |
645 | ." my \$val = ".$self->_generate_get($name, $spec).";\n" | ||||
646 | ." ".$self->_generate_simple_has('$_[0]', $name, $spec)."\n" | ||||
647 | ." or Carp::croak(q{Attempted to access '}.${name_str}.q{' but it is not set});\n" | ||||
648 | ." \$val;\n" | ||||
649 | ."}\n"; | ||||
650 | } | ||||
651 | # spent 159µs within Method::Generate::Accessor::_generate_delegation which was called 41 times, avg 4µs/call:
# 41 times (159µs+0s) by Method::Generate::Accessor::generate_method at line 238, avg 4µs/call | ||||
652 | 41 | 21µs | my ($self, $asserter, $target, $args) = @_; | ||
653 | 41 | 23µs | my $arg_string = do { | ||
654 | 41 | 13µs | if (@$args) { | ||
655 | # I could, I reckon, linearise out non-refs here using quotify | ||||
656 | # plus something to check for numbers but I'm unsure if it's worth it | ||||
657 | $self->{captures}{'@curries'} = $args; | ||||
658 | '@curries, @_'; | ||||
659 | } else { | ||||
660 | 41 | 18µs | '@_'; | ||
661 | } | ||||
662 | }; | ||||
663 | 41 | 109µs | "shift->${asserter}->${target}(${arg_string});"; | ||
664 | } | ||||
665 | |||||
666 | sub _generate_xs { | ||||
667 | my ($self, $type, $into, $name, $slot) = @_; | ||||
668 | Class::XSAccessor->import( | ||||
669 | class => $into, | ||||
670 | $type => { $name => $slot }, | ||||
671 | replace => 1, | ||||
672 | ); | ||||
673 | $into->can($name); | ||||
674 | } | ||||
675 | |||||
676 | 5 | 10µs | # spent 10µs within Method::Generate::Accessor::default_construction_string which was called 5 times, avg 2µs/call:
# 5 times (10µs+0s) by Method::Generate::Constructor::_build_construction_string at line 68 of Method/Generate/Constructor.pm, avg 2µs/call | ||
677 | |||||
678 | # spent 16.6ms (733µs+15.9) within Method::Generate::Accessor::_validate_codulatable which was called 88 times, avg 188µs/call:
# 59 times (614µs+15.8ms) by Method::Generate::Accessor::generate_method at line 103, avg 279µs/call
# 17 times (67µs+5µs) by Method::Generate::Accessor::generate_method at line 106, avg 4µs/call
# 12 times (52µs+3µs) by Method::Generate::Accessor::generate_method at line 119, avg 5µs/call | ||||
679 | 88 | 42µs | my ($self, $setting, $value, $into, $appended) = @_; | ||
680 | |||||
681 | 88 | 17µs | my $error; | ||
682 | |||||
683 | 88 | 345µs | 88 | 87µs | if (blessed $value) { # spent 87µs making 88 calls to Scalar::Util::blessed, avg 989ns/call |
684 | 47 | 10µs | local $@; | ||
685 | 2 | 203µs | 2 | 102µs | # spent 61µs (20+41) within Method::Generate::Accessor::BEGIN@685 which was called:
# once (20µs+41µs) by Moo::_accessor_maker_for at line 685 # spent 61µs making 1 call to Method::Generate::Accessor::BEGIN@685
# spent 41µs making 1 call to warnings::unimport |
686 | 141 | 372µs | 47 | 15.8ms | eval { \&$value; 1 } # spent 15.8ms making 47 calls to Type::Tiny::__ANON__[Type/Tiny.pm:89], avg 335µs/call |
687 | and return 1; | ||||
688 | $error = "could not be converted to a coderef: $@"; | ||||
689 | } | ||||
690 | elsif (ref $value eq 'CODE') { | ||||
691 | return 1; | ||||
692 | } | ||||
693 | else { | ||||
694 | $error = 'is not a coderef or code-convertible object'; | ||||
695 | } | ||||
696 | |||||
697 | croak "Invalid $setting '" | ||||
698 | . ($INC{'overload.pm'} ? overload::StrVal($value) : $value) | ||||
699 | . "' for $into " . $error | ||||
700 | . ($appended ? " $appended" : ''); | ||||
701 | } | ||||
702 | |||||
703 | 1 | 5µs | 1; | ||
# spent 22µs within Method::Generate::Accessor::CORE:subst which was called 49 times, avg 449ns/call:
# 49 times (22µs+0s) by Method::Generate::Accessor::generate_method at line 53, avg 449ns/call |