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

Filename/usr/local/share/perl/5.18.2/Method/Generate/Constructor.pm
StatementsExecuted 565 statements in 3.67ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.84ms6.94msMethod::Generate::Constructor::::BEGIN@4Method::Generate::Constructor::BEGIN@4
211344µs9.32msMethod::Generate::Constructor::::_assign_newMethod::Generate::Constructor::_assign_new
1232205µs386µsMethod::Generate::Constructor::::register_attribute_specsMethod::Generate::Constructor::register_attribute_specs
211149µs9.97msMethod::Generate::Constructor::::generate_methodMethod::Generate::Constructor::generate_method
1421100µs213µsMethod::Generate::Constructor::::assert_constructorMethod::Generate::Constructor::assert_constructor
21196µs113µsMethod::Generate::Constructor::::_check_requiredMethod::Generate::Constructor::_check_required
21188µs251µsMethod::Generate::Constructor::::install_delayedMethod::Generate::Constructor::install_delayed
21181µs12.3msMethod::Generate::Constructor::::__ANON__[:102]Method::Generate::Constructor::__ANON__[:102]
141177µs113µsMethod::Generate::Constructor::::current_constructorMethod::Generate::Constructor::current_constructor
151167µs67µsMethod::Generate::Constructor::::_cap_callMethod::Generate::Constructor::_cap_call
63126µs26µsMethod::Generate::Constructor::::CORE:sortMethod::Generate::Constructor::CORE:sort (opcode)
21121µs28µsMethod::Generate::Constructor::::_build_construction_stringMethod::Generate::Constructor::_build_construction_string
21119µs51µsMethod::Generate::Constructor::::_handle_subconstructorMethod::Generate::Constructor::_handle_subconstructor
11115µs57µsMethod::Generate::Constructor::::BEGIN@3Method::Generate::Constructor::BEGIN@3
21114µs43µsMethod::Generate::Constructor::::construction_stringMethod::Generate::Constructor::construction_string
151111µs11µsMethod::Generate::Constructor::::CORE:substMethod::Generate::Constructor::CORE:subst (opcode)
11111µs52µsMethod::Generate::Constructor::::BEGIN@5Method::Generate::Constructor::BEGIN@5
11110µs320µsMethod::Generate::Constructor::::BEGIN@8Method::Generate::Constructor::BEGIN@8
11110µs44µsMethod::Generate::Constructor::::BEGIN@6Method::Generate::Constructor::BEGIN@6
1119µs37µsMethod::Generate::Constructor::::BEGIN@7Method::Generate::Constructor::BEGIN@7
4218µs8µsMethod::Generate::Constructor::::accessor_generatorMethod::Generate::Constructor::accessor_generator
1114µs4µsMethod::Generate::Constructor::::_generate_args_via_buildargsMethod::Generate::Constructor::_generate_args_via_buildargs
1112µs2µsMethod::Generate::Constructor::::_generate_argsMethod::Generate::Constructor::_generate_args
0000s0sMethod::Generate::Constructor::::all_attribute_specsMethod::Generate::Constructor::all_attribute_specs
0000s0sMethod::Generate::Constructor::::buildall_generatorMethod::Generate::Constructor::buildall_generator
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::Constructor;
2
3240µs299µs
# spent 57µs (15+42) within Method::Generate::Constructor::BEGIN@3 which was called: # once (15µs+42µs) by Moo::_constructor_maker_for at line 3
use Moo::_strictures;
# spent 57µs making 1 call to Method::Generate::Constructor::BEGIN@3 # spent 42µs making 1 call to Moo::_strictures::import
42142µs27.01ms
# spent 6.94ms (1.84+5.10) within Method::Generate::Constructor::BEGIN@4 which was called: # once (1.84ms+5.10ms) by Moo::_constructor_maker_for at line 4
use Sub::Quote qw(quote_sub unquote_sub quotify);
# spent 6.94ms making 1 call to Method::Generate::Constructor::BEGIN@4 # spent 68µs making 1 call to Exporter::import
5250µs294µs
# spent 52µs (11+41) within Method::Generate::Constructor::BEGIN@5 which was called: # once (11µs+41µs) by Moo::_constructor_maker_for at line 5
use Sub::Defer;
# spent 52µs making 1 call to Method::Generate::Constructor::BEGIN@5 # spent 41µs making 1 call to Exporter::import
6234µs278µs
# spent 44µs (10+34) within Method::Generate::Constructor::BEGIN@6 which was called: # once (10µs+34µs) by Moo::_constructor_maker_for at line 6
use Moo::_Utils qw(_getstash _getglob);
# spent 44µs making 1 call to Method::Generate::Constructor::BEGIN@6 # spent 34µs making 1 call to Exporter::import
7231µs265µs
# spent 37µs (9+28) within Method::Generate::Constructor::BEGIN@7 which was called: # once (9µs+28µs) by Moo::_constructor_maker_for at line 7
use Scalar::Util qw(weaken);
# spent 37µs making 1 call to Method::Generate::Constructor::BEGIN@7 # spent 28µs making 1 call to Exporter::import
821.99ms2631µs
# spent 320µs (10+311) within Method::Generate::Constructor::BEGIN@8 which was called: # once (10µs+311µs) by Moo::_constructor_maker_for at line 8
use Moo;
# spent 320µs making 1 call to Method::Generate::Constructor::BEGIN@8 # spent 311µs making 1 call to Moo::import
9
10
# spent 386µs (205+181) within Method::Generate::Constructor::register_attribute_specs which was called 12 times, avg 32µs/call: # 9 times (120µs+126µs) by Moo::has at line 55 of Moo.pm, avg 27µs/call # 2 times (23µs+32µs) by Moo::_constructor_maker_for at line 212 of Moo.pm, avg 27µs/call # once (62µs+24µs) by Moo::_constructor_maker_for at line 244
sub register_attribute_specs {
111216µs my ($self, @new_specs) = @_;
121217µs12170µs $self->assert_constructor;
# spent 170µs making 12 calls to Method::Generate::Constructor::assert_constructor, avg 14µs/call
13128µs my $specs = $self->{attribute_specs}||={};
141241µs while (my ($name, $new_spec) = splice @new_specs, 0, 2) {
151560µs1511µs if ($name =~ s/^\+//) {
# spent 11µs making 15 calls to Method::Generate::Constructor::CORE:subst, avg 753ns/call
16 die "has '+${name}' given but no ${name} attribute already exists"
17 unless my $old_spec = $specs->{$name};
18 foreach my $key (keys %$old_spec) {
19 if (!exists $new_spec->{$key}) {
20 $new_spec->{$key} = $old_spec->{$key}
21 unless $key eq 'handles';
22 }
23 elsif ($key eq 'moosify') {
24 $new_spec->{$key} = [
25 map { ref $_ eq 'ARRAY' ? @$_ : $_ }
26 ($old_spec->{$key}, $new_spec->{$key})
27 ];
28 }
29 }
30 }
31156µs if ($new_spec->{required}
32 && !(
33 $self->accessor_generator->has_default($name, $new_spec)
34 || !exists $new_spec->{init_arg}
35 || defined $new_spec->{init_arg}
36 )
37 ) {
38 die "You cannot have a required attribute (${name})"
39 . " without a default, builder, or an init_arg";
40 }
411516µs $new_spec->{index} = scalar keys %$specs
42 unless defined $new_spec->{index};
431515µs $specs->{$name} = $new_spec;
44 }
451238µs $self;
46}
47
48sub all_attribute_specs {
49 $_[0]->{attribute_specs}
50}
51
52
# spent 8µs within Method::Generate::Constructor::accessor_generator which was called 4 times, avg 2µs/call: # 2 times (4µs+0s) by Method::Generate::Constructor::_build_construction_string at line 70, avg 2µs/call # 2 times (4µs+0s) by Method::Generate::Constructor::_assign_new at line 203, avg 2µs/call
sub accessor_generator {
53473µs $_[0]->{accessor_generator}
54}
55
56
# spent 43µs (14+28) within Method::Generate::Constructor::construction_string which was called 2 times, avg 21µs/call: # 2 times (14µs+28µs) by Method::Generate::Constructor::generate_method at line 141, avg 21µs/call
sub construction_string {
572900ns my ($self) = @_;
58214µs228µs $self->{construction_string}
# spent 28µs making 2 calls to Method::Generate::Constructor::_build_construction_string, avg 14µs/call
59 ||= $self->_build_construction_string;
60}
61
62sub buildall_generator {
63 require Method::Generate::BuildAll;
64 Method::Generate::BuildAll->new;
65}
66
67
# spent 28µs (21+8) within Method::Generate::Constructor::_build_construction_string which was called 2 times, avg 14µs/call: # 2 times (21µs+8µs) by Method::Generate::Constructor::construction_string at line 58, avg 14µs/call
sub _build_construction_string {
682600ns my ($self) = @_;
6921µs my $builder = $self->{construction_builder};
70214µs48µs $builder ? $self->$builder
# spent 4µs making 2 calls to Method::Generate::Constructor::accessor_generator, avg 2µs/call # spent 3µs making 2 calls to Method::Generate::Accessor::default_construction_string, avg 2µs/call
71 : 'bless('
72 .$self->accessor_generator->default_construction_string
73 .', $class);'
74}
75
76
# spent 251µs (88+163) within Method::Generate::Constructor::install_delayed which was called 2 times, avg 125µs/call: # 2 times (88µs+163µs) by Moo::_constructor_maker_for at line 212 of Moo.pm, avg 125µs/call
sub install_delayed {
7721µs my ($self) = @_;
7823µs244µs $self->assert_constructor;
# spent 44µs making 2 calls to Method::Generate::Constructor::assert_constructor, avg 22µs/call
7922µs my $package = $self->{package};
80217µs26µs my (undef, @isa) = @{mro::get_linear_isa($package)};
# spent 6µs making 2 calls to mro::get_linear_isa, avg 3µs/call
8123µs my $isa = join ',', @isa;
82
# spent 12.3ms (81µs+12.2) within Method::Generate::Constructor::__ANON__[/usr/local/share/perl/5.18.2/Method/Generate/Constructor.pm:102] which was called 2 times, avg 6.14ms/call: # 2 times (81µs+12.2ms) by Sub::Defer::undefer_sub at line 23 of Sub/Defer.pm, avg 6.14ms/call
my $constructor = defer_sub "${package}::new" => sub {
83222µs26µs my (undef, @new_isa) = @{mro::get_linear_isa($package)};
# spent 6µs making 2 calls to mro::get_linear_isa, avg 3µs/call
8424µs if (join(',', @new_isa) ne $isa) {
85 my ($expected_new) = grep { *{_getglob($_.'::new')}{CODE} } @isa;
86 my ($found_new) = grep { *{_getglob($_.'::new')}{CODE} } @new_isa;
87 if (($found_new||'') ne ($expected_new||'')) {
88 $found_new ||= 'none';
89 $expected_new ||= 'none';
90 die "Expected parent constructor of $package to be"
91 . " $expected_new, but found $found_new: changing the inheritance"
92 . " chain (\@ISA) at runtime is unsupported";
93 }
94 }
95
96227µs412.2ms my $constructor = unquote_sub $self->generate_method(
# spent 9.97ms making 2 calls to Method::Generate::Constructor::generate_method, avg 4.98ms/call # spent 2.22ms making 2 calls to Sub::Quote::unquote_sub, avg 1.11ms/call
97 $package, 'new', $self->{attribute_specs}, { no_install => 1 }
98 );
99212µs $self->{inlined} = 1;
100211µs22µs weaken($self->{constructor} = $constructor);
# spent 2µs making 2 calls to Scalar::Util::weaken, avg 1µs/call
10128µs $constructor;
102218µs2110µs };
# spent 110µs making 2 calls to Sub::Defer::defer_sub, avg 55µs/call
10326µs $self->{inlined} = 0;
104234µs23µs weaken($self->{constructor} = $constructor);
# spent 3µs making 2 calls to Scalar::Util::weaken, avg 2µs/call
105216µs $self;
106}
107
108
# spent 113µs (77+36) within Method::Generate::Constructor::current_constructor which was called 14 times, avg 8µs/call: # 14 times (77µs+36µs) by Method::Generate::Constructor::assert_constructor at line 116, avg 8µs/call
sub current_constructor {
109145µs my ($self, $package) = @_;
1101469µs1436µs return *{_getglob("${package}::new")}{CODE};
# spent 36µs making 14 calls to Moo::_Utils::_getglob, avg 3µs/call
111}
112
113
# spent 213µs (100+113) within Method::Generate::Constructor::assert_constructor which was called 14 times, avg 15µs/call: # 12 times (81µs+88µs) by Method::Generate::Constructor::register_attribute_specs at line 12, avg 14µs/call # 2 times (19µs+25µs) by Method::Generate::Constructor::install_delayed at line 78, avg 22µs/call
sub assert_constructor {
114144µs my ($self) = @_;
1151416µs my $package = $self->{package} or return 1;
1161433µs14113µs my $current = $self->current_constructor($package)
# spent 113µs making 14 calls to Method::Generate::Constructor::current_constructor, avg 8µs/call
117 or return 1;
118126µs my $constructor = $self->{constructor}
119 or die "Unknown constructor for $package already exists";
120128µs die "Constructor for $package has been replaced with an unknown sub"
121 if $constructor != $current;
1221233µs die "Constructor for $package has been inlined and cannot be updated"
123 if $self->{inlined};
124}
125
126
# spent 9.97ms (149µs+9.82) within Method::Generate::Constructor::generate_method which was called 2 times, avg 4.98ms/call: # 2 times (149µs+9.82ms) by Method::Generate::Constructor::__ANON__[/usr/local/share/perl/5.18.2/Method/Generate/Constructor.pm:102] at line 96, avg 4.98ms/call
sub generate_method {
12722µs my ($self, $into, $name, $spec, $quote_opts) = @_;
128218µs foreach my $no_init (grep !exists($spec->{$_}{init_arg}), keys %$spec) {
1291512µs $spec->{$no_init}{init_arg} = $no_init;
130 }
13123µs local $self->{captures} = {};
1322900ns my $body = ' my $class = ref($_[0]) ? ref(shift) : shift;';
13326µs251µs $body .= $self->_handle_subconstructor($into, $name);
# spent 51µs making 2 calls to Method::Generate::Constructor::_handle_subconstructor, avg 26µs/call
134215µs25µs my $into_buildargs = $into->can('BUILDARGS');
# spent 5µs making 2 calls to UNIVERSAL::can, avg 2µs/call
13527µs14µs if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) {
136 $body .= $self->_generate_args_via_buildargs;
137 } else {
13813µs12µs $body .= $self->_generate_args;
# spent 2µs making 1 call to Method::Generate::Constructor::_generate_args
139 }
14026µs2113µs $body .= $self->_check_required($spec);
# spent 113µs making 2 calls to Method::Generate::Constructor::_check_required, avg 56µs/call
14129µs243µs $body .= ' my $new = '.$self->construction_string.";\n";
# spent 43µs making 2 calls to Method::Generate::Constructor::construction_string, avg 21µs/call
142217µs29.32ms $body .= $self->_assign_new($spec);
# spent 9.32ms making 2 calls to Method::Generate::Constructor::_assign_new, avg 4.66ms/call
143225µs217µs if ($into->can('BUILD')) {
# spent 17µs making 2 calls to UNIVERSAL::can, avg 8µs/call
144 $body .= $self->buildall_generator->buildall_body_for(
145 $into, '$new', '$args'
146 );
147 }
14822µs $body .= ' return $new;'."\n";
149215µs28µs if ($into->can('DEMOLISH')) {
# spent 8µs making 2 calls to UNIVERSAL::can, avg 4µs/call
150 require Method::Generate::DemolishAll;
151 Method::Generate::DemolishAll->new->generate_method($into);
152 }
153 quote_sub
154217µs2252µs "${into}::${name}" => $body,
# spent 252µs making 2 calls to Sub::Quote::quote_sub, avg 126µs/call
155 $self->{captures}, $quote_opts||{}
156 ;
157}
158
159
# spent 51µs (19+33) within Method::Generate::Constructor::_handle_subconstructor which was called 2 times, avg 26µs/call: # 2 times (19µs+33µs) by Method::Generate::Constructor::generate_method at line 133, avg 26µs/call
sub _handle_subconstructor {
16021µs my ($self, $into, $name) = @_;
161217µs233µs if (my $gen = $self->{subconstructor_handler}) {
# spent 33µs making 2 calls to Sub::Quote::quotify, avg 16µs/call
162 ' if ($class ne '.quotify($into).') {'."\n".
163 $gen.
164 ' }'."\n";
165 } else {
166 ''
167 }
168}
169
170
# spent 67µs within Method::Generate::Constructor::_cap_call which was called 15 times, avg 4µs/call: # 15 times (67µs+0s) by Method::Generate::Constructor::_assign_new at line 217, avg 4µs/call
sub _cap_call {
171159µs my ($self, $code, $captures) = @_;
1721535µs @{$self->{captures}}{keys %$captures} = values %$captures if $captures;
1731543µs $code;
174}
175
176
# spent 4µs within Method::Generate::Constructor::_generate_args_via_buildargs which was called: # once (4µs+0s) by Method::Generate::Constructor::generate_method at line 135
sub _generate_args_via_buildargs {
1771700ns my ($self) = @_;
17815µs q{ my $args = $class->BUILDARGS(@_);}."\n"
179 .q{ die "BUILDARGS did not return a hashref" unless ref($args) eq 'HASH';}
180 ."\n";
181}
182
183# inlined from Moo::Object - update that first.
184
# spent 2µs within Method::Generate::Constructor::_generate_args which was called: # once (2µs+0s) by Method::Generate::Constructor::generate_method at line 138
sub _generate_args {
1851600ns my ($self) = @_;
18615µs return <<'_EOA';
187 my $args = scalar @_ == 1
188 ? ref $_[0] eq 'HASH'
189 ? { %{ $_[0] } }
190 : die "Single parameters to new() must be a HASH ref"
191 . " data => ". $_[0] ."\n"
192 : @_ % 2
193 ? die "The new() method for $class expects a hash reference or a"
194 . " key/value list. You passed an odd number of arguments\n"
195 : {@_}
196 ;
197_EOA
198
199}
200
201
# spent 9.32ms (344µs+8.98) within Method::Generate::Constructor::_assign_new which was called 2 times, avg 4.66ms/call: # 2 times (344µs+8.98ms) by Method::Generate::Constructor::generate_method at line 142, avg 4.66ms/call
sub _assign_new {
20221µs my ($self, $spec) = @_;
20324µs24µs my $ag = $self->accessor_generator;
# spent 4µs making 2 calls to Method::Generate::Constructor::accessor_generator, avg 2µs/call
2042700ns my %test;
205220µs24µs NAME: foreach my $name (sort keys %$spec) {
# spent 4µs making 2 calls to Method::Generate::Constructor::CORE:sort, avg 2µs/call
206156µs my $attr_spec = $spec->{$name};
207157µs next NAME unless defined($attr_spec->{init_arg})
208 or $ag->has_eager_default($name, $attr_spec);
2091520µs $test{$name} = $attr_spec->{init_arg};
210 }
2111510µs join '', map {
212268µs25µs my $arg = $test{$_};
# spent 5µs making 2 calls to Method::Generate::Constructor::CORE:sort, avg 2µs/call
2131527µs1582µs my $arg_key = quotify($arg);
# spent 82µs making 15 calls to Sub::Quote::quotify, avg 5µs/call
2141513µs my $test = defined $arg ? "exists \$args->{$arg_key}" : undef;
215158µs my $source = defined $arg ? "\$args->{$arg_key}" : undef;
216158µs my $attr_spec = $spec->{$_};
2171554µs308.88ms $self->_cap_call($ag->generate_populate_set(
# spent 8.82ms making 15 calls to Method::Generate::Accessor::generate_populate_set, avg 588µs/call # spent 67µs making 15 calls to Method::Generate::Constructor::_cap_call, avg 4µs/call
218 '$new', $_, $attr_spec, $source, $test, $arg,
219 ));
220 } sort keys %test;
221}
222
223
# spent 113µs (96+17) within Method::Generate::Constructor::_check_required which was called 2 times, avg 56µs/call: # 2 times (96µs+17µs) by Method::Generate::Constructor::generate_method at line 140, avg 56µs/call
sub _check_required {
22421µs my ($self, $spec) = @_;
225 my @required_init =
226 map $spec->{$_}{init_arg},
227 grep {
2281790µs217µs my %s = %{$spec->{$_}}; # ignore required if default or builder set
# spent 17µs making 2 calls to Method::Generate::Constructor::CORE:sort, avg 8µs/call
2291515µs $s{required} and not($s{builder} or exists $s{default})
230 } sort keys %$spec;
231211µs return '' unless @required_init;
232 ' if (my @missing = grep !exists $args->{$_}, '
233 .join(', ', map quotify($_), @required_init).') {'."\n"
234 .q{ die "Missing required arguments: ".join(', ', sort @missing);}."\n"
235 ." }\n";
236}
237
238# bootstrap our own constructor
239sub new {
24011µs my $class = shift;
241111µs15µs delete _getstash(__PACKAGE__)->{new};
# spent 5µs making 1 call to Moo::_Utils::_getstash
242117µs18µs bless $class->BUILDARGS(@_), $class;
# spent 8µs making 1 call to Moo::Object::BUILDARGS
243}
244125µs285µsMoo->_constructor_maker_for(__PACKAGE__)
# spent 85µs making 1 call to Method::Generate::Constructor::register_attribute_specs # spent 10.5ms making 1 call to Moo::_constructor_maker_for, recursion: max depth 1, sum of overlapping time 10.5ms
245->register_attribute_specs(
246 attribute_specs => {
247 is => 'ro',
248 reader => 'all_attribute_specs',
249 },
250 accessor_generator => { is => 'ro' },
251 construction_string => { is => 'lazy' },
252 construction_builder => { is => 'bare' },
253 subconstructor_handler => { is => 'ro' },
254 package => { is => 'bare' },
255);
256
257111µs1;
 
# spent 26µs within Method::Generate::Constructor::CORE:sort which was called 6 times, avg 4µs/call: # 2 times (17µs+0s) by Method::Generate::Constructor::_check_required at line 228, avg 8µs/call # 2 times (5µs+0s) by Method::Generate::Constructor::_assign_new at line 212, avg 2µs/call # 2 times (4µs+0s) by Method::Generate::Constructor::_assign_new at line 205, avg 2µs/call
sub Method::Generate::Constructor::CORE:sort; # opcode
# spent 11µs within Method::Generate::Constructor::CORE:subst which was called 15 times, avg 753ns/call: # 15 times (11µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 15, avg 753ns/call
sub Method::Generate::Constructor::CORE:subst; # opcode