← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:42 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Method/Generate/Constructor.pm
StatementsExecuted 271 statements in 2.16ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
311132µs846µsMethod::Generate::Constructor::::generate_methodMethod::Generate::Constructor::generate_method
311129µs472µsMethod::Generate::Constructor::::_assign_newMethod::Generate::Constructor::_assign_new
63267µs71µsMethod::Generate::Constructor::::register_attribute_specsMethod::Generate::Constructor::register_attribute_specs
31146µs49µsMethod::Generate::Constructor::::_check_requiredMethod::Generate::Constructor::_check_required
31133µs120µsMethod::Generate::Constructor::::install_delayedMethod::Generate::Constructor::install_delayed
11127µs107µsMethod::Generate::Constructor::::BEGIN@3Method::Generate::Constructor::BEGIN@3
31125µs2.57msMethod::Generate::Constructor::::__ANON__[:64]Method::Generate::Constructor::__ANON__[:64]
31125µs29µsMethod::Generate::Constructor::::_handle_subconstructorMethod::Generate::Constructor::_handle_subconstructor
71122µs22µsMethod::Generate::Constructor::::_cap_callMethod::Generate::Constructor::_cap_call
31122µs28µsMethod::Generate::Constructor::::_build_construction_stringMethod::Generate::Constructor::_build_construction_string
11116µs44µsMethod::Generate::Constructor::::BEGIN@7Method::Generate::Constructor::BEGIN@7
31114µs42µsMethod::Generate::Constructor::::construction_stringMethod::Generate::Constructor::construction_string
11113µs62µsMethod::Generate::Constructor::::BEGIN@4Method::Generate::Constructor::BEGIN@4
11112µs49µsMethod::Generate::Constructor::::BEGIN@6Method::Generate::Constructor::BEGIN@6
11112µs100µsMethod::Generate::Constructor::::BEGIN@5Method::Generate::Constructor::BEGIN@5
11111µs65µsMethod::Generate::Constructor::::BEGIN@8Method::Generate::Constructor::BEGIN@8
11110µs1.07msMethod::Generate::Constructor::::BEGIN@186Method::Generate::Constructor::BEGIN@186
9316µs6µsMethod::Generate::Constructor::::CORE:sortMethod::Generate::Constructor::CORE:sort (opcode)
6216µs6µsMethod::Generate::Constructor::::accessor_generatorMethod::Generate::Constructor::accessor_generator
3116µs6µsMethod::Generate::Constructor::::_generate_argsMethod::Generate::Constructor::_generate_args
7114µs4µsMethod::Generate::Constructor::::CORE:substMethod::Generate::Constructor::CORE:subst (opcode)
0000s0sMethod::Generate::Constructor::::_generate_args_via_buildargsMethod::Generate::Constructor::_generate_args_via_buildargs
0000s0sMethod::Generate::Constructor::::all_attribute_specsMethod::Generate::Constructor::all_attribute_specs
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
3343µs3188µ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
use strictures 1;
# 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
4250µs2111µ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
use Sub::Quote;
# spent 62µs making 1 call to Method::Generate::Constructor::BEGIN@4 # spent 49µs making 1 call to Exporter::import
5246µs2189µ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
use base qw(Moo::Object);
# spent 100µs making 1 call to Method::Generate::Constructor::BEGIN@5 # spent 89µs making 1 call to base::import
6241µs286µ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
use Sub::Defer;
# spent 49µs making 1 call to Method::Generate::Constructor::BEGIN@6 # spent 37µs making 1 call to Exporter::import
7238µs273µ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
use B 'perlstring';
# spent 44µs making 1 call to Method::Generate::Constructor::BEGIN@7 # spent 29µs making 1 call to Exporter::import
821.30ms2119µ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
use Moo::_Utils qw(_getstash);
# 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
sub register_attribute_specs {
1165µs my ($self, @new_specs) = @_;
12610µs my $specs = $self->{attribute_specs}||={};
13613µs while (my ($name, $new_spec) = splice @new_specs, 0, 2) {
14720µs74µ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 }
3076µs $new_spec->{index} = scalar keys %$specs
31 unless defined $new_spec->{index};
3273µs $specs->{$name} = $new_spec;
33 }
34618µs $self;
35}
36
37sub 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
sub accessor_generator {
42617µ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
sub construction_string {
463600ns my ($self) = @_;
47311µs328µ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
sub _build_construction_string {
52315µs66µ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
sub install_delayed {
5831µs my ($self) = @_;
5934µ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
defer_sub "${package}::new" => sub {
61318µs62.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 )
64318µs387µs };
# spent 87µs making 3 calls to Sub::Defer::defer_sub, avg 29µs/call
6537µ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
sub generate_method {
6931µs my ($self, $into, $name, $spec, $quote_opts) = @_;
7039µs foreach my $no_init (grep !exists($spec->{$_}{init_arg}), keys %$spec) {
7175µs $spec->{$no_init}{init_arg} = $no_init;
72 }
7333µs local $self->{captures} = {};
743900ns my $body = ' my $class = shift;'."\n"
75 .' $class = ref($class) if ref($class);'."\n";
7635µs329µs $body .= $self->_handle_subconstructor($into, $name);
# spent 29µs making 3 calls to Method::Generate::Constructor::_handle_subconstructor, avg 10µs/call
77322µs312µs my $into_buildargs = $into->can('BUILDARGS');
# spent 12µs making 3 calls to UNIVERSAL::can, avg 4µs/call
7834µs if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) {
79 $body .= $self->_generate_args_via_buildargs;
80 } else {
8135µs36µs $body .= $self->_generate_args;
# spent 6µs making 3 calls to Method::Generate::Constructor::_generate_args, avg 2µs/call
82 }
8334µs349µs $body .= $self->_check_required($spec);
# spent 49µs making 3 calls to Method::Generate::Constructor::_check_required, avg 16µs/call
84312µs342µs $body .= ' my $new = '.$self->construction_string.";\n";
# spent 42µs making 3 calls to Method::Generate::Constructor::construction_string, avg 14µs/call
8536µs3472µs $body .= $self->_assign_new($spec);
# spent 472µs making 3 calls to Method::Generate::Constructor::_assign_new, avg 157µs/call
86320µs312µ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 }
923600ns $body .= ' return $new;'."\n";
93314µs37µ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
98318µs386µ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
sub _handle_subconstructor {
10431µs my ($self, $into, $name) = @_;
105333µs35µ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
sub _cap_call {
11574µs my ($self, $code, $captures) = @_;
11678µs @{$self->{captures}}{keys %$captures} = values %$captures if $captures;
117717µs $code;
118}
119
120sub _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
sub _generate_args {
1293600ns my ($self) = @_;
13039µ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
sub _assign_new {
1513800ns my ($self, $spec) = @_;
15232µs33µs my $ag = $self->accessor_generator;
# spent 3µs making 3 calls to Method::Generate::Constructor::accessor_generator, avg 900ns/call
1533300ns my %test;
154316µs32µs NAME: foreach my $name (sort keys %$spec) {
# spent 2µs making 3 calls to Method::Generate::Constructor::CORE:sort, avg 600ns/call
15572µs my $attr_spec = $spec->{$name};
15671µs next NAME unless defined($attr_spec->{init_arg})
157 or $ag->has_eager_default($name, $attr_spec);
15876µs $test{$name} = $attr_spec->{init_arg};
159 }
160727µs710µs join '', map {
# spent 10µs making 7 calls to B::perlstring, avg 1µs/call
161333µs31µs my $arg_key = perlstring($test{$_});
# spent 1µs making 3 calls to Method::Generate::Constructor::CORE:sort, avg 433ns/call
16273µs my $test = "exists \$args->{$arg_key}";
16373µs my $source = "\$args->{$arg_key}";
16472µs my $attr_spec = $spec->{$_};
165718µs14328µ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
sub _check_required {
1723800ns my ($self, $spec) = @_;
173 my @required_init =
174 map $spec->{$_}{init_arg},
175 grep {
1761035µs33µ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
17776µs $s{required} and not($s{builder} or $s{default})
178 } sort keys %$spec;
179310µ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
186287µs22.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
use Moo;
# spent 1.07ms making 1 call to Method::Generate::Constructor::BEGIN@186 # spent 1.06ms making 1 call to Moo::import
187113µs232µsMoo->_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
19818µs1;
 
# 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
sub Method::Generate::Constructor::CORE:sort; # opcode
# 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
sub Method::Generate::Constructor::CORE:subst; # opcode