← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:45:08 2010
Reported on Wed Nov 17 22:10:57 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Method/Constructor.pm
StatementsExecuted 6061 statements in 88.0ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1301129.6ms90.3msMoose::Meta::Method::Constructor::::_generate_slot_initializerMoose::Meta::Method::Constructor::_generate_slot_initializer
421117.5ms357msMoose::Meta::Method::Constructor::::_initialize_bodyMoose::Meta::Method::Constructor::_initialize_body
170317.39ms39.0msMoose::Meta::Method::Constructor::::_generate_slot_assignmentMoose::Meta::Method::Constructor::_generate_slot_assignment
42116.70ms10.1msMoose::Meta::Method::Constructor::::_generate_triggersMoose::Meta::Method::Constructor::_generate_triggers
42115.70ms363msMoose::Meta::Method::Constructor::::newMoose::Meta::Method::Constructor::new
42114.20ms111msMoose::Meta::Method::Constructor::::_generate_slot_initializersMoose::Meta::Method::Constructor::_generate_slot_initializers
42113.73ms53.3msMoose::Meta::Method::Constructor::::_generate_BUILDARGSMoose::Meta::Method::Constructor::_generate_BUILDARGS
64212.86ms4.19msMoose::Meta::Method::Constructor::::_generate_type_constraint_checkMoose::Meta::Method::Constructor::_generate_type_constraint_check
42222.15ms50.8msMoose::Meta::Method::Constructor::::_generate_BUILDALLMoose::Meta::Method::Constructor::_generate_BUILDALL
26211.90ms4.18msMoose::Meta::Method::Constructor::::_generate_type_constraint_and_coercionMoose::Meta::Method::Constructor::_generate_type_constraint_and_coercion
42111.80ms16.1msMoose::Meta::Method::Constructor::::_generate_instanceMoose::Meta::Method::Constructor::_generate_instance
42111.44ms54.7msMoose::Meta::Method::Constructor::::_generate_paramsMoose::Meta::Method::Constructor::_generate_params
4211610µs610µsMoose::Meta::Method::Constructor::::_generate_fallback_constructorMoose::Meta::Method::Constructor::_generate_fallback_constructor
11175µs94µsMoose::Meta::Method::Constructor::::BEGIN@4Moose::Meta::Method::Constructor::BEGIN@4
11141µs469µsMoose::Meta::Method::Constructor::::BEGIN@13Moose::Meta::Method::Constructor::BEGIN@13
11139µs323µsMoose::Meta::Method::Constructor::::BEGIN@8Moose::Meta::Method::Constructor::BEGIN@8
11137µs106µsMoose::Meta::Method::Constructor::::BEGIN@5Moose::Meta::Method::Constructor::BEGIN@5
11118µs18µsMoose::Meta::Method::Constructor::::BEGIN@7Moose::Meta::Method::Constructor::BEGIN@7
0000s0sMoose::Meta::Method::Constructor::::_generate_type_coercionMoose::Meta::Method::Constructor::_generate_type_coercion
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::Method::Constructor;
3
43100µs2112µs
# spent 94µs (75+19) within Moose::Meta::Method::Constructor::BEGIN@4 which was called: # once (75µs+19µs) by Moose::Meta::Class::BEGIN@23 at line 4
use strict;
# spent 94µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@4 # spent 19µs making 1 call to strict::import
5392µs2175µs
# spent 106µs (37+69) within Moose::Meta::Method::Constructor::BEGIN@5 which was called: # once (37µs+69µs) by Moose::Meta::Class::BEGIN@23 at line 5
use warnings;
# spent 106µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@5 # spent 69µs making 1 call to warnings::import
6
73112µs118µs
# spent 18µs within Moose::Meta::Method::Constructor::BEGIN@7 which was called: # once (18µs+0s) by Moose::Meta::Class::BEGIN@23 at line 7
use Carp ();
# spent 18µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@7
83233µs2608µs
# spent 323µs (39+285) within Moose::Meta::Method::Constructor::BEGIN@8 which was called: # once (39µs+285µs) by Moose::Meta::Class::BEGIN@23 at line 8
use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
# spent 323µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@8 # spent 285µs making 1 call to Exporter::import
9
10132µsour $VERSION = '1.19';
1113µsour $AUTHORITY = 'cpan:STEVAN';
12
131428µs
# spent 469µs (41+429) within Moose::Meta::Method::Constructor::BEGIN@13 which was called: # once (41µs+429µs) by Moose::Meta::Class::BEGIN@23 at line 14
use base 'Moose::Meta::Method',
# spent 428µs making 1 call to base::import
1435.65ms1469µs 'Class::MOP::Method::Constructor';
# spent 469µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@13
15
16
# spent 363ms (5.70+358) within Moose::Meta::Method::Constructor::new which was called 42 times, avg 8.65ms/call: # 42 times (5.70ms+358ms) by Class::MOP::Class::_inline_constructor at line 1330 of Class/MOP/Class.pm, avg 8.65ms/call
sub new {
173785.99ms my $class = shift;
18 my %options = @_;
19
20 my $meta = $options{metaclass};
21
22 (ref $options{options} eq 'HASH')
23 || $class->throw_error("You must pass a hash of options", data => $options{options});
24
25 ($options{package_name} && $options{name})
26 || $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT");
27
28 my $self = bless {
29 'body' => undef,
30 'package_name' => $options{package_name},
31 'name' => $options{name},
32 'options' => $options{options},
33 'associated_metaclass' => $meta,
34 '_expected_method_class' => $options{_expected_method_class} || 'Moose::Object',
35 } => $class;
36
37 # we don't want this creating
38 # a cycle in the code, if not
39 # needed
4042327µs weaken($self->{'associated_metaclass'});
# spent 327µs making 42 calls to Scalar::Util::weaken, avg 8µs/call
41
4242357ms $self->_initialize_body;
# spent 357ms making 42 calls to Moose::Meta::Method::Constructor::_initialize_body, avg 8.51ms/call
43
44 return $self;
45}
46
47## method
48
49
# spent 357ms (17.5+340) within Moose::Meta::Method::Constructor::_initialize_body which was called 42 times, avg 8.51ms/call: # 42 times (17.5ms+340ms) by Moose::Meta::Method::Constructor::new at line 42, avg 8.51ms/call
sub _initialize_body {
5092411.1ms my $self = shift;
51 # TODO:
52 # the %options should also include a both
53 # a call 'initializer' and call 'SUPER::'
54 # options, which should cover approx 90%
55 # of the possible use cases (even if it
56 # requires some adaption on the part of
57 # the author, after all, nothing is free)
58 my $source = 'sub {';
59 $source .= "\n" . 'my $_instance = shift;';
60
61 $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;';
62
6384683µs $source .= "\n" . "if (\$class ne '" . $self->associated_metaclass->name
# spent 463µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 11µs/call # spent 220µs making 42 calls to Class::MOP::Package::name, avg 5µs/call
64 . "') {";
6542610µs $source .= "\n return "
# spent 610µs making 42 calls to Moose::Meta::Method::Constructor::_generate_fallback_constructor, avg 15µs/call
66 . $self->_generate_fallback_constructor('$class') . ";";
67 $source .= "\n}\n";
68
694254.7ms $source .= $self->_generate_params('$params', '$class');
# spent 54.7ms making 42 calls to Moose::Meta::Method::Constructor::_generate_params, avg 1.30ms/call
704216.1ms $source .= $self->_generate_instance('$instance', '$class');
# spent 16.1ms making 42 calls to Moose::Meta::Method::Constructor::_generate_instance, avg 383µs/call
7142111ms $source .= $self->_generate_slot_initializers;
# spent 111ms making 42 calls to Moose::Meta::Method::Constructor::_generate_slot_initializers, avg 2.65ms/call
72
734210.1ms $source .= $self->_generate_triggers();
# spent 10.1ms making 42 calls to Moose::Meta::Method::Constructor::_generate_triggers, avg 241µs/call
744258.5ms $source .= ";\n" . $self->_generate_BUILDALL();
# spent 48.2ms making 37 calls to Class::MOP::Class::__ANON__::SERIAL::2::_generate_BUILDALL, avg 1.30ms/call # spent 10.3ms making 5 calls to Moose::Meta::Method::Constructor::_generate_BUILDALL, avg 2.07ms/call
75
76 $source .= ";\nreturn \$instance";
77 $source .= ";\n" . '}';
7842461µs warn $source if $self->options->{debug};
# spent 461µs making 42 calls to Class::MOP::Method::Constructor::options, avg 11µs/call
79
80 # We need to check if the attribute ->can('type_constraint')
81 # since we may be trying to immutabilize a Moose meta class,
82 # which in turn has attributes which are Class::MOP::Attribute
83 # objects, rather than Moose::Meta::Attribute. And
84 # Class::MOP::Attribute attributes have no type constraints.
85 # However we need to make sure we leave an undef value there
86 # because the inlined code is using the index of the attributes
87 # to determine where to find the type constraint
88
8942487µs my $attrs = $self->_attributes;
# spent 487µs making 42 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call
90
911901.55ms my @type_constraints = map {
# spent 786µs making 130 calls to UNIVERSAL::can, avg 6µs/call # spent 761µs making 60 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 13µs/call
921302.76ms $_->can('type_constraint') ? $_->type_constraint : undef
93 } @$attrs;
94
95606.83ms my @type_constraint_bodies = map {
# spent 6.61ms making 46 calls to MooseX::Types::TypeDecorator::AUTOLOAD, avg 144µs/call # spent 225µs making 14 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 16µs/call
961301.08ms defined $_ ? $_->_compiled_type_constraint : undef;
97 } @type_constraints;
98
991301.54ms1301.87ms my $defaults = [map { $_->default } @$attrs];
# spent 1.87ms making 130 calls to Class::MOP::Mixin::AttributeCore::default, avg 14µs/call
100
1014276.4ms my ( $code, $e ) = $self->_compile_code(
# spent 76.4ms making 42 calls to Class::MOP::Method::Generated::_compile_code, avg 1.82ms/call
102 code => $source,
103 environment => {
104 '$meta' => \$self,
105 '$attrs' => \$attrs,
106 '$defaults' => \$defaults,
107 '@type_constraints' => \@type_constraints,
108 '@type_constraint_bodies' => \@type_constraint_bodies,
109 },
110 );
111
112 $self->throw_error(
113 "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e",
114 error => $e, data => $source )
115 if $e;
116
117 $self->{'body'} = $code;
118}
119
120
# spent 610µs within Moose::Meta::Method::Constructor::_generate_fallback_constructor which was called 42 times, avg 15µs/call: # 42 times (610µs+0s) by Moose::Meta::Method::Constructor::_initialize_body at line 65, avg 15µs/call
sub _generate_fallback_constructor {
12184760µs my ( $self, $class_var ) = @_;
122 "${class_var}->Moose::Object::new(\@_)";
123}
124
125
# spent 54.7ms (1.44+53.3) within Moose::Meta::Method::Constructor::_generate_params which was called 42 times, avg 1.30ms/call: # 42 times (1.44ms+53.3ms) by Moose::Meta::Method::Constructor::_initialize_body at line 69, avg 1.30ms/call
sub _generate_params {
126841.47ms my ( $self, $var, $class_var ) = @_;
1274253.3ms "my $var = " . $self->_generate_BUILDARGS( $class_var, '@_' ) . ";\n";
# spent 53.3ms making 42 calls to Moose::Meta::Method::Constructor::_generate_BUILDARGS, avg 1.27ms/call
128}
129
130
# spent 16.1ms (1.80+14.3) within Moose::Meta::Method::Constructor::_generate_instance which was called 42 times, avg 383µs/call: # 42 times (1.80ms+14.3ms) by Moose::Meta::Method::Constructor::_initialize_body at line 70, avg 383µs/call
sub _generate_instance {
131841.60ms my ( $self, $var, $class_var ) = @_;
1328414.3ms "my $var = "
# spent 13.9ms making 42 calls to Class::MOP::Class::inline_create_instance, avg 330µs/call # spent 412µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 10µs/call
133 . $self->associated_metaclass->inline_create_instance($class_var) . ";\n";
134}
135
136
# spent 111ms (4.20+107) within Moose::Meta::Method::Constructor::_generate_slot_initializers which was called 42 times, avg 2.65ms/call: # 42 times (4.20ms+107ms) by Moose::Meta::Method::Constructor::_initialize_body at line 71, avg 2.65ms/call
sub _generate_slot_initializers {
137842.20ms my ($self) = @_;
13813090.3ms return (join ";\n" => map {
# spent 90.3ms making 130 calls to Moose::Meta::Method::Constructor::_generate_slot_initializer, avg 694µs/call
139 $self->_generate_slot_initializer($_)
1401301.52ms4216.8ms } 0 .. (@{$self->_attributes} - 1)) . ";\n";
# spent 16.8ms making 42 calls to Class::MOP::Method::Constructor::_attributes, avg 401µs/call
141}
142
143
# spent 53.3ms (3.73+49.6) within Moose::Meta::Method::Constructor::_generate_BUILDARGS which was called 42 times, avg 1.27ms/call: # 42 times (3.73ms+49.6ms) by Moose::Meta::Method::Constructor::_generate_params at line 127, avg 1.27ms/call
sub _generate_BUILDARGS {
1441263.58ms my ( $self, $class, $args ) = @_;
145
1468448.5ms my $buildargs = $self->associated_metaclass->find_method_by_name("BUILDARGS");
# spent 48.2ms making 42 calls to Class::MOP::Class::find_method_by_name, avg 1.15ms/call # spent 350µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 8µs/call
147
148811.04ms if ( $args eq '@_'
# spent 823µs making 42 calls to Moose::Meta::Method::_inline_throw_error, avg 20µs/call # spent 212µs making 39 calls to Class::MOP::Method::body, avg 5µs/call
149 and ( !$buildargs or $buildargs->body == \&Moose::Object::BUILDARGS )
150 ) {
151
152 # This is the same logic as Moose::Object::BUILDARGS
153 return sprintf( <<'EOF', $self->_inline_throw_error( q{'Single parameters to new() must be a HASH ref'}, 'data => $_[0]' ) );
154do {
155 my $params;
156 if ( scalar @_ == 1 ) {
157 unless ( defined $_[0] && ref $_[0] eq 'HASH' ) {
158 %s
159 }
160 $params = { %%{ $_[0] } };
161 }
162 elsif ( @_ %% 2 ) {
163 Carp::carp(
164 "The new() method for $class expects a hash reference or a key/value list."
165 . " You passed an odd number of arguments" );
166 $params = { @_, undef };
167 }
168 else {
169 $params = {@_};
170 }
171 $params
172};
173EOF
174 ;
175 }
176 else {
177 return $class . "->BUILDARGS($args)";
178 }
179}
180
181
# spent 50.8ms (2.15+48.6) within Moose::Meta::Method::Constructor::_generate_BUILDALL which was called 42 times, avg 1.21ms/call: # 37 times (1.89ms+38.6ms) by Class::MOP::Class:::around at line 18 of MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm, avg 1.09ms/call # 5 times (268µs+10.1ms) by Moose::Meta::Method::Constructor::_initialize_body at line 74, avg 2.07ms/call
sub _generate_BUILDALL {
1821682.03ms my $self = shift;
183 my @BUILD_calls;
1848448.6ms foreach my $method (reverse $self->associated_metaclass->find_all_methods_by_name('BUILD')) {
# spent 48.3ms making 42 calls to Class::MOP::Class::find_all_methods_by_name, avg 1.15ms/call # spent 390µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 9µs/call
185114µs push @BUILD_calls => '$instance->' . $method->{class} . '::BUILD($params)';
186 }
187 return join ";\n" => @BUILD_calls;
188}
189
190
# spent 10.1ms (6.70+3.44) within Moose::Meta::Method::Constructor::_generate_triggers which was called 42 times, avg 241µs/call: # 42 times (6.70ms+3.44ms) by Moose::Meta::Method::Constructor::_initialize_body at line 73, avg 241µs/call
sub _generate_triggers {
1911681.90ms my $self = shift;
192 my @trigger_calls;
19342519µs foreach my $i ( 0 .. $#{ $self->_attributes } ) {
# spent 519µs making 42 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call
1942604.82ms1301.44ms my $attr = $self->_attributes->[$i];
# spent 1.44ms making 130 calls to Class::MOP::Method::Constructor::_attributes, avg 11µs/call
195
1961901.49ms next unless $attr->can('has_trigger') && $attr->has_trigger;
# spent 872µs making 130 calls to UNIVERSAL::can, avg 7µs/call # spent 616µs making 60 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 10µs/call
197
198 my $init_arg = $attr->init_arg;
199
200 next unless defined $init_arg;
201
202 push @trigger_calls => '(exists $params->{\''
203 . $init_arg
204 . '\'}) && do {'
205 . "\n "
206 . '$attrs->['
207 . $i
208 . ']->trigger->('
209 . '$instance, '
210 . $attr->inline_get('$instance')
211 . ', '
212 . ');' . "\n}";
213 }
214
215 return join ";\n" => @trigger_calls;
216}
217
218
# spent 90.3ms (29.6+60.7) within Moose::Meta::Method::Constructor::_generate_slot_initializer which was called 130 times, avg 694µs/call: # 130 times (29.6ms+60.7ms) by Moose::Meta::Method::Constructor::_generate_slot_initializers at line 138, avg 694µs/call
sub _generate_slot_initializer {
219104018.1ms my $self = shift;
220 my $index = shift;
221
2221301.57ms my $attr = $self->_attributes->[$index];
# spent 1.57ms making 130 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call
223
224130866µs my @source = ('## ' . $attr->name);
# spent 866µs making 130 calls to Class::MOP::Mixin::AttributeCore::name, avg 7µs/call
225
2261301.19ms my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME
# spent 1.19ms making 130 calls to UNIVERSAL::isa, avg 9µs/call
227
2282482.88ms if ($is_moose && defined($attr->init_arg) && $attr->is_required && !$attr->has_default && !$attr->has_builder) {
# spent 971µs making 88 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 11µs/call # spent 683µs making 48 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 14µs/call # spent 475µs making 28 calls to Moose::Meta::Method::_inline_throw_error, avg 17µs/call # spent 308µs making 28 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 11µs/call # spent 300µs making 28 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 11µs/call # spent 140µs making 28 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call
229 push @source => ('(exists $params->{\'' . $attr->init_arg . '\'}) ' .
230 '|| ' . $self->_inline_throw_error('"Attribute (' . quotemeta($attr->name) . ') is required"') .';');
231 }
232
2338527.26ms2943.04ms if (($attr->has_default || $attr->has_builder) && !($is_moose && $attr->is_lazy)) {
# spent 1.32ms making 130 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call # spent 728µs making 72 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call # spent 698µs making 70 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 10µs/call # spent 293µs making 22 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 13µs/call
234
2352301.49ms58626µs if ( defined( my $init_arg = $attr->init_arg ) ) {
# spent 626µs making 58 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 11µs/call
236 push @source => 'if (exists $params->{\'' . $init_arg . '\'}) {';
237 push @source => ('my $val = $params->{\'' . $init_arg . '\'};');
238101.81ms push @source => $self->_generate_type_constraint_and_coercion($attr, $index)
# spent 1.81ms making 10 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 181µs/call
239 if $is_moose;
2404610.4ms push @source => $self->_generate_slot_assignment($attr, '$val', $index);
# spent 10.4ms making 46 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 227µs/call
241 push @source => "} else {";
242 }
243 my $default;
2441163.35ms if ( $attr->has_default ) {
# spent 2.78ms making 58 calls to Class::MOP::Method::Constructor::_generate_default_value, avg 48µs/call # spent 568µs making 58 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call
245 $default = $self->_generate_default_value($attr, $index);
246 }
247 else {
248 my $builder = $attr->builder;
249 $default = '$instance->' . $builder;
250 }
251
252 push @source => '{'; # wrap this to avoid my $val overwrite warnings
253 push @source => ('my $val = ' . $default . ';');
254162.37ms push @source => $self->_generate_type_constraint_and_coercion($attr, $index)
# spent 2.37ms making 16 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 148µs/call
255 if $is_moose;
2565813.1ms push @source => $self->_generate_slot_assignment($attr, '$val', $index);
# spent 13.1ms making 58 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 225µs/call
257 push @source => '}'; # close - wrap this to avoid my $val overrite warnings
258
25958599µs push @source => "}" if defined $attr->init_arg;
# spent 599µs making 58 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call
260 }
261 elsif ( defined( my $init_arg = $attr->init_arg ) ) {
262 push @source => '(exists $params->{\'' . $init_arg . '\'}) && do {';
263
264 push @source => ('my $val = $params->{\'' . $init_arg . '\'};');
265761.15ms38415µs if ($is_moose && $attr->has_type_constraint) {
# spent 415µs making 38 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 11µs/call
26638492µs if ($attr->should_coerce && $attr->type_constraint->has_coercion) {
# spent 492µs making 38 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 13µs/call
267 push @source => $self->_generate_type_coercion(
268 $attr,
269 '$type_constraints[' . $index . ']',
270 '$val',
271 '$val'
272 );
273 }
274382.48ms push @source => $self->_generate_type_constraint_check(
# spent 2.48ms making 38 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_check, avg 65µs/call
275 $attr,
276 '$type_constraint_bodies[' . $index . ']',
277 '$type_constraints[' . $index . ']',
278 '$val'
279 );
280 }
2816615.5ms push @source => $self->_generate_slot_assignment($attr, '$val', $index);
# spent 15.5ms making 66 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 235µs/call
282
283 push @source => "}";
284 }
285
286 return join "\n" => @source;
287}
288
289
# spent 39.0ms (7.39+31.6) within Moose::Meta::Method::Constructor::_generate_slot_assignment which was called 170 times, avg 229µs/call: # 66 times (2.86ms+12.7ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 281, avg 235µs/call # 58 times (2.60ms+10.5ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 256, avg 225µs/call # 46 times (1.93ms+8.49ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 240, avg 227µs/call
sub _generate_slot_assignment {
2905102.78ms my ($self, $attr, $value, $index) = @_;
291
292 my $source;
293
2941703.94ms1701.65ms if ( $attr->has_initializer ) {
# spent 1.65ms making 170 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 10µs/call
295 return
296 '$attrs->['
297 . $index
298 . ']->set_initial_value($instance, '
299 . $value . ');';
300 }
301 else {
30217030.0ms return $attr->inline_set(
# spent 17.4ms making 106 calls to Class::MOP::Attribute::inline_set, avg 164µs/call # spent 12.6ms making 64 calls to Moose::Meta::Attribute::inline_set, avg 197µs/call
303 '$instance',
304 $value
305 ) . ';';
306 }
307
308 return $source;
309}
310
311
# spent 4.18ms (1.90+2.27) within Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion which was called 26 times, avg 161µs/call: # 16 times (1.01ms+1.36ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 254, avg 148µs/call # 10 times (890µs+915µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 238, avg 181µs/call
sub _generate_type_constraint_and_coercion {
3121561.63ms my ($self, $attr, $index) = @_;
313
31426254µs return unless $attr->has_type_constraint;
# spent 254µs making 26 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 10µs/call
315
316 my @source;
31726310µs if ($attr->should_coerce && $attr->type_constraint->has_coercion) {
# spent 310µs making 26 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 12µs/call
318 push @source => $self->_generate_type_coercion(
319 $attr,
320 '$type_constraints[' . $index . ']',
321 '$val',
322 '$val'
323 );
324 }
325261.71ms push @source => $self->_generate_type_constraint_check(
# spent 1.71ms making 26 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_check, avg 66µs/call
326 $attr,
327 ('$type_constraint_bodies[' . $index . ']'),
328 ('$type_constraints[' . $index . ']'),
329 '$val'
330 );
331 return @source;
332}
333
334sub _generate_type_coercion {
335 my ($self, $attr, $type_constraint_name, $value_name, $return_value_name) = @_;
336 return ($return_value_name . ' = ' . $type_constraint_name . '->coerce(' . $value_name . ');');
337}
338
339
# spent 4.19ms (2.86+1.32) within Moose::Meta::Method::Constructor::_generate_type_constraint_check which was called 64 times, avg 65µs/call: # 38 times (1.71ms+764µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 274, avg 65µs/call # 26 times (1.15ms+559µs) by Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion at line 325, avg 66µs/call
sub _generate_type_constraint_check {
3401283.11ms my ($self, $attr, $type_constraint_cv, $type_constraint_obj, $value_name) = @_;
341 return (
3421281.32ms $self->_inline_throw_error('"Attribute (' # FIXME add 'dad'
# spent 1.01ms making 64 calls to Moose::Meta::Method::_inline_throw_error, avg 16µs/call # spent 310µs making 64 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call
343 . quotemeta( $attr->name )
344 . ') does not pass the type constraint because: " . '
345 . $type_constraint_obj . '->get_message(' . $value_name . ')')
346 . "\n\t unless " . $type_constraint_cv . '->(' . $value_name . ');'
347 );
348}
349
350114µs1;
351
352__END__