Filename | /usr/share/perl5/Method/Generate/Constructor.pm |
Statements | Executed 1937 statements in 4.46ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.22ms | 1.59ms | BEGIN@4 | Method::Generate::Constructor::
10 | 1 | 1 | 854µs | 3.48ms | _assign_new | Method::Generate::Constructor::
2 | 1 | 1 | 450µs | 789µs | buildall_generator | Method::Generate::Constructor::
10 | 1 | 1 | 449µs | 5.92ms | generate_method | Method::Generate::Constructor::
26 | 4 | 3 | 432µs | 456µs | register_attribute_specs | Method::Generate::Constructor::
10 | 1 | 1 | 330µs | 357µs | _check_required | Method::Generate::Constructor::
76 | 1 | 1 | 185µs | 185µs | _cap_call | Method::Generate::Constructor::
10 | 1 | 1 | 82µs | 11.4ms | __ANON__[:76] | Method::Generate::Constructor::
10 | 1 | 1 | 79µs | 343µs | install_delayed | Method::Generate::Constructor::
10 | 1 | 1 | 65µs | 87µs | _build_construction_string | Method::Generate::Constructor::
10 | 1 | 1 | 64µs | 87µs | _handle_subconstructor | Method::Generate::Constructor::
30 | 3 | 1 | 58µs | 58µs | CORE:sort (opcode) | Method::Generate::Constructor::
10 | 1 | 1 | 41µs | 128µs | construction_string | Method::Generate::Constructor::
82 | 1 | 1 | 24µs | 24µs | CORE:subst (opcode) | Method::Generate::Constructor::
20 | 2 | 1 | 20µs | 20µs | accessor_generator | Method::Generate::Constructor::
1 | 1 | 1 | 20µs | 73µs | BEGIN@3 | Method::Generate::Constructor::
1 | 1 | 1 | 12µs | 74µs | BEGIN@8 | Method::Generate::Constructor::
1 | 1 | 1 | 11µs | 75µs | BEGIN@5 | Method::Generate::Constructor::
6 | 1 | 1 | 10µs | 10µs | _generate_args | Method::Generate::Constructor::
1 | 1 | 1 | 10µs | 339µs | BEGIN@197 | Method::Generate::Constructor::
1 | 1 | 1 | 10µs | 46µs | BEGIN@6 | Method::Generate::Constructor::
1 | 1 | 1 | 8µs | 32µs | BEGIN@7 | Method::Generate::Constructor::
4 | 1 | 1 | 7µs | 7µs | _generate_args_via_buildargs | Method::Generate::Constructor::
1 | 1 | 1 | 6µs | 45µs | __ANON__[:197] | Method::Generate::Constructor::
0 | 0 | 0 | 0s | 0s | all_attribute_specs | Method::Generate::Constructor::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Method::Generate::Constructor; | ||||
2 | |||||
3 | 3 | 41µs | 3 | 127µs | # spent 73µs (20+54) within Method::Generate::Constructor::BEGIN@3 which was called:
# once (20µs+54µs) by Moo::_constructor_maker_for at line 3 # spent 73µs making 1 call to Method::Generate::Constructor::BEGIN@3
# spent 35µs making 1 call to strictures::import
# spent 18µs making 1 call to strictures::VERSION |
4 | 2 | 131µs | 2 | 1.62ms | # spent 1.59ms (1.22+362µs) within Method::Generate::Constructor::BEGIN@4 which was called:
# once (1.22ms+362µs) by Moo::_constructor_maker_for at line 4 # spent 1.59ms making 1 call to Method::Generate::Constructor::BEGIN@4
# spent 38µs making 1 call to Exporter::import |
5 | 2 | 33µs | 2 | 140µs | # spent 75µs (11+65) within Method::Generate::Constructor::BEGIN@5 which was called:
# once (11µs+65µs) by Moo::_constructor_maker_for at line 5 # spent 75µs making 1 call to Method::Generate::Constructor::BEGIN@5
# spent 65µs making 1 call to base::import |
6 | 2 | 32µs | 2 | 82µs | # spent 46µs (10+36) within Method::Generate::Constructor::BEGIN@6 which was called:
# once (10µs+36µs) by Moo::_constructor_maker_for at line 6 # spent 46µs making 1 call to Method::Generate::Constructor::BEGIN@6
# spent 36µs making 1 call to Exporter::import |
7 | 2 | 31µs | 2 | 55µs | # spent 32µs (8+24) within Method::Generate::Constructor::BEGIN@7 which was called:
# once (8µs+24µs) by Moo::_constructor_maker_for at line 7 # spent 32µs making 1 call to Method::Generate::Constructor::BEGIN@7
# spent 24µs making 1 call to Exporter::import |
8 | 2 | 1.16ms | 2 | 135µs | # spent 74µs (12+62) within Method::Generate::Constructor::BEGIN@8 which was called:
# once (12µs+62µs) by Moo::_constructor_maker_for at line 8 # spent 74µs making 1 call to Method::Generate::Constructor::BEGIN@8
# spent 62µs making 1 call to Exporter::import |
9 | |||||
10 | # spent 456µs (432+24) within Method::Generate::Constructor::register_attribute_specs which was called 26 times, avg 18µs/call:
# 10 times (315µs+19µs) by Moo::Role::_handle_constructor at line 351 of Moo/Role.pm, avg 33µs/call
# 10 times (44µs+0s) by Moo::_constructor_maker_for at line 199 of Moo.pm, avg 4µs/call
# 5 times (41µs+3µs) by Moo::has at line 54 of Moo.pm, avg 9µs/call
# once (31µs+2µs) by Moo::_constructor_maker_for at line 198 | ||||
11 | 26 | 33µs | my ($self, @new_specs) = @_; | ||
12 | 26 | 20µs | my $specs = $self->{attribute_specs}||={}; | ||
13 | 26 | 94µs | while (my ($name, $new_spec) = splice @new_specs, 0, 2) { | ||
14 | 82 | 164µs | 82 | 24µs | if ($name =~ s/^\+//) { # spent 24µs making 82 calls to Method::Generate::Constructor::CORE:subst, avg 294ns/call |
15 | die "has '+${name}' given but no ${name} attribute already exists" | ||||
16 | unless my $old_spec = $specs->{$name}; | ||||
17 | foreach my $key (keys %$old_spec) { | ||||
18 | if (!exists $new_spec->{$key}) { | ||||
19 | $new_spec->{$key} = $old_spec->{$key} | ||||
20 | unless $key eq 'handles'; | ||||
21 | } | ||||
22 | elsif ($key eq 'moosify') { | ||||
23 | $new_spec->{$key} = [ | ||||
24 | map { ref $_ eq 'ARRAY' ? @$_ : $_ } | ||||
25 | ($old_spec->{$key}, $new_spec->{$key}) | ||||
26 | ]; | ||||
27 | } | ||||
28 | } | ||||
29 | } | ||||
30 | 82 | 23µs | if (exists $new_spec->{init_arg} && !defined $new_spec->{init_arg} | ||
31 | && $new_spec->{required}) { | ||||
32 | die "${name} attribute can't be required with init_arg => undef"; | ||||
33 | } | ||||
34 | 82 | 48µs | $new_spec->{index} = scalar keys %$specs | ||
35 | unless defined $new_spec->{index}; | ||||
36 | 82 | 42µs | $specs->{$name} = $new_spec; | ||
37 | } | ||||
38 | 26 | 59µs | $self; | ||
39 | } | ||||
40 | |||||
41 | sub all_attribute_specs { | ||||
42 | $_[0]->{attribute_specs} | ||||
43 | } | ||||
44 | |||||
45 | # spent 20µs within Method::Generate::Constructor::accessor_generator which was called 20 times, avg 995ns/call:
# 10 times (12µs+0s) by Method::Generate::Constructor::_build_construction_string at line 63, avg 1µs/call
# 10 times (8µs+0s) by Method::Generate::Constructor::_assign_new at line 163, avg 770ns/call | ||||
46 | 20 | 49µs | $_[0]->{accessor_generator} | ||
47 | } | ||||
48 | |||||
49 | # spent 128µs (41+87) within Method::Generate::Constructor::construction_string which was called 10 times, avg 13µs/call:
# 10 times (41µs+87µs) by Method::Generate::Constructor::generate_method at line 96, avg 13µs/call | ||||
50 | 10 | 4µs | my ($self) = @_; | ||
51 | 10 | 34µs | 10 | 87µs | $self->{construction_string} # spent 87µs making 10 calls to Method::Generate::Constructor::_build_construction_string, avg 9µs/call |
52 | ||= $self->_build_construction_string; | ||||
53 | } | ||||
54 | |||||
55 | # spent 789µs (450+339) within Method::Generate::Constructor::buildall_generator which was called 2 times, avg 395µs/call:
# 2 times (450µs+339µs) by Method::Generate::Constructor::generate_method at line 98, avg 395µs/call | ||||
56 | 2 | 92µs | require Method::Generate::BuildAll; | ||
57 | 2 | 11µs | 2 | 27µs | Method::Generate::BuildAll->new; # spent 27µs making 2 calls to Moo::Object::new, avg 14µs/call |
58 | } | ||||
59 | |||||
60 | # spent 87µs (65+22) within Method::Generate::Constructor::_build_construction_string which was called 10 times, avg 9µs/call:
# 10 times (65µs+22µs) by Method::Generate::Constructor::construction_string at line 51, avg 9µs/call | ||||
61 | 10 | 2µs | my ($self) = @_; | ||
62 | 10 | 4µs | my $builder = $self->{construction_builder}; | ||
63 | 10 | 44µs | 20 | 22µs | $builder ? $self->$builder # spent 12µs making 10 calls to Method::Generate::Constructor::accessor_generator, avg 1µs/call
# spent 10µs making 10 calls to Method::Generate::Accessor::default_construction_string, avg 1µs/call |
64 | : 'bless(' | ||||
65 | .$self->accessor_generator->default_construction_string | ||||
66 | .', $class);' | ||||
67 | } | ||||
68 | |||||
69 | # spent 343µs (79+264) within Method::Generate::Constructor::install_delayed which was called 10 times, avg 34µs/call:
# 10 times (79µs+264µs) by Moo::_constructor_maker_for at line 199 of Moo.pm, avg 34µs/call | ||||
70 | 10 | 4µs | my ($self) = @_; | ||
71 | 10 | 8µs | my $package = $self->{package}; | ||
72 | # spent 11.4ms (82µs+11.3) within Method::Generate::Constructor::__ANON__[/usr/share/perl5/Method/Generate/Constructor.pm:76] which was called 10 times, avg 1.14ms/call:
# 10 times (82µs+11.3ms) by Sub::Defer::undefer_sub at line 22 of Sub/Defer.pm, avg 1.14ms/call | ||||
73 | 10 | 64µs | 20 | 11.3ms | unquote_sub $self->generate_method( # spent 5.92ms making 10 calls to Method::Generate::Constructor::generate_method, avg 592µs/call
# spent 5.36ms making 10 calls to Sub::Quote::unquote_sub, avg 536µs/call |
74 | $package, 'new', $self->{attribute_specs}, { no_install => 1 } | ||||
75 | ) | ||||
76 | 10 | 48µs | 10 | 264µs | }; # spent 264µs making 10 calls to Sub::Defer::defer_sub, avg 26µs/call |
77 | 10 | 19µs | $self; | ||
78 | } | ||||
79 | |||||
80 | # spent 5.92ms (449µs+5.47) within Method::Generate::Constructor::generate_method which was called 10 times, avg 592µs/call:
# 10 times (449µs+5.47ms) by Method::Generate::Constructor::__ANON__[/usr/share/perl5/Method/Generate/Constructor.pm:76] at line 73, avg 592µs/call | ||||
81 | 10 | 5µs | my ($self, $into, $name, $spec, $quote_opts) = @_; | ||
82 | 10 | 52µs | foreach my $no_init (grep !exists($spec->{$_}{init_arg}), keys %$spec) { | ||
83 | 76 | 38µs | $spec->{$no_init}{init_arg} = $no_init; | ||
84 | } | ||||
85 | 10 | 10µs | local $self->{captures} = {}; | ||
86 | 10 | 3µs | my $body = ' my $class = shift;'."\n" | ||
87 | .' $class = ref($class) if ref($class);'."\n"; | ||||
88 | 10 | 16µs | 10 | 87µs | $body .= $self->_handle_subconstructor($into, $name); # spent 87µs making 10 calls to Method::Generate::Constructor::_handle_subconstructor, avg 9µs/call |
89 | 10 | 63µs | 10 | 33µs | my $into_buildargs = $into->can('BUILDARGS'); # spent 33µs making 10 calls to UNIVERSAL::can, avg 3µs/call |
90 | 10 | 19µs | 4 | 7µs | if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) { # spent 7µs making 4 calls to Method::Generate::Constructor::_generate_args_via_buildargs, avg 2µs/call |
91 | $body .= $self->_generate_args_via_buildargs; | ||||
92 | } else { | ||||
93 | 6 | 10µs | 6 | 10µs | $body .= $self->_generate_args; # spent 10µs making 6 calls to Method::Generate::Constructor::_generate_args, avg 2µs/call |
94 | } | ||||
95 | 10 | 16µs | 10 | 357µs | $body .= $self->_check_required($spec); # spent 357µs making 10 calls to Method::Generate::Constructor::_check_required, avg 36µs/call |
96 | 10 | 20µs | 10 | 128µs | $body .= ' my $new = '.$self->construction_string.";\n"; # spent 128µs making 10 calls to Method::Generate::Constructor::construction_string, avg 13µs/call |
97 | 10 | 27µs | 10 | 3.48ms | $body .= $self->_assign_new($spec); # spent 3.48ms making 10 calls to Method::Generate::Constructor::_assign_new, avg 348µs/call |
98 | 10 | 83µs | 14 | 895µs | if ($into->can('BUILD')) { # spent 789µs making 2 calls to Method::Generate::Constructor::buildall_generator, avg 395µs/call
# spent 62µs making 2 calls to Method::Generate::BuildAll::buildall_body_for, avg 31µs/call
# spent 44µs making 10 calls to UNIVERSAL::can, avg 4µs/call |
99 | $body .= $self->buildall_generator->buildall_body_for( | ||||
100 | $into, '$new', '$args' | ||||
101 | ); | ||||
102 | } | ||||
103 | 10 | 4µs | $body .= ' return $new;'."\n"; | ||
104 | 10 | 52µs | 10 | 29µs | if ($into->can('DEMOLISH')) { # spent 29µs making 10 calls to UNIVERSAL::can, avg 3µs/call |
105 | require Method::Generate::DemolishAll; | ||||
106 | Method::Generate::DemolishAll->new->generate_method($into); | ||||
107 | } | ||||
108 | quote_sub | ||||
109 | 10 | 58µs | 10 | 440µs | "${into}::${name}" => $body, # spent 440µs making 10 calls to Sub::Quote::quote_sub, avg 44µs/call |
110 | $self->{captures}, $quote_opts||{} | ||||
111 | ; | ||||
112 | } | ||||
113 | |||||
114 | # spent 87µs (64+23) within Method::Generate::Constructor::_handle_subconstructor which was called 10 times, avg 9µs/call:
# 10 times (64µs+23µs) by Method::Generate::Constructor::generate_method at line 88, avg 9µs/call | ||||
115 | 10 | 4µs | my ($self, $into, $name) = @_; | ||
116 | 10 | 98µs | 10 | 23µs | if (my $gen = $self->{subconstructor_handler}) { # spent 23µs making 10 calls to B::perlstring, avg 2µs/call |
117 | ' if ($class ne '.perlstring($into).') {'."\n". | ||||
118 | $gen. | ||||
119 | ' }'."\n"; | ||||
120 | } else { | ||||
121 | '' | ||||
122 | } | ||||
123 | } | ||||
124 | |||||
125 | # spent 185µs within Method::Generate::Constructor::_cap_call which was called 76 times, avg 2µs/call:
# 76 times (185µs+0s) by Method::Generate::Constructor::_assign_new at line 176, avg 2µs/call | ||||
126 | 76 | 27µs | my ($self, $code, $captures) = @_; | ||
127 | 76 | 80µs | @{$self->{captures}}{keys %$captures} = values %$captures if $captures; | ||
128 | 76 | 162µs | $code; | ||
129 | } | ||||
130 | |||||
131 | # spent 7µs within Method::Generate::Constructor::_generate_args_via_buildargs which was called 4 times, avg 2µs/call:
# 4 times (7µs+0s) by Method::Generate::Constructor::generate_method at line 90, avg 2µs/call | ||||
132 | 4 | 2µs | my ($self) = @_; | ||
133 | 4 | 21µs | q{ my $args = $class->BUILDARGS(@_);}."\n" | ||
134 | .q{ die "BUILDARGS did not return a hashref" unless ref($args) eq 'HASH';} | ||||
135 | ."\n"; | ||||
136 | } | ||||
137 | |||||
138 | # inlined from Moo::Object - update that first. | ||||
139 | # spent 10µs within Method::Generate::Constructor::_generate_args which was called 6 times, avg 2µs/call:
# 6 times (10µs+0s) by Method::Generate::Constructor::generate_method at line 93, avg 2µs/call | ||||
140 | 6 | 2µs | my ($self) = @_; | ||
141 | 6 | 19µs | return <<'_EOA'; | ||
142 | my $args; | ||||
143 | if ( scalar @_ == 1 ) { | ||||
144 | unless ( defined $_[0] && ref $_[0] eq 'HASH' ) { | ||||
145 | die "Single parameters to new() must be a HASH ref" | ||||
146 | ." data => ". $_[0] ."\n"; | ||||
147 | } | ||||
148 | $args = { %{ $_[0] } }; | ||||
149 | } | ||||
150 | elsif ( @_ % 2 ) { | ||||
151 | die "The new() method for $class expects a hash reference or a key/value list." | ||||
152 | . " You passed an odd number of arguments\n"; | ||||
153 | } | ||||
154 | else { | ||||
155 | $args = {@_}; | ||||
156 | } | ||||
157 | _EOA | ||||
158 | |||||
159 | } | ||||
160 | |||||
161 | # spent 3.48ms (854µs+2.63) within Method::Generate::Constructor::_assign_new which was called 10 times, avg 348µs/call:
# 10 times (854µs+2.63ms) by Method::Generate::Constructor::generate_method at line 97, avg 348µs/call | ||||
162 | 10 | 4µs | my ($self, $spec) = @_; | ||
163 | 10 | 9µs | 10 | 8µs | my $ag = $self->accessor_generator; # spent 8µs making 10 calls to Method::Generate::Constructor::accessor_generator, avg 770ns/call |
164 | 10 | 1µs | my %test; | ||
165 | 10 | 52µs | 10 | 17µs | NAME: foreach my $name (sort keys %$spec) { # spent 17µs making 10 calls to Method::Generate::Constructor::CORE:sort, avg 2µs/call |
166 | 82 | 17µs | my $attr_spec = $spec->{$name}; | ||
167 | 82 | 24µs | 6 | 8µs | next NAME unless defined($attr_spec->{init_arg}) # spent 8µs making 6 calls to Method::Generate::Accessor::has_eager_default, avg 1µs/call |
168 | or $ag->has_eager_default($name, $attr_spec); | ||||
169 | 76 | 46µs | $test{$name} = $attr_spec->{init_arg}; | ||
170 | } | ||||
171 | 76 | 234µs | 76 | 77µs | join '', map { # spent 77µs making 76 calls to B::perlstring, avg 1µs/call |
172 | 10 | 150µs | 10 | 13µs | my $arg_key = perlstring($test{$_}); # spent 13µs making 10 calls to Method::Generate::Constructor::CORE:sort, avg 1µs/call |
173 | 76 | 34µs | my $test = "exists \$args->{$arg_key}"; | ||
174 | 76 | 21µs | my $source = "\$args->{$arg_key}"; | ||
175 | 76 | 22µs | my $attr_spec = $spec->{$_}; | ||
176 | 76 | 179µs | 152 | 2.51ms | $self->_cap_call($ag->generate_populate_set( # spent 2.32ms making 76 calls to Method::Generate::Accessor::generate_populate_set, avg 31µs/call
# spent 185µs making 76 calls to Method::Generate::Constructor::_cap_call, avg 2µs/call |
177 | '$new', $_, $attr_spec, $source, $test, $test{$_}, | ||||
178 | )); | ||||
179 | } sort keys %test; | ||||
180 | } | ||||
181 | |||||
182 | # spent 357µs (330+28) within Method::Generate::Constructor::_check_required which was called 10 times, avg 36µs/call:
# 10 times (330µs+28µs) by Method::Generate::Constructor::generate_method at line 95, avg 36µs/call | ||||
183 | 10 | 3µs | my ($self, $spec) = @_; | ||
184 | my @required_init = | ||||
185 | map $spec->{$_}{init_arg}, | ||||
186 | grep { | ||||
187 | 92 | 266µs | 10 | 28µs | my %s = %{$spec->{$_}}; # ignore required if default or builder set # spent 28µs making 10 calls to Method::Generate::Constructor::CORE:sort, avg 3µs/call |
188 | 82 | 58µs | $s{required} and not($s{builder} or $s{default}) | ||
189 | } sort keys %$spec; | ||||
190 | 10 | 10µs | return '' unless @required_init; | ||
191 | 8 | 36µs | ' if (my @missing = grep !exists $args->{$_}, qw(' | ||
192 | .join(' ',@required_init).')) {'."\n" | ||||
193 | .q{ die "Missing required arguments: ".join(', ', sort @missing);}."\n" | ||||
194 | ." }\n"; | ||||
195 | } | ||||
196 | |||||
197 | 4 | 81µs | 3 | 708µs | # spent 339µs (10+330) within Method::Generate::Constructor::BEGIN@197 which was called:
# once (10µs+330µs) by Moo::_constructor_maker_for at line 197
# spent 45µs (6+39) within Method::Generate::Constructor::__ANON__[/usr/share/perl5/Method/Generate/Constructor.pm:197] which was called:
# once (6µs+39µs) by import::into at line 34 of Import/Into.pm # spent 339µs making 1 call to Method::Generate::Constructor::BEGIN@197
# spent 330µs making 1 call to Moo::import
# spent 39µs making 1 call to strictures::import |
198 | 1 | 16µs | 2 | 33µs | Moo->_constructor_maker_for(__PACKAGE__)->register_attribute_specs( # spent 33µs making 1 call to Method::Generate::Constructor::register_attribute_specs
# spent 7.03ms making 1 call to Moo::_constructor_maker_for, recursion: max depth 1, sum of overlapping time 7.03ms |
199 | attribute_specs => { | ||||
200 | is => 'ro', | ||||
201 | reader => 'all_attribute_specs', | ||||
202 | }, | ||||
203 | accessor_generator => { is => 'ro' }, | ||||
204 | construction_string => { is => 'lazy' }, | ||||
205 | construction_builder => { is => 'lazy' }, | ||||
206 | subconstructor_handler => { is => 'ro' }, | ||||
207 | package => { is => 'ro' }, | ||||
208 | ); | ||||
209 | |||||
210 | 1 | 6µs | 1; | ||
# spent 58µs within Method::Generate::Constructor::CORE:sort which was called 30 times, avg 2µs/call:
# 10 times (28µs+0s) by Method::Generate::Constructor::_check_required at line 187, avg 3µs/call
# 10 times (17µs+0s) by Method::Generate::Constructor::_assign_new at line 165, avg 2µs/call
# 10 times (13µs+0s) by Method::Generate::Constructor::_assign_new at line 172, avg 1µs/call | |||||
# spent 24µs within Method::Generate::Constructor::CORE:subst which was called 82 times, avg 294ns/call:
# 82 times (24µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 14, avg 294ns/call |