Filename | /usr/share/perl5/Method/Generate/Constructor.pm |
Statements | Executed 349 statements in 1.92ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 129µs | 588µs | _assign_new | Method::Generate::Constructor::
2 | 1 | 1 | 100µs | 976µs | generate_method | Method::Generate::Constructor::
10 | 3 | 2 | 87µs | 94µs | register_attribute_specs | Method::Generate::Constructor::
2 | 1 | 1 | 60µs | 68µs | _check_required | Method::Generate::Constructor::
1 | 1 | 1 | 24µs | 97µs | BEGIN@3 | Method::Generate::Constructor::
11 | 1 | 1 | 21µs | 21µs | _cap_call | Method::Generate::Constructor::
2 | 1 | 1 | 20µs | 2.31ms | __ANON__[:81] | Method::Generate::Constructor::
2 | 1 | 1 | 20µs | 74µs | install_delayed | Method::Generate::Constructor::
2 | 1 | 1 | 16µs | 29µs | _build_construction_string | Method::Generate::Constructor::
2 | 1 | 1 | 14µs | 33µs | _handle_subconstructor | Method::Generate::Constructor::
1 | 1 | 1 | 12µs | 430µs | BEGIN@202 | Method::Generate::Constructor::
2 | 1 | 1 | 12µs | 40µs | construction_string | Method::Generate::Constructor::
6 | 3 | 1 | 11µs | 11µs | CORE:sort (opcode) | Method::Generate::Constructor::
1 | 1 | 1 | 11µs | 34µs | BEGIN@5 | Method::Generate::Constructor::
1 | 1 | 1 | 10µs | 48µs | BEGIN@4 | Method::Generate::Constructor::
1 | 1 | 1 | 9µs | 44µs | BEGIN@6 | Method::Generate::Constructor::
1 | 1 | 1 | 9µs | 47µs | __ANON__[:202] | Method::Generate::Constructor::
13 | 1 | 1 | 7µs | 7µs | CORE:subst (opcode) | Method::Generate::Constructor::
3 | 2 | 1 | 3µs | 3µs | accessor_generator | Method::Generate::Constructor::
2 | 1 | 1 | 3µs | 3µs | _generate_args | 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::
0 | 0 | 0 | 0s | 0s | buildall_generator | 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 | 171µs | # spent 97µs (24+73) within Method::Generate::Constructor::BEGIN@3 which was called:
# once (24µs+73µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 3 # spent 97µs making 1 call to Method::Generate::Constructor::BEGIN@3
# spent 47µs making 1 call to strictures::import
# spent 26µs making 1 call to strictures::VERSION |
4 | 2 | 70µs | 2 | 86µs | # spent 48µs (10+38) within Method::Generate::Constructor::BEGIN@4 which was called:
# once (10µs+38µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 4 # spent 48µs making 1 call to Method::Generate::Constructor::BEGIN@4
# spent 38µs making 1 call to Exporter::import |
5 | 2 | 56µs | 2 | 56µs | # spent 34µs (11+23) within Method::Generate::Constructor::BEGIN@5 which was called:
# once (11µs+23µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 5 # spent 34µs making 1 call to Method::Generate::Constructor::BEGIN@5
# spent 23µs making 1 call to Exporter::import |
6 | 2 | 1.10ms | 2 | 79µs | # spent 44µs (9+35) within Method::Generate::Constructor::BEGIN@6 which was called:
# once (9µs+35µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 6 # spent 44µs making 1 call to Method::Generate::Constructor::BEGIN@6
# spent 35µs making 1 call to Exporter::import |
7 | |||||
8 | # spent 94µs (87+7) within Method::Generate::Constructor::register_attribute_specs which was called 10 times, avg 9µs/call:
# 7 times (51µs+6µs) by Moo::has at line 52 of Moo.pm, avg 8µs/call
# 2 times (10µs+0s) by Moo::_constructor_maker_for at line 201 of Moo.pm, avg 5µs/call
# once (26µs+2µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 208 | ||||
9 | 10 | 6µs | my ($self, @new_specs) = @_; | ||
10 | 10 | 7µs | my $specs = $self->{attribute_specs}||={}; | ||
11 | 10 | 20µs | while (my ($name, $new_spec) = splice @new_specs, 0, 2) { | ||
12 | 13 | 32µs | 13 | 7µs | if ($name =~ s/^\+//) { # spent 7µs making 13 calls to Method::Generate::Constructor::CORE:subst, avg 569ns/call |
13 | die "has '+${name}' given but no ${name} attribute already exists" | ||||
14 | unless my $old_spec = $specs->{$name}; | ||||
15 | foreach my $key (keys %$old_spec) { | ||||
16 | if (!exists $new_spec->{$key}) { | ||||
17 | $new_spec->{$key} = $old_spec->{$key} | ||||
18 | unless $key eq 'handles'; | ||||
19 | } | ||||
20 | elsif ($key eq 'moosify') { | ||||
21 | $new_spec->{$key} = [ | ||||
22 | map { ref $_ eq 'ARRAY' ? @$_ : $_ } | ||||
23 | ($old_spec->{$key}, $new_spec->{$key}) | ||||
24 | ]; | ||||
25 | } | ||||
26 | } | ||||
27 | } | ||||
28 | 13 | 5µs | if ($new_spec->{required} | ||
29 | && !( | ||||
30 | exists $new_spec->{default} | ||||
31 | || $new_spec->{builder} | ||||
32 | || !exists $new_spec->{init_arg} | ||||
33 | || defined $new_spec->{init_arg} | ||||
34 | ) | ||||
35 | ) { | ||||
36 | die "You cannot have a required attribute (${name})" | ||||
37 | . " without a default, builder, or an init_arg"; | ||||
38 | } | ||||
39 | 13 | 8µs | $new_spec->{index} = scalar keys %$specs | ||
40 | unless defined $new_spec->{index}; | ||||
41 | 13 | 7µs | $specs->{$name} = $new_spec; | ||
42 | } | ||||
43 | 10 | 19µs | $self; | ||
44 | } | ||||
45 | |||||
46 | sub all_attribute_specs { | ||||
47 | $_[0]->{attribute_specs} | ||||
48 | } | ||||
49 | |||||
50 | sub accessor_generator { | ||||
51 | 3 | 9µs | $_[0]->{accessor_generator} | ||
52 | } | ||||
53 | |||||
54 | # spent 40µs (12+29) within Method::Generate::Constructor::construction_string which was called 2 times, avg 20µs/call:
# 2 times (12µs+29µs) by Method::Generate::Constructor::generate_method at line 101, avg 20µs/call | ||||
55 | 2 | 700ns | my ($self) = @_; | ||
56 | 2 | 9µs | 2 | 29µs | $self->{construction_string} # spent 29µs making 2 calls to Method::Generate::Constructor::_build_construction_string, avg 14µs/call |
57 | ||= $self->_build_construction_string; | ||||
58 | } | ||||
59 | |||||
60 | sub buildall_generator { | ||||
61 | require Method::Generate::BuildAll; | ||||
62 | Method::Generate::BuildAll->new; | ||||
63 | } | ||||
64 | |||||
65 | # spent 29µs (16+13) within Method::Generate::Constructor::_build_construction_string which was called 2 times, avg 14µs/call:
# 2 times (16µs+13µs) by Method::Generate::Constructor::construction_string at line 56, avg 14µs/call | ||||
66 | 2 | 400ns | my ($self) = @_; | ||
67 | 2 | 800ns | my $builder = $self->{construction_builder}; | ||
68 | 2 | 13µs | 3 | 12µs | $builder ? $self->$builder # spent 9µs making 1 call to Moo::__ANON__[Moo.pm:183]
# spent 2µs making 1 call to Method::Generate::Constructor::accessor_generator
# spent 2µs making 1 call to Method::Generate::Accessor::default_construction_string |
69 | : 'bless(' | ||||
70 | .$self->accessor_generator->default_construction_string | ||||
71 | .', $class);' | ||||
72 | } | ||||
73 | |||||
74 | # spent 74µs (20+55) within Method::Generate::Constructor::install_delayed which was called 2 times, avg 37µs/call:
# 2 times (20µs+55µs) by Moo::_constructor_maker_for at line 201 of Moo.pm, avg 37µs/call | ||||
75 | 2 | 700ns | my ($self) = @_; | ||
76 | 2 | 4µs | my $package = $self->{package}; | ||
77 | # spent 2.31ms (20µs+2.29) within Method::Generate::Constructor::__ANON__[/usr/share/perl5/Method/Generate/Constructor.pm:81] which was called 2 times, avg 1.16ms/call:
# 2 times (20µs+2.29ms) by Sub::Defer::undefer_sub at line 22 of Sub/Defer.pm, avg 1.16ms/call | ||||
78 | 2 | 14µs | 4 | 2.29ms | unquote_sub $self->generate_method( # spent 1.32ms making 2 calls to Sub::Quote::unquote_sub, avg 658µs/call
# spent 976µs making 2 calls to Method::Generate::Constructor::generate_method, avg 488µs/call |
79 | $package, 'new', $self->{attribute_specs}, { no_install => 1 } | ||||
80 | ) | ||||
81 | 2 | 7µs | 2 | 55µs | }; # spent 55µs making 2 calls to Sub::Defer::defer_sub, avg 27µs/call |
82 | 2 | 4µs | $self; | ||
83 | } | ||||
84 | |||||
85 | # spent 976µs (100+877) within Method::Generate::Constructor::generate_method which was called 2 times, avg 488µs/call:
# 2 times (100µs+877µs) by Method::Generate::Constructor::__ANON__[/usr/share/perl5/Method/Generate/Constructor.pm:81] at line 78, avg 488µs/call | ||||
86 | 2 | 2µs | my ($self, $into, $name, $spec, $quote_opts) = @_; | ||
87 | 2 | 15µs | foreach my $no_init (grep !exists($spec->{$_}{init_arg}), keys %$spec) { | ||
88 | 11 | 6µs | $spec->{$no_init}{init_arg} = $no_init; | ||
89 | } | ||||
90 | 2 | 2µs | local $self->{captures} = {}; | ||
91 | 2 | 900ns | my $body = ' my $class = shift;'."\n" | ||
92 | .' $class = ref($class) if ref($class);'."\n"; | ||||
93 | 2 | 4µs | 2 | 33µs | $body .= $self->_handle_subconstructor($into, $name); # spent 33µs making 2 calls to Method::Generate::Constructor::_handle_subconstructor, avg 16µs/call |
94 | 2 | 15µs | 2 | 9µs | my $into_buildargs = $into->can('BUILDARGS'); # spent 9µs making 2 calls to UNIVERSAL::can, avg 4µs/call |
95 | 2 | 3µs | if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) { | ||
96 | $body .= $self->_generate_args_via_buildargs; | ||||
97 | } else { | ||||
98 | 2 | 4µs | 2 | 3µs | $body .= $self->_generate_args; # spent 3µs making 2 calls to Method::Generate::Constructor::_generate_args, avg 1µs/call |
99 | } | ||||
100 | 2 | 4µs | 2 | 68µs | $body .= $self->_check_required($spec); # spent 68µs making 2 calls to Method::Generate::Constructor::_check_required, avg 34µs/call |
101 | 2 | 5µs | 2 | 40µs | $body .= ' my $new = '.$self->construction_string.";\n"; # spent 40µs making 2 calls to Method::Generate::Constructor::construction_string, avg 20µs/call |
102 | 2 | 9µs | 2 | 588µs | $body .= $self->_assign_new($spec); # spent 588µs making 2 calls to Method::Generate::Constructor::_assign_new, avg 294µs/call |
103 | 2 | 15µs | 2 | 9µs | if ($into->can('BUILD')) { # spent 9µs making 2 calls to UNIVERSAL::can, avg 4µs/call |
104 | $body .= $self->buildall_generator->buildall_body_for( | ||||
105 | $into, '$new', '$args' | ||||
106 | ); | ||||
107 | } | ||||
108 | 2 | 1µs | $body .= ' return $new;'."\n"; | ||
109 | 2 | 11µs | 2 | 7µs | if ($into->can('DEMOLISH')) { # spent 7µs making 2 calls to UNIVERSAL::can, avg 4µs/call |
110 | require Method::Generate::DemolishAll; | ||||
111 | Method::Generate::DemolishAll->new->generate_method($into); | ||||
112 | } | ||||
113 | quote_sub | ||||
114 | 2 | 13µs | 2 | 120µs | "${into}::${name}" => $body, # spent 120µs making 2 calls to Sub::Quote::quote_sub, avg 60µs/call |
115 | $self->{captures}, $quote_opts||{} | ||||
116 | ; | ||||
117 | } | ||||
118 | |||||
119 | # spent 33µs (14+19) within Method::Generate::Constructor::_handle_subconstructor which was called 2 times, avg 16µs/call:
# 2 times (14µs+19µs) by Method::Generate::Constructor::generate_method at line 93, avg 16µs/call | ||||
120 | 2 | 900ns | my ($self, $into, $name) = @_; | ||
121 | 2 | 15µs | 2 | 19µs | if (my $gen = $self->{subconstructor_handler}) { # spent 19µs making 2 calls to Sub::Quote::quotify, avg 9µs/call |
122 | ' if ($class ne '.quotify($into).') {'."\n". | ||||
123 | $gen. | ||||
124 | ' }'."\n"; | ||||
125 | } else { | ||||
126 | '' | ||||
127 | } | ||||
128 | } | ||||
129 | |||||
130 | # spent 21µs within Method::Generate::Constructor::_cap_call which was called 11 times, avg 2µs/call:
# 11 times (21µs+0s) by Method::Generate::Constructor::_assign_new at line 181, avg 2µs/call | ||||
131 | 11 | 3µs | my ($self, $code, $captures) = @_; | ||
132 | 11 | 10µs | @{$self->{captures}}{keys %$captures} = values %$captures if $captures; | ||
133 | 11 | 18µs | $code; | ||
134 | } | ||||
135 | |||||
136 | sub _generate_args_via_buildargs { | ||||
137 | my ($self) = @_; | ||||
138 | q{ my $args = $class->BUILDARGS(@_);}."\n" | ||||
139 | .q{ die "BUILDARGS did not return a hashref" unless ref($args) eq 'HASH';} | ||||
140 | ."\n"; | ||||
141 | } | ||||
142 | |||||
143 | # inlined from Moo::Object - update that first. | ||||
144 | # spent 3µs within Method::Generate::Constructor::_generate_args which was called 2 times, avg 1µs/call:
# 2 times (3µs+0s) by Method::Generate::Constructor::generate_method at line 98, avg 1µs/call | ||||
145 | 2 | 700ns | my ($self) = @_; | ||
146 | 2 | 6µs | return <<'_EOA'; | ||
147 | my $args; | ||||
148 | if ( scalar @_ == 1 ) { | ||||
149 | unless ( defined $_[0] && ref $_[0] eq 'HASH' ) { | ||||
150 | die "Single parameters to new() must be a HASH ref" | ||||
151 | ." data => ". $_[0] ."\n"; | ||||
152 | } | ||||
153 | $args = { %{ $_[0] } }; | ||||
154 | } | ||||
155 | elsif ( @_ % 2 ) { | ||||
156 | die "The new() method for $class expects a hash reference or a" | ||||
157 | . " key/value list. You passed an odd number of arguments\n"; | ||||
158 | } | ||||
159 | else { | ||||
160 | $args = {@_}; | ||||
161 | } | ||||
162 | _EOA | ||||
163 | |||||
164 | } | ||||
165 | |||||
166 | # spent 588µs (129+459) within Method::Generate::Constructor::_assign_new which was called 2 times, avg 294µs/call:
# 2 times (129µs+459µs) by Method::Generate::Constructor::generate_method at line 102, avg 294µs/call | ||||
167 | 2 | 700ns | my ($self, $spec) = @_; | ||
168 | 2 | 2µs | 2 | 2µs | my $ag = $self->accessor_generator; # spent 2µs making 2 calls to Method::Generate::Constructor::accessor_generator, avg 750ns/call |
169 | 2 | 500ns | my %test; | ||
170 | 2 | 10µs | 2 | 2µs | NAME: foreach my $name (sort keys %$spec) { # spent 2µs making 2 calls to Method::Generate::Constructor::CORE:sort, avg 1µs/call |
171 | 13 | 3µs | my $attr_spec = $spec->{$name}; | ||
172 | 13 | 8µs | 2 | 4µs | next NAME unless defined($attr_spec->{init_arg}) # spent 4µs making 2 calls to Method::Generate::Accessor::has_eager_default, avg 2µs/call |
173 | or $ag->has_eager_default($name, $attr_spec); | ||||
174 | 11 | 6µs | $test{$name} = $attr_spec->{init_arg}; | ||
175 | } | ||||
176 | 11 | 12µs | 11 | 31µs | join '', map { # spent 31µs making 11 calls to Sub::Quote::quotify, avg 3µs/call |
177 | 2 | 25µs | 2 | 2µs | my $arg_key = quotify($test{$_}); # spent 2µs making 2 calls to Method::Generate::Constructor::CORE:sort, avg 900ns/call |
178 | 11 | 6µs | my $test = "exists \$args->{$arg_key}"; | ||
179 | 11 | 4µs | my $source = "\$args->{$arg_key}"; | ||
180 | 11 | 3µs | my $attr_spec = $spec->{$_}; | ||
181 | 11 | 25µs | 22 | 419µs | $self->_cap_call($ag->generate_populate_set( # spent 398µs making 11 calls to Method::Generate::Accessor::generate_populate_set, avg 36µs/call
# spent 21µs making 11 calls to Method::Generate::Constructor::_cap_call, avg 2µs/call |
182 | '$new', $_, $attr_spec, $source, $test, $test{$_}, | ||||
183 | )); | ||||
184 | } sort keys %test; | ||||
185 | } | ||||
186 | |||||
187 | # spent 68µs (60+7) within Method::Generate::Constructor::_check_required which was called 2 times, avg 34µs/call:
# 2 times (60µs+7µs) by Method::Generate::Constructor::generate_method at line 100, avg 34µs/call | ||||
188 | 2 | 800ns | my ($self, $spec) = @_; | ||
189 | my @required_init = | ||||
190 | map $spec->{$_}{init_arg}, | ||||
191 | grep { | ||||
192 | 15 | 53µs | 2 | 7µs | my %s = %{$spec->{$_}}; # ignore required if default or builder set # spent 7µs making 2 calls to Method::Generate::Constructor::CORE:sort, avg 4µs/call |
193 | 13 | 8µs | $s{required} and not($s{builder} or $s{default}) | ||
194 | } sort keys %$spec; | ||||
195 | 2 | 4µs | return '' unless @required_init; | ||
196 | 1 | 6µs | ' if (my @missing = grep !exists $args->{$_}, qw(' | ||
197 | .join(' ',@required_init).')) {'."\n" | ||||
198 | .q{ die "Missing required arguments: ".join(', ', sort @missing);}."\n" | ||||
199 | ." }\n"; | ||||
200 | } | ||||
201 | |||||
202 | 4 | 126µs | 4 | 887µs | # spent 430µs (12+419) within Method::Generate::Constructor::BEGIN@202 which was called:
# once (12µs+419µs) by DBIx::Class::Storage::BlockRunner::BEGIN@16 at line 202
# spent 47µs (9+38) within Method::Generate::Constructor::__ANON__[/usr/share/perl5/Method/Generate/Constructor.pm:202] which was called:
# once (9µs+38µs) by import::into at line 36 of Import/Into.pm # spent 430µs making 1 call to Method::Generate::Constructor::BEGIN@202
# spent 419µs making 1 call to Moo::import
# spent 24µs making 1 call to strictures::import
# spent 13µs making 1 call to Module::Runtime::use_module |
203 | # bootstrap our own constructor | ||||
204 | sub new { | ||||
205 | 1 | 200ns | my $class = shift; | ||
206 | 1 | 6µs | 1 | 5µs | bless $class->BUILDARGS(@_), $class; # spent 5µs making 1 call to Moo::Object::BUILDARGS |
207 | } | ||||
208 | 1 | 11µs | 2 | 201µs | Moo->_constructor_maker_for(__PACKAGE__) # spent 173µs making 1 call to Moo::_constructor_maker_for
# spent 28µs making 1 call to Method::Generate::Constructor::register_attribute_specs |
209 | ->register_attribute_specs( | ||||
210 | attribute_specs => { | ||||
211 | is => 'ro', | ||||
212 | reader => 'all_attribute_specs', | ||||
213 | }, | ||||
214 | accessor_generator => { is => 'ro' }, | ||||
215 | construction_string => { is => 'lazy' }, | ||||
216 | construction_builder => { is => 'bare' }, | ||||
217 | subconstructor_handler => { is => 'ro' }, | ||||
218 | package => { is => 'bare' }, | ||||
219 | ); | ||||
220 | |||||
221 | 1 | 4µs | 1; | ||
# spent 11µs within Method::Generate::Constructor::CORE:sort which was called 6 times, avg 2µs/call:
# 2 times (7µs+0s) by Method::Generate::Constructor::_check_required at line 192, avg 4µs/call
# 2 times (2µs+0s) by Method::Generate::Constructor::_assign_new at line 170, avg 1µs/call
# 2 times (2µs+0s) by Method::Generate::Constructor::_assign_new at line 177, avg 900ns/call | |||||
# spent 7µs within Method::Generate::Constructor::CORE:subst which was called 13 times, avg 569ns/call:
# 13 times (7µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 12, avg 569ns/call |