Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/Method/Generate/Constructor.pm |
Statements | Executed 271 statements in 2.16ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 1 | 1 | 132µs | 846µs | generate_method | Method::Generate::Constructor::
3 | 1 | 1 | 129µs | 472µs | _assign_new | Method::Generate::Constructor::
6 | 3 | 2 | 67µs | 71µs | register_attribute_specs | Method::Generate::Constructor::
3 | 1 | 1 | 46µs | 49µs | _check_required | Method::Generate::Constructor::
3 | 1 | 1 | 33µs | 120µs | install_delayed | Method::Generate::Constructor::
1 | 1 | 1 | 27µs | 107µs | BEGIN@3 | Method::Generate::Constructor::
3 | 1 | 1 | 25µs | 2.57ms | __ANON__[:64] | Method::Generate::Constructor::
3 | 1 | 1 | 25µs | 29µs | _handle_subconstructor | Method::Generate::Constructor::
7 | 1 | 1 | 22µs | 22µs | _cap_call | Method::Generate::Constructor::
3 | 1 | 1 | 22µs | 28µs | _build_construction_string | Method::Generate::Constructor::
1 | 1 | 1 | 16µs | 44µs | BEGIN@7 | Method::Generate::Constructor::
3 | 1 | 1 | 14µs | 42µs | construction_string | Method::Generate::Constructor::
1 | 1 | 1 | 13µs | 62µs | BEGIN@4 | Method::Generate::Constructor::
1 | 1 | 1 | 12µs | 49µs | BEGIN@6 | Method::Generate::Constructor::
1 | 1 | 1 | 12µs | 100µs | BEGIN@5 | Method::Generate::Constructor::
1 | 1 | 1 | 11µs | 65µs | BEGIN@8 | Method::Generate::Constructor::
1 | 1 | 1 | 10µs | 1.07ms | BEGIN@186 | Method::Generate::Constructor::
9 | 3 | 1 | 6µs | 6µs | CORE:sort (opcode) | Method::Generate::Constructor::
6 | 2 | 1 | 6µs | 6µs | accessor_generator | Method::Generate::Constructor::
3 | 1 | 1 | 6µs | 6µs | _generate_args | Method::Generate::Constructor::
7 | 1 | 1 | 4µs | 4µs | CORE:subst (opcode) | Method::Generate::Constructor::
0 | 0 | 0 | 0s | 0s | _generate_args_via_buildargs | 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 | 43µs | 3 | 188µs | # spent 107µs (27+81) within Method::Generate::Constructor::BEGIN@3 which was called:
# once (27µs+81µs) by Moo::_constructor_maker_for at line 3 # spent 107µs making 1 call to Method::Generate::Constructor::BEGIN@3
# spent 60µs making 1 call to strictures::import
# spent 21µs making 1 call to strictures::VERSION |
4 | 2 | 50µs | 2 | 111µs | # spent 62µs (13+49) within Method::Generate::Constructor::BEGIN@4 which was called:
# once (13µs+49µs) by Moo::_constructor_maker_for at line 4 # spent 62µs making 1 call to Method::Generate::Constructor::BEGIN@4
# spent 49µs making 1 call to Exporter::import |
5 | 2 | 46µs | 2 | 189µs | # spent 100µs (12+89) within Method::Generate::Constructor::BEGIN@5 which was called:
# once (12µs+89µs) by Moo::_constructor_maker_for at line 5 # spent 100µs making 1 call to Method::Generate::Constructor::BEGIN@5
# spent 89µs making 1 call to base::import |
6 | 2 | 41µs | 2 | 86µs | # spent 49µs (12+37) within Method::Generate::Constructor::BEGIN@6 which was called:
# once (12µs+37µs) by Moo::_constructor_maker_for at line 6 # spent 49µs making 1 call to Method::Generate::Constructor::BEGIN@6
# spent 37µs making 1 call to Exporter::import |
7 | 2 | 38µs | 2 | 73µs | # spent 44µs (16+29) within Method::Generate::Constructor::BEGIN@7 which was called:
# once (16µs+29µs) by Moo::_constructor_maker_for at line 7 # spent 44µs making 1 call to Method::Generate::Constructor::BEGIN@7
# spent 29µs making 1 call to Exporter::import |
8 | 2 | 1.30ms | 2 | 119µs | # spent 65µs (11+54) within Method::Generate::Constructor::BEGIN@8 which was called:
# once (11µs+54µs) by Moo::_constructor_maker_for at line 8 # spent 65µs making 1 call to Method::Generate::Constructor::BEGIN@8
# spent 54µs making 1 call to Exporter::import |
9 | |||||
10 | # spent 71µs (67+4) within Method::Generate::Constructor::register_attribute_specs which was called 6 times, avg 12µs/call:
# 3 times (20µs+0s) by Moo::_constructor_maker_for at line 189 of Moo.pm, avg 7µs/call
# 2 times (18µs+2µs) by Moo::has at line 52 of Moo.pm, avg 10µs/call
# once (30µs+2µs) by Moo::_constructor_maker_for at line 187 | ||||
11 | 6 | 5µs | my ($self, @new_specs) = @_; | ||
12 | 6 | 10µs | my $specs = $self->{attribute_specs}||={}; | ||
13 | 6 | 13µs | while (my ($name, $new_spec) = splice @new_specs, 0, 2) { | ||
14 | 7 | 20µs | 7 | 4µs | if ($name =~ s/^\+//) { # spent 4µs making 7 calls to Method::Generate::Constructor::CORE:subst, avg 514ns/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 | 7 | 6µs | $new_spec->{index} = scalar keys %$specs | ||
31 | unless defined $new_spec->{index}; | ||||
32 | 7 | 3µs | $specs->{$name} = $new_spec; | ||
33 | } | ||||
34 | 6 | 18µs | $self; | ||
35 | } | ||||
36 | |||||
37 | sub all_attribute_specs { | ||||
38 | $_[0]->{attribute_specs} | ||||
39 | } | ||||
40 | |||||
41 | # spent 6µs within Method::Generate::Constructor::accessor_generator which was called 6 times, avg 1µs/call:
# 3 times (3µs+0s) by Method::Generate::Constructor::_build_construction_string at line 52, avg 1µs/call
# 3 times (3µs+0s) by Method::Generate::Constructor::_assign_new at line 152, avg 900ns/call | ||||
42 | 6 | 17µs | $_[0]->{accessor_generator} | ||
43 | } | ||||
44 | |||||
45 | # spent 42µs (14+28) within Method::Generate::Constructor::construction_string which was called 3 times, avg 14µs/call:
# 3 times (14µs+28µs) by Method::Generate::Constructor::generate_method at line 84, avg 14µs/call | ||||
46 | 3 | 600ns | my ($self) = @_; | ||
47 | 3 | 11µs | 3 | 28µs | $self->{construction_string} # spent 28µs making 3 calls to Method::Generate::Constructor::_build_construction_string, avg 9µs/call |
48 | ||= $self->_build_construction_string; | ||||
49 | } | ||||
50 | |||||
51 | # spent 28µs (22+6) within Method::Generate::Constructor::_build_construction_string which was called 3 times, avg 9µs/call:
# 3 times (22µs+6µs) by Method::Generate::Constructor::construction_string at line 47, avg 9µs/call | ||||
52 | 3 | 15µs | 6 | 6µs | 'bless(' # spent 3µs making 3 calls to Method::Generate::Constructor::accessor_generator, avg 1µs/call
# spent 3µs making 3 calls to Method::Generate::Accessor::default_construction_string, avg 1µs/call |
53 | .$_[0]->accessor_generator->default_construction_string | ||||
54 | .', $class);' | ||||
55 | } | ||||
56 | |||||
57 | # spent 120µs (33+87) within Method::Generate::Constructor::install_delayed which was called 3 times, avg 40µs/call:
# 3 times (33µs+87µs) by Moo::_constructor_maker_for at line 189 of Moo.pm, avg 40µs/call | ||||
58 | 3 | 1µs | my ($self) = @_; | ||
59 | 3 | 4µs | my $package = $self->{package}; | ||
60 | # spent 2.57ms (25µs+2.54) within Method::Generate::Constructor::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Method/Generate/Constructor.pm:64] which was called 3 times, avg 855µs/call:
# 3 times (25µs+2.54ms) by Sub::Defer::undefer_sub at line 22 of Sub/Defer.pm, avg 855µs/call | ||||
61 | 3 | 18µs | 6 | 2.54ms | unquote_sub $self->generate_method( # spent 1.69ms making 3 calls to Sub::Quote::unquote_sub, avg 565µs/call
# spent 846µs making 3 calls to Method::Generate::Constructor::generate_method, avg 282µs/call |
62 | $package, 'new', $self->{attribute_specs}, { no_install => 1 } | ||||
63 | ) | ||||
64 | 3 | 18µs | 3 | 87µs | }; # spent 87µs making 3 calls to Sub::Defer::defer_sub, avg 29µs/call |
65 | 3 | 7µs | $self; | ||
66 | } | ||||
67 | |||||
68 | # spent 846µs (132+715) within Method::Generate::Constructor::generate_method which was called 3 times, avg 282µs/call:
# 3 times (132µs+715µs) by Method::Generate::Constructor::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Method/Generate/Constructor.pm:64] at line 61, avg 282µs/call | ||||
69 | 3 | 1µs | my ($self, $into, $name, $spec, $quote_opts) = @_; | ||
70 | 3 | 9µs | foreach my $no_init (grep !exists($spec->{$_}{init_arg}), keys %$spec) { | ||
71 | 7 | 5µs | $spec->{$no_init}{init_arg} = $no_init; | ||
72 | } | ||||
73 | 3 | 3µs | local $self->{captures} = {}; | ||
74 | 3 | 900ns | my $body = ' my $class = shift;'."\n" | ||
75 | .' $class = ref($class) if ref($class);'."\n"; | ||||
76 | 3 | 5µs | 3 | 29µs | $body .= $self->_handle_subconstructor($into, $name); # spent 29µs making 3 calls to Method::Generate::Constructor::_handle_subconstructor, avg 10µs/call |
77 | 3 | 22µs | 3 | 12µs | my $into_buildargs = $into->can('BUILDARGS'); # spent 12µs making 3 calls to UNIVERSAL::can, avg 4µs/call |
78 | 3 | 4µs | if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) { | ||
79 | $body .= $self->_generate_args_via_buildargs; | ||||
80 | } else { | ||||
81 | 3 | 5µs | 3 | 6µs | $body .= $self->_generate_args; # spent 6µs making 3 calls to Method::Generate::Constructor::_generate_args, avg 2µs/call |
82 | } | ||||
83 | 3 | 4µs | 3 | 49µs | $body .= $self->_check_required($spec); # spent 49µs making 3 calls to Method::Generate::Constructor::_check_required, avg 16µs/call |
84 | 3 | 12µs | 3 | 42µs | $body .= ' my $new = '.$self->construction_string.";\n"; # spent 42µs making 3 calls to Method::Generate::Constructor::construction_string, avg 14µs/call |
85 | 3 | 6µs | 3 | 472µs | $body .= $self->_assign_new($spec); # spent 472µs making 3 calls to Method::Generate::Constructor::_assign_new, avg 157µs/call |
86 | 3 | 20µs | 3 | 12µs | if ($into->can('BUILD')) { # spent 12µs making 3 calls to UNIVERSAL::can, avg 4µs/call |
87 | require Method::Generate::BuildAll; | ||||
88 | $body .= Method::Generate::BuildAll->new->buildall_body_for( | ||||
89 | $into, '$new', '$args' | ||||
90 | ); | ||||
91 | } | ||||
92 | 3 | 600ns | $body .= ' return $new;'."\n"; | ||
93 | 3 | 14µs | 3 | 7µs | if ($into->can('DEMOLISH')) { # spent 7µs making 3 calls to UNIVERSAL::can, avg 2µs/call |
94 | require Method::Generate::DemolishAll; | ||||
95 | Method::Generate::DemolishAll->new->generate_method($into); | ||||
96 | } | ||||
97 | quote_sub | ||||
98 | 3 | 18µs | 3 | 86µs | "${into}::${name}" => $body, # spent 86µs making 3 calls to Sub::Quote::quote_sub, avg 28µs/call |
99 | $self->{captures}, $quote_opts||{} | ||||
100 | ; | ||||
101 | } | ||||
102 | |||||
103 | # spent 29µs (25+5) within Method::Generate::Constructor::_handle_subconstructor which was called 3 times, avg 10µs/call:
# 3 times (25µs+5µs) by Method::Generate::Constructor::generate_method at line 76, avg 10µs/call | ||||
104 | 3 | 1µs | my ($self, $into, $name) = @_; | ||
105 | 3 | 33µs | 3 | 5µs | if (my $gen = $self->{subconstructor_handler}) { # spent 5µs making 3 calls to B::perlstring, avg 2µs/call |
106 | ' if ($class ne '.perlstring($into).') {'."\n". | ||||
107 | $gen. | ||||
108 | ' }'."\n"; | ||||
109 | } else { | ||||
110 | '' | ||||
111 | } | ||||
112 | } | ||||
113 | |||||
114 | # spent 22µs within Method::Generate::Constructor::_cap_call which was called 7 times, avg 3µs/call:
# 7 times (22µs+0s) by Method::Generate::Constructor::_assign_new at line 165, avg 3µs/call | ||||
115 | 7 | 4µs | my ($self, $code, $captures) = @_; | ||
116 | 7 | 8µs | @{$self->{captures}}{keys %$captures} = values %$captures if $captures; | ||
117 | 7 | 17µs | $code; | ||
118 | } | ||||
119 | |||||
120 | sub _generate_args_via_buildargs { | ||||
121 | my ($self) = @_; | ||||
122 | q{ my $args = $class->BUILDARGS(@_);}."\n" | ||||
123 | .q{ die "BUILDARGS did not return a hashref" unless ref($args) eq 'HASH';} | ||||
124 | ."\n"; | ||||
125 | } | ||||
126 | |||||
127 | # inlined from Moo::Object - update that first. | ||||
128 | # spent 6µs within Method::Generate::Constructor::_generate_args which was called 3 times, avg 2µs/call:
# 3 times (6µs+0s) by Method::Generate::Constructor::generate_method at line 81, avg 2µs/call | ||||
129 | 3 | 600ns | my ($self) = @_; | ||
130 | 3 | 9µs | return <<'_EOA'; | ||
131 | my $args; | ||||
132 | if ( scalar @_ == 1 ) { | ||||
133 | unless ( defined $_[0] && ref $_[0] eq 'HASH' ) { | ||||
134 | die "Single parameters to new() must be a HASH ref" | ||||
135 | ." data => ". $_[0] ."\n"; | ||||
136 | } | ||||
137 | $args = { %{ $_[0] } }; | ||||
138 | } | ||||
139 | elsif ( @_ % 2 ) { | ||||
140 | die "The new() method for $class expects a hash reference or a key/value list." | ||||
141 | . " You passed an odd number of arguments\n"; | ||||
142 | } | ||||
143 | else { | ||||
144 | $args = {@_}; | ||||
145 | } | ||||
146 | _EOA | ||||
147 | |||||
148 | } | ||||
149 | |||||
150 | # spent 472µs (129+343) within Method::Generate::Constructor::_assign_new which was called 3 times, avg 157µs/call:
# 3 times (129µs+343µs) by Method::Generate::Constructor::generate_method at line 85, avg 157µs/call | ||||
151 | 3 | 800ns | my ($self, $spec) = @_; | ||
152 | 3 | 2µs | 3 | 3µs | my $ag = $self->accessor_generator; # spent 3µs making 3 calls to Method::Generate::Constructor::accessor_generator, avg 900ns/call |
153 | 3 | 300ns | my %test; | ||
154 | 3 | 16µs | 3 | 2µs | NAME: foreach my $name (sort keys %$spec) { # spent 2µs making 3 calls to Method::Generate::Constructor::CORE:sort, avg 600ns/call |
155 | 7 | 2µs | my $attr_spec = $spec->{$name}; | ||
156 | 7 | 1µs | next NAME unless defined($attr_spec->{init_arg}) | ||
157 | or $ag->has_eager_default($name, $attr_spec); | ||||
158 | 7 | 6µs | $test{$name} = $attr_spec->{init_arg}; | ||
159 | } | ||||
160 | 7 | 27µs | 7 | 10µs | join '', map { # spent 10µs making 7 calls to B::perlstring, avg 1µs/call |
161 | 3 | 33µs | 3 | 1µs | my $arg_key = perlstring($test{$_}); # spent 1µs making 3 calls to Method::Generate::Constructor::CORE:sort, avg 433ns/call |
162 | 7 | 3µs | my $test = "exists \$args->{$arg_key}"; | ||
163 | 7 | 3µs | my $source = "\$args->{$arg_key}"; | ||
164 | 7 | 2µs | my $attr_spec = $spec->{$_}; | ||
165 | 7 | 18µs | 14 | 328µs | $self->_cap_call($ag->generate_populate_set( # spent 305µs making 7 calls to Method::Generate::Accessor::generate_populate_set, avg 44µs/call
# spent 22µs making 7 calls to Method::Generate::Constructor::_cap_call, avg 3µs/call |
166 | '$new', $_, $attr_spec, $source, $test, $test{$_}, | ||||
167 | )); | ||||
168 | } sort keys %test; | ||||
169 | } | ||||
170 | |||||
171 | # spent 49µs (46+3) within Method::Generate::Constructor::_check_required which was called 3 times, avg 16µs/call:
# 3 times (46µs+3µs) by Method::Generate::Constructor::generate_method at line 83, avg 16µs/call | ||||
172 | 3 | 800ns | my ($self, $spec) = @_; | ||
173 | my @required_init = | ||||
174 | map $spec->{$_}{init_arg}, | ||||
175 | grep { | ||||
176 | 10 | 35µs | 3 | 3µs | my %s = %{$spec->{$_}}; # ignore required if default or builder set # spent 3µs making 3 calls to Method::Generate::Constructor::CORE:sort, avg 1µs/call |
177 | 7 | 6µs | $s{required} and not($s{builder} or $s{default}) | ||
178 | } sort keys %$spec; | ||||
179 | 3 | 10µs | return '' unless @required_init; | ||
180 | ' if (my @missing = grep !exists $args->{$_}, qw(' | ||||
181 | .join(' ',@required_init).')) {'."\n" | ||||
182 | .q{ die "Missing required arguments: ".join(', ', sort @missing);}."\n" | ||||
183 | ." }\n"; | ||||
184 | } | ||||
185 | |||||
186 | 2 | 87µs | 2 | 2.13ms | # spent 1.07ms (10µs+1.06) within Method::Generate::Constructor::BEGIN@186 which was called:
# once (10µs+1.06ms) by Moo::_constructor_maker_for at line 186 # spent 1.07ms making 1 call to Method::Generate::Constructor::BEGIN@186
# spent 1.06ms making 1 call to Moo::import |
187 | 1 | 13µs | 2 | 32µs | Moo->_constructor_maker_for(__PACKAGE__)->register_attribute_specs( # spent 32µs making 1 call to Method::Generate::Constructor::register_attribute_specs
# spent 5.76ms making 1 call to Moo::_constructor_maker_for, recursion: max depth 1, sum of overlapping time 5.76ms |
188 | attribute_specs => { | ||||
189 | is => 'ro', | ||||
190 | reader => 'all_attribute_specs', | ||||
191 | }, | ||||
192 | accessor_generator => { is => 'ro' }, | ||||
193 | construction_string => { is => 'lazy' }, | ||||
194 | subconstructor_handler => { is => 'ro' }, | ||||
195 | package => { is => 'ro' }, | ||||
196 | ); | ||||
197 | |||||
198 | 1 | 8µs | 1; | ||
# spent 6µs within Method::Generate::Constructor::CORE:sort which was called 9 times, avg 711ns/call:
# 3 times (3µs+0s) by Method::Generate::Constructor::_check_required at line 176, avg 1µs/call
# 3 times (2µs+0s) by Method::Generate::Constructor::_assign_new at line 154, avg 600ns/call
# 3 times (1µs+0s) by Method::Generate::Constructor::_assign_new at line 161, avg 433ns/call | |||||
# spent 4µs within Method::Generate::Constructor::CORE:subst which was called 7 times, avg 514ns/call:
# 7 times (4µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 14, avg 514ns/call |