← 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:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Moo/HandleMoose.pm
StatementsExecuted 51 statements in 2.20ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
311307µs2.89msMoo::HandleMoose::::inject_fake_metaclass_for Moo::HandleMoose::inject_fake_metaclass_for
11127µs84µsMoo::HandleMoose::::BEGIN@3 Moo::HandleMoose::BEGIN@3
11120µs20µsMoo::HandleMoose::::inject_all Moo::HandleMoose::inject_all
11112µs24µsMoo::HandleMoose::::BEGIN@202 Moo::HandleMoose::BEGIN@202
11112µs79µsMoo::HandleMoose::::BEGIN@4 Moo::HandleMoose::BEGIN@4
11111µs22µsMoo::HandleMoose::::BEGIN@16 Moo::HandleMoose::BEGIN@16
1119µs36µsMoo::HandleMoose::::BEGIN@5 Moo::HandleMoose::BEGIN@5
1119µs28µsMoo::HandleMoose::::import Moo::HandleMoose::import
2115µs5µsMoo::HandleMoose::::maybe_reinject_fake_metaclass_for Moo::HandleMoose::maybe_reinject_fake_metaclass_for
0000s0sMoo::HandleMoose::FakeConstructor::::_uninlined_bodyMoo::HandleMoose::FakeConstructor::_uninlined_body
0000s0sMoo::HandleMoose::::__ANON__[:131] Moo::HandleMoose::__ANON__[:131]
0000s0sMoo::HandleMoose::::__ANON__[:143] Moo::HandleMoose::__ANON__[:143]
0000s0sMoo::HandleMoose::::__ANON__[:146] Moo::HandleMoose::__ANON__[:146]
0000s0sMoo::HandleMoose::::inject_real_metaclass_for Moo::HandleMoose::inject_real_metaclass_for
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moo::HandleMoose;
2
3340µs3142µs
# spent 84µs (27+57) within Moo::HandleMoose::BEGIN@3 which was called: # once (27µs+57µs) by Foo::Moo::BEGIN@116 at line 3
use strictures 1;
# spent 84µs making 1 call to Moo::HandleMoose::BEGIN@3 # spent 41µs making 1 call to strictures::import # spent 16µs making 1 call to strictures::VERSION
4235µs2147µs
# spent 79µs (12+68) within Moo::HandleMoose::BEGIN@4 which was called: # once (12µs+68µs) by Foo::Moo::BEGIN@116 at line 4
use Moo::_Utils;
# spent 79µs making 1 call to Moo::HandleMoose::BEGIN@4 # spent 68µs making 1 call to Exporter::import
52125µs262µs
# spent 36µs (9+27) within Moo::HandleMoose::BEGIN@5 which was called: # once (9µs+27µs) by Foo::Moo::BEGIN@116 at line 5
use B qw(perlstring);
# spent 36µs making 1 call to Moo::HandleMoose::BEGIN@5 # spent 27µs making 1 call to Exporter::import
6
71200nsour %TYPE_MAP;
8
91100nsour $SETUP_DONE;
10
1135µs120µs
# spent 28µs (9+20) within Moo::HandleMoose::import which was called: # once (9µs+20µs) by Foo::Moo::BEGIN@116 at line 17 of Moo/sification.pm
sub import { return if $SETUP_DONE; inject_all(); $SETUP_DONE = 1; }
# spent 20µs making 1 call to Moo::HandleMoose::inject_all
12
13
# spent 20µs within Moo::HandleMoose::inject_all which was called: # once (20µs+0s) by Moo::HandleMoose::import at line 11
sub inject_all {
141500ns require Class::MOP;
15 inject_fake_metaclass_for($_)
1641.50ms234µs
# spent 22µs (11+11) within Moo::HandleMoose::BEGIN@16 which was called: # once (11µs+11µs) by Foo::Moo::BEGIN@116 at line 16
for grep $_ ne 'Moo::Object', do { no warnings 'once'; keys %Moo::MAKERS };
# spent 22µs making 1 call to Moo::HandleMoose::BEGIN@16 # spent 12µs making 1 call to warnings::unimport
1711µs inject_fake_metaclass_for($_) for keys %Moo::Role::INFO;
181300ns require Moose::Meta::Method::Constructor;
19120µs @Moo::HandleMoose::FakeConstructor::ISA = 'Moose::Meta::Method::Constructor';
20}
21
22
# spent 5µs within Moo::HandleMoose::maybe_reinject_fake_metaclass_for which was called 2 times, avg 2µs/call: # 2 times (5µs+0s) by Moo::_maybe_reset_handlemoose at line 113 of Moo.pm, avg 2µs/call
sub maybe_reinject_fake_metaclass_for {
232600ns my ($name) = @_;
242400ns our %DID_INJECT;
2527µs if (delete $DID_INJECT{$name}) {
26 unless ($Moo::Role::INFO{$name}) {
27 Moo->_constructor_maker_for($name)->install_delayed;
28 }
29 inject_fake_metaclass_for($name);
30 }
31}
32
33
# spent 2.89ms (307µs+2.58) within Moo::HandleMoose::inject_fake_metaclass_for which was called 3 times, avg 964µs/call: # 3 times (307µs+2.58ms) by Moo::import at line 75 of Moo.pm, avg 964µs/call
sub inject_fake_metaclass_for {
3431µs my ($name) = @_;
3531µs require Class::MOP;
363260µs require Moo::HandleMoose::FakeMetaClass;
37312µs37µs Class::MOP::store_metaclass_by_name(
# spent 7µs making 3 calls to Class::MOP::store_metaclass_by_name, avg 2µs/call
38 $name, bless({ name => $name }, 'Moo::HandleMoose::FakeMetaClass')
39 );
4032µs require Moose::Util::TypeConstraints;
41310µs if ($Moo::Role::INFO{$name}) {
42 Moose::Util::TypeConstraints::find_or_create_does_type_constraint($name);
43 } else {
4436µs32.58ms Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($name);
# spent 2.58ms making 3 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 859µs/call
45 }
46}
47
48{
491500ns package Moo::HandleMoose::FakeConstructor;
50
51 sub _uninlined_body { \&Moose::Object::new }
52}
53
54
55sub inject_real_metaclass_for {
56 my ($name) = @_;
57 our %DID_INJECT;
58 return Class::MOP::get_metaclass_by_name($name) if $DID_INJECT{$name};
59 require Moose; require Moo; require Moo::Role; require Scalar::Util;
60 Class::MOP::remove_metaclass_by_name($name);
61 my ($am_role, $meta, $attr_specs, $attr_order) = do {
62 if (my $info = $Moo::Role::INFO{$name}) {
63 my @attr_info = @{$info->{attributes}||[]};
64 (1, Moose::Meta::Role->initialize($name),
65 { @attr_info },
66 [ @attr_info[grep !($_ % 2), 0..$#attr_info] ]
67 )
68 } elsif ( my $cmaker = Moo->_constructor_maker_for($name) ) {
69 my $specs = $cmaker->all_attribute_specs;
70 (0, Moose::Meta::Class->initialize($name), $specs,
71 [ sort { $specs->{$a}{index} <=> $specs->{$b}{index} } keys %$specs ]
72 );
73 } else {
74 # This codepath is used if $name does not exist in $Moo::MAKERS
75 (0, Moose::Meta::Class->initialize($name), {}, [] )
76 }
77 };
78
79 for my $spec (values %$attr_specs) {
80 if (my $inflators = delete $spec->{moosify}) {
81 $_->($spec) for @$inflators;
82 }
83 }
84
85 my %methods = %{Role::Tiny->_concrete_methods_of($name)};
86
87 # if stuff gets added afterwards, _maybe_reset_handlemoose should
88 # trigger the recreation of the metaclass but we need to ensure the
89 # Role::Tiny cache is cleared so we don't confuse Moo itself.
90 if (my $info = $Role::Tiny::INFO{$name}) {
91 delete $info->{methods};
92 }
93
94 # needed to ensure the method body is stable and get things named
95 Sub::Defer::undefer_sub($_) for grep defined, values %methods;
96 my @attrs;
97 {
98 # This local is completely not required for roles but harmless
99 local @{_getstash($name)}{keys %methods};
100 my %seen_name;
101 foreach my $name (@$attr_order) {
102 $seen_name{$name} = 1;
103 my %spec = %{$attr_specs->{$name}};
104 my %spec_map = (
105 map { $_->name => $_->init_arg||$_->name }
106 (
107 (grep { $_->has_init_arg }
108 $meta->attribute_metaclass->meta->get_all_attributes),
109 grep { exists($_->{init_arg}) ? defined($_->init_arg) : 1 }
110 map {
111 my $meta = Moose::Util::resolve_metatrait_alias('Attribute', $_)
112 ->meta;
113 map $meta->get_attribute($_), $meta->get_attribute_list
114 } @{$spec{traits}||[]}
115 )
116 );
117 # have to hard code this because Moose's role meta-model is lacking
118 $spec_map{traits} ||= 'traits';
119
120 $spec{is} = 'ro' if $spec{is} eq 'lazy' or $spec{is} eq 'rwp';
121 my $coerce = $spec{coerce};
122 if (my $isa = $spec{isa}) {
123 my $tc = $spec{isa} = do {
124 if (my $mapped = $TYPE_MAP{$isa}) {
125 my $type = $mapped->();
126 Scalar::Util::blessed($type) && $type->isa("Moose::Meta::TypeConstraint")
127 or die "error inflating attribute '$name' for package '$_[0]': \$TYPE_MAP{$isa} did not return a valid type constraint'";
128 $coerce ? $type->create_child_type(name => $type->name) : $type;
129 } else {
130 Moose::Meta::TypeConstraint->new(
131 constraint => sub { eval { &$isa; 1 } }
132 );
133 }
134 };
135 if ($coerce) {
136 $tc->coercion(Moose::Meta::TypeCoercion->new)
137 ->_compiled_type_coercion($coerce);
138 $spec{coerce} = 1;
139 }
140 } elsif ($coerce) {
141 my $attr = perlstring($name);
142 my $tc = Moose::Meta::TypeConstraint->new(
143 constraint => sub { die "This is not going to work" },
144 inlined => sub {
145 'my $r = $_[42]{'.$attr.'}; $_[42]{'.$attr.'} = 1; $r'
146 },
147 );
148 $tc->coercion(Moose::Meta::TypeCoercion->new)
149 ->_compiled_type_coercion($coerce);
150 $spec{isa} = $tc;
151 $spec{coerce} = 1;
152 }
153 %spec =
154 map { $spec_map{$_} => $spec{$_} }
155 grep { exists $spec_map{$_} }
156 keys %spec;
157 push @attrs, $meta->add_attribute($name => %spec);
158 }
159 foreach my $mouse (do { our %MOUSE; @{$MOUSE{$name}||[]} }) {
160 foreach my $attr ($mouse->get_all_attributes) {
161 my %spec = %{$attr};
162 delete @spec{qw(
163 associated_class associated_methods __METACLASS__
164 provides curries
165 )};
166 my $name = delete $spec{name};
167 next if $seen_name{$name}++;
168 push @attrs, $meta->add_attribute($name => %spec);
169 }
170 }
171 }
172 for my $meth_name (keys %methods) {
173 my $meth_code = $methods{$meth_name};
174 $meta->add_method($meth_name, $meth_code) if $meth_code;
175 }
176
177 if ($am_role) {
178 my $info = $Moo::Role::INFO{$name};
179 $meta->add_required_methods(@{$info->{requires}});
180 foreach my $modifier (@{$info->{modifiers}}) {
181 my ($type, @args) = @$modifier;
182 my $code = pop @args;
183 $meta->${\"add_${type}_method_modifier"}($_, $code) for @args;
184 }
185 } else {
186 foreach my $attr (@attrs) {
187 foreach my $method (@{$attr->associated_methods}) {
188 $method->{body} = $name->can($method->name);
189 }
190 }
191 bless(
192 $meta->find_method_by_name('new'),
193 'Moo::HandleMoose::FakeConstructor',
194 );
195 # a combination of Moo and Moose may bypass a Moo constructor but still
196 # use a Moo DEMOLISHALL. We need to make sure this is loaded before
197 # global destruction.
198 require Method::Generate::DemolishAll;
199 }
200 $meta->add_role(Class::MOP::class_of($_))
201 for grep !/\|/ && $_ ne $name, # reject Foo|Bar and same-role-as-self
2022169µs235µs
# spent 24µs (12+12) within Moo::HandleMoose::BEGIN@202 which was called: # once (12µs+12µs) by Foo::Moo::BEGIN@116 at line 202
do { no warnings 'once'; keys %{$Role::Tiny::APPLIED_TO{$name}} };
# spent 24µs making 1 call to Moo::HandleMoose::BEGIN@202 # spent 12µs making 1 call to warnings::unimport
203 $DID_INJECT{$name} = 1;
204 $meta;
205}
206
20714µs1;