File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Method/Constructor.pm |
Statements Executed | 205 |
Statement Execution Time | 1.95ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 1 | 1 | 229µs | 487µs | _generate_slot_initializer | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 203µs | 1.70ms | new | Moose::Meta::Method::Constructor::
6 | 3 | 1 | 102µs | 169µs | _generate_slot_assignment | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 91µs | 1.49ms | _initialize_body | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 39µs | 58µs | _generate_triggers | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 33µs | 563µs | _generate_slot_initializers | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 25µs | 268µs | _generate_BUILDARGS | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 23µs | 41µs | _generate_instance | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 15µs | 18µs | BEGIN@4 | Moose::Meta::Method::Constructor::
4 | 2 | 1 | 15µs | 19µs | _generate_type_constraint_and_coercion | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 13µs | 116µs | _generate_BUILDALL | Moose::Meta::Method::Constructor::
2 | 1 | 1 | 11µs | 16µs | _generate_default_value | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 10µs | 278µs | _generate_params | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 8µs | 17µs | BEGIN@5 | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 7µs | 83µs | BEGIN@12 | Moose::Meta::Method::Constructor::
1 | 1 | 1 | 7µs | 51µs | BEGIN@7 | Moose::Meta::Method::Constructor::
0 | 0 | 0 | 0s | 0s | _generate_type_coercion | Moose::Meta::Method::Constructor::
0 | 0 | 0 | 0s | 0s | _generate_type_constraint_check | Moose::Meta::Method::Constructor::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Moose::Meta::Method::Constructor; | ||||
3 | |||||
4 | 3 | 25µs | 2 | 21µs | # spent 18µs (15+3) within Moose::Meta::Method::Constructor::BEGIN@4 which was called
# once (15µs+3µs) by Moose::Meta::Class::BEGIN@22 at line 4 # spent 18µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@4
# spent 3µs making 1 call to strict::import |
5 | 3 | 24µs | 2 | 27µs | # spent 17µs (8+10) within Moose::Meta::Method::Constructor::BEGIN@5 which was called
# once (8µs+10µs) by Moose::Meta::Class::BEGIN@22 at line 5 # spent 17µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@5
# spent 10µs making 1 call to warnings::import |
6 | |||||
7 | 3 | 46µs | 2 | 96µs | # spent 51µs (7+45) within Moose::Meta::Method::Constructor::BEGIN@7 which was called
# once (7µs+45µs) by Moose::Meta::Class::BEGIN@22 at line 7 # spent 51µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@7
# spent 45µs making 1 call to Exporter::import |
8 | |||||
9 | 1 | 600ns | our $VERSION = '0.98'; | ||
10 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
11 | |||||
12 | 1 | 4µs | 1 | 76µs | # spent 83µs (7+76) within Moose::Meta::Method::Constructor::BEGIN@12 which was called
# once (7µs+76µs) by Moose::Meta::Class::BEGIN@22 at line 13 # spent 76µs making 1 call to base::import |
13 | 2 | 1.17ms | 1 | 83µs | 'Class::MOP::Method::Constructor'; # spent 83µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@12 |
14 | |||||
15 | # spent 1.70ms (203µs+1.49) within Moose::Meta::Method::Constructor::new which was called
# once (203µs+1.49ms) by Class::MOP::Class::_inline_constructor at line 1055 of Class/MOP/Class.pm | ||||
16 | 1 | 1µs | my $class = shift; | ||
17 | 1 | 3µs | my %options = @_; | ||
18 | |||||
19 | 1 | 800ns | my $meta = $options{metaclass}; | ||
20 | |||||
21 | 1 | 1µs | (ref $options{options} eq 'HASH') | ||
22 | || $class->throw_error("You must pass a hash of options", data => $options{options}); | ||||
23 | |||||
24 | 1 | 800ns | ($options{package_name} && $options{name}) | ||
25 | || $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT"); | ||||
26 | |||||
27 | 1 | 185µs | my $self = bless { | ||
28 | 'body' => undef, | ||||
29 | 'package_name' => $options{package_name}, | ||||
30 | 'name' => $options{name}, | ||||
31 | 'options' => $options{options}, | ||||
32 | 'associated_metaclass' => $meta, | ||||
33 | '_expected_method_class' => $options{_expected_method_class} || 'Moose::Object', | ||||
34 | } => $class; | ||||
35 | |||||
36 | # we don't want this creating | ||||
37 | # a cycle in the code, if not | ||||
38 | # needed | ||||
39 | 1 | 4µs | 1 | 900ns | weaken($self->{'associated_metaclass'}); # spent 900ns making 1 call to Scalar::Util::weaken |
40 | |||||
41 | 1 | 2µs | 1 | 1.49ms | $self->_initialize_body; # spent 1.49ms making 1 call to Moose::Meta::Method::Constructor::_initialize_body |
42 | |||||
43 | 1 | 4µs | return $self; | ||
44 | } | ||||
45 | |||||
46 | ## method | ||||
47 | |||||
48 | # spent 1.49ms (91µs+1.40) within Moose::Meta::Method::Constructor::_initialize_body which was called
# once (91µs+1.40ms) by Moose::Meta::Method::Constructor::new at line 41 | ||||
49 | 1 | 600ns | my $self = shift; | ||
50 | # TODO: | ||||
51 | # the %options should also include a both | ||||
52 | # a call 'initializer' and call 'SUPER::' | ||||
53 | # options, which should cover approx 90% | ||||
54 | # of the possible use cases (even if it | ||||
55 | # requires some adaption on the part of | ||||
56 | # the author, after all, nothing is free) | ||||
57 | 1 | 700ns | my $source = 'sub {'; | ||
58 | 1 | 700ns | $source .= "\n" . 'my $_instance = shift;'; | ||
59 | |||||
60 | 1 | 600ns | $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;'; | ||
61 | |||||
62 | 1 | 500ns | $source .= "\n" . 'return $class->Moose::Object::new(@_)'; | ||
63 | 1 | 8µs | 2 | 3µs | $source .= "\n if \$class ne '" . $self->associated_metaclass->name # spent 2µs making 1 call to Class::MOP::Method::associated_metaclass
# spent 600ns making 1 call to Class::MOP::Package::name |
64 | . "';\n"; | ||||
65 | |||||
66 | 1 | 3µs | 1 | 278µs | $source .= $self->_generate_params('$params', '$class'); # spent 278µs making 1 call to Moose::Meta::Method::Constructor::_generate_params |
67 | 1 | 7µs | 1 | 41µs | $source .= $self->_generate_instance('$instance', '$class'); # spent 41µs making 1 call to Moose::Meta::Method::Constructor::_generate_instance |
68 | 1 | 4µs | 1 | 563µs | $source .= $self->_generate_slot_initializers; # spent 563µs making 1 call to Moose::Meta::Method::Constructor::_generate_slot_initializers |
69 | |||||
70 | 1 | 3µs | 1 | 58µs | $source .= $self->_generate_triggers(); # spent 58µs making 1 call to Moose::Meta::Method::Constructor::_generate_triggers |
71 | 1 | 3µs | 1 | 116µs | $source .= ";\n" . $self->_generate_BUILDALL(); # spent 116µs making 1 call to Moose::Meta::Method::Constructor::_generate_BUILDALL |
72 | |||||
73 | 1 | 300ns | $source .= ";\nreturn \$instance"; | ||
74 | 1 | 400ns | $source .= ";\n" . '}'; | ||
75 | 1 | 7µs | 1 | 2µs | warn $source if $self->options->{debug}; # spent 2µs making 1 call to Class::MOP::Method::Constructor::options |
76 | |||||
77 | # We need to check if the attribute ->can('type_constraint') | ||||
78 | # since we may be trying to immutabilize a Moose meta class, | ||||
79 | # which in turn has attributes which are Class::MOP::Attribute | ||||
80 | # objects, rather than Moose::Meta::Attribute. And | ||||
81 | # Class::MOP::Attribute attributes have no type constraints. | ||||
82 | # However we need to make sure we leave an undef value there | ||||
83 | # because the inlined code is using the index of the attributes | ||||
84 | # to determine where to find the type constraint | ||||
85 | |||||
86 | 1 | 2µs | 1 | 1µs | my $attrs = $self->_attributes; # spent 1µs making 1 call to Class::MOP::Method::Constructor::_attributes |
87 | |||||
88 | 4 | 13µs | 8 | 7µs | my @type_constraints = map { # spent 4µs making 4 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 1µs/call
# spent 3µs making 4 calls to UNIVERSAL::can, avg 650ns/call |
89 | 1 | 3µs | $_->can('type_constraint') ? $_->type_constraint : undef | ||
90 | } @$attrs; | ||||
91 | |||||
92 | 4 | 800ns | my @type_constraint_bodies = map { | ||
93 | 1 | 2µs | defined $_ ? $_->_compiled_type_constraint : undef; | ||
94 | } @type_constraints; | ||||
95 | |||||
96 | 1 | 9µs | 1 | 333µs | my ( $code, $e ) = $self->_compile_code( # spent 333µs making 1 call to Class::MOP::Method::Generated::_compile_code |
97 | code => $source, | ||||
98 | environment => { | ||||
99 | '$meta' => \$self, | ||||
100 | '$attrs' => \$attrs, | ||||
101 | '@type_constraints' => \@type_constraints, | ||||
102 | '@type_constraint_bodies' => \@type_constraint_bodies, | ||||
103 | }, | ||||
104 | ); | ||||
105 | |||||
106 | 1 | 400ns | $self->throw_error( | ||
107 | "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e", | ||||
108 | error => $e, data => $source ) | ||||
109 | if $e; | ||||
110 | |||||
111 | 1 | 4µs | $self->{'body'} = $code; | ||
112 | } | ||||
113 | |||||
114 | # spent 278µs (10+268) within Moose::Meta::Method::Constructor::_generate_params which was called
# once (10µs+268µs) by Moose::Meta::Method::Constructor::_initialize_body at line 66 | ||||
115 | 1 | 1µs | my ( $self, $var, $class_var ) = @_; | ||
116 | 1 | 8µs | 1 | 268µs | "my $var = " . $self->_generate_BUILDARGS( $class_var, '@_' ) . ";\n"; # spent 268µs making 1 call to Moose::Meta::Method::Constructor::_generate_BUILDARGS |
117 | } | ||||
118 | |||||
119 | # spent 41µs (23+18) within Moose::Meta::Method::Constructor::_generate_instance which was called
# once (23µs+18µs) by Moose::Meta::Method::Constructor::_initialize_body at line 67 | ||||
120 | 1 | 1µs | my ( $self, $var, $class_var ) = @_; | ||
121 | 1 | 14µs | 2 | 18µs | "my $var = " # spent 15µs making 1 call to Class::MOP::Method::Constructor::_meta_instance
# spent 3µs making 1 call to Class::MOP::Instance::inline_create_instance |
122 | . $self->_meta_instance->inline_create_instance($class_var) . ";\n"; | ||||
123 | } | ||||
124 | |||||
125 | # spent 563µs (33+530) within Moose::Meta::Method::Constructor::_generate_slot_initializers which was called
# once (33µs+530µs) by Moose::Meta::Method::Constructor::_initialize_body at line 68 | ||||
126 | 1 | 700ns | my ($self) = @_; | ||
127 | 4 | 5µs | 4 | 487µs | return (join ";\n" => map { # spent 487µs making 4 calls to Moose::Meta::Method::Constructor::_generate_slot_initializer, avg 122µs/call |
128 | $self->_generate_slot_initializer($_) | ||||
129 | 1 | 22µs | 1 | 42µs | } 0 .. (@{$self->_attributes} - 1)) . ";\n"; # spent 42µs making 1 call to Class::MOP::Method::Constructor::_attributes |
130 | } | ||||
131 | |||||
132 | # spent 268µs (25+243) within Moose::Meta::Method::Constructor::_generate_BUILDARGS which was called
# once (25µs+243µs) by Moose::Meta::Method::Constructor::_generate_params at line 116 | ||||
133 | 1 | 1µs | my ( $self, $class, $args ) = @_; | ||
134 | |||||
135 | 1 | 6µs | 2 | 240µs | my $buildargs = $self->associated_metaclass->find_method_by_name("BUILDARGS"); # spent 239µs making 1 call to Class::MOP::Class::find_method_by_name
# spent 700ns making 1 call to Class::MOP::Method::associated_metaclass |
136 | |||||
137 | 1 | 16µs | 2 | 3µs | if ( $args eq '@_' and ( !$buildargs or $buildargs->body == \&Moose::Object::BUILDARGS ) ) { # spent 2µs making 1 call to Moose::Meta::Method::_inline_throw_error
# spent 700ns making 1 call to Class::MOP::Method::body |
138 | return join("\n", | ||||
139 | 'do {', | ||||
140 | $self->_inline_throw_error('"Single parameters to new() must be a HASH ref"', 'data => $_[0]'), | ||||
141 | ' if scalar @_ == 1 && !( defined $_[0] && ref $_[0] eq q{HASH} );', | ||||
142 | '(scalar @_ == 1) ? {%{$_[0]}} : {@_};', | ||||
143 | '}', | ||||
144 | ); | ||||
145 | } else { | ||||
146 | return $class . "->BUILDARGS($args)"; | ||||
147 | } | ||||
148 | } | ||||
149 | |||||
150 | # spent 116µs (13+103) within Moose::Meta::Method::Constructor::_generate_BUILDALL which was called
# once (13µs+103µs) by Moose::Meta::Method::Constructor::_initialize_body at line 71 | ||||
151 | 1 | 500ns | my $self = shift; | ||
152 | 1 | 200ns | my @BUILD_calls; | ||
153 | 1 | 7µs | 2 | 103µs | foreach my $method (reverse $self->associated_metaclass->find_all_methods_by_name('BUILD')) { # spent 102µs making 1 call to Class::MOP::Class::find_all_methods_by_name
# spent 1µs making 1 call to Class::MOP::Method::associated_metaclass |
154 | push @BUILD_calls => '$instance->' . $method->{class} . '::BUILD($params)'; | ||||
155 | } | ||||
156 | 1 | 4µs | return join ";\n" => @BUILD_calls; | ||
157 | } | ||||
158 | |||||
159 | # spent 58µs (39+19) within Moose::Meta::Method::Constructor::_generate_triggers which was called
# once (39µs+19µs) by Moose::Meta::Method::Constructor::_initialize_body at line 70 | ||||
160 | 1 | 400ns | my $self = shift; | ||
161 | 1 | 400ns | my @trigger_calls; | ||
162 | 1 | 6µs | 1 | 1µs | foreach my $i ( 0 .. $#{ $self->_attributes } ) { # spent 1µs making 1 call to Class::MOP::Method::Constructor::_attributes |
163 | 4 | 4µs | 4 | 5µs | my $attr = $self->_attributes->[$i]; # spent 5µs making 4 calls to Class::MOP::Method::Constructor::_attributes, avg 1µs/call |
164 | |||||
165 | 4 | 20µs | 8 | 13µs | next unless $attr->can('has_trigger') && $attr->has_trigger; # spent 8µs making 4 calls to UNIVERSAL::can, avg 2µs/call
# spent 5µs making 4 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 1µs/call |
166 | |||||
167 | my $init_arg = $attr->init_arg; | ||||
168 | |||||
169 | next unless defined $init_arg; | ||||
170 | |||||
171 | push @trigger_calls => '(exists $params->{\'' | ||||
172 | . $init_arg | ||||
173 | . '\'}) && do {' | ||||
174 | . "\n " | ||||
175 | . '$attrs->[' | ||||
176 | . $i | ||||
177 | . ']->trigger->(' | ||||
178 | . '$instance, ' | ||||
179 | . $self->_meta_instance->inline_get_slot_value( | ||||
180 | '$instance', | ||||
181 | $attr->name, | ||||
182 | ) | ||||
183 | . ', ' | ||||
184 | . ');' . "\n}"; | ||||
185 | } | ||||
186 | |||||
187 | 1 | 4µs | return join ";\n" => @trigger_calls; | ||
188 | } | ||||
189 | |||||
190 | # spent 487µs (229+258) within Moose::Meta::Method::Constructor::_generate_slot_initializer which was called 4 times, avg 122µs/call:
# 4 times (229µs+258µs) by Moose::Meta::Method::Constructor::_generate_slot_initializers at line 127, avg 122µs/call | ||||
191 | 4 | 1µs | my $self = shift; | ||
192 | 4 | 800ns | my $index = shift; | ||
193 | |||||
194 | 4 | 5µs | 4 | 5µs | my $attr = $self->_attributes->[$index]; # spent 5µs making 4 calls to Class::MOP::Method::Constructor::_attributes, avg 1µs/call |
195 | |||||
196 | 4 | 13µs | 4 | 2µs | my @source = ('## ' . $attr->name); # spent 2µs making 4 calls to Class::MOP::Mixin::AttributeCore::name, avg 600ns/call |
197 | |||||
198 | 4 | 11µs | 4 | 3µs | my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME # spent 3µs making 4 calls to UNIVERSAL::isa, avg 725ns/call |
199 | |||||
200 | 4 | 48µs | 18 | 24µs | if ($is_moose && defined($attr->init_arg) && $attr->is_required && !$attr->has_default && !$attr->has_builder) { # spent 7µs making 4 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 2µs/call
# spent 6µs making 6 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 1µs/call
# spent 5µs making 2 calls to Moose::Meta::Method::_inline_throw_error, avg 2µs/call
# spent 3µs making 2 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 2µs/call
# spent 3µs making 2 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call
# spent 800ns making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 400ns/call |
201 | push @source => ('(exists $params->{\'' . $attr->init_arg . '\'}) ' . | ||||
202 | '|| ' . $self->_inline_throw_error('"Attribute (' . quotemeta($attr->name) . ') is required"') .';'); | ||||
203 | } | ||||
204 | |||||
205 | 4 | 12µs | 10 | 10µs | if (($attr->has_default || $attr->has_builder) && !($is_moose && $attr->is_lazy)) { # spent 4µs making 4 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call
# spent 2µs making 2 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 1µs/call
# spent 2µs making 2 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 900ns/call
# spent 2µs making 2 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 900ns/call |
206 | |||||
207 | 2 | 3µs | 2 | 2µs | if ( defined( my $init_arg = $attr->init_arg ) ) { # spent 2µs making 2 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 900ns/call |
208 | 2 | 2µs | push @source => 'if (exists $params->{\'' . $init_arg . '\'}) {'; | ||
209 | 2 | 1µs | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | ||
210 | 2 | 3µs | 2 | 11µs | push @source => $self->_generate_type_constraint_and_coercion($attr, $index) # spent 11µs making 2 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 6µs/call |
211 | if $is_moose; | ||||
212 | 2 | 2µs | 2 | 48µs | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 48µs making 2 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 24µs/call |
213 | 2 | 1µs | push @source => "} else {"; | ||
214 | } | ||||
215 | 2 | 500ns | my $default; | ||
216 | 2 | 6µs | 4 | 18µs | if ( $attr->has_default ) { # spent 16µs making 2 calls to Moose::Meta::Method::Constructor::_generate_default_value, avg 8µs/call
# spent 2µs making 2 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call |
217 | $default = $self->_generate_default_value($attr, $index); | ||||
218 | } | ||||
219 | else { | ||||
220 | my $builder = $attr->builder; | ||||
221 | $default = '$instance->' . $builder; | ||||
222 | } | ||||
223 | |||||
224 | 2 | 1µs | push @source => '{'; # wrap this to avoid my $val overwrite warnings | ||
225 | 2 | 2µs | push @source => ('my $val = ' . $default . ';'); | ||
226 | 2 | 3µs | 2 | 8µs | push @source => $self->_generate_type_constraint_and_coercion($attr, $index) # spent 8µs making 2 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 4µs/call |
227 | if $is_moose; | ||||
228 | 2 | 3µs | 2 | 44µs | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 44µs making 2 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 22µs/call |
229 | 2 | 800ns | push @source => '}'; # close - wrap this to avoid my $val overrite warnings | ||
230 | |||||
231 | 2 | 3µs | 2 | 2µs | push @source => "}" if defined $attr->init_arg; # spent 2µs making 2 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 1µs/call |
232 | } | ||||
233 | elsif ( defined( my $init_arg = $attr->init_arg ) ) { | ||||
234 | 2 | 2µs | push @source => '(exists $params->{\'' . $init_arg . '\'}) && do {'; | ||
235 | |||||
236 | 2 | 2µs | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | ||
237 | 2 | 9µs | 2 | 4µs | if ($is_moose && $attr->has_type_constraint) { # spent 4µs making 2 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 2µs/call |
238 | if ($attr->should_coerce && $attr->type_constraint->has_coercion) { | ||||
239 | push @source => $self->_generate_type_coercion( | ||||
240 | $attr, | ||||
241 | '$type_constraints[' . $index . ']', | ||||
242 | '$val', | ||||
243 | '$val' | ||||
244 | ); | ||||
245 | } | ||||
246 | push @source => $self->_generate_type_constraint_check( | ||||
247 | $attr, | ||||
248 | '$type_constraint_bodies[' . $index . ']', | ||||
249 | '$type_constraints[' . $index . ']', | ||||
250 | '$val' | ||||
251 | ); | ||||
252 | } | ||||
253 | 2 | 9µs | 2 | 77µs | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 77µs making 2 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 38µs/call |
254 | |||||
255 | 2 | 1µs | push @source => "}"; | ||
256 | } | ||||
257 | |||||
258 | 4 | 16µs | return join "\n" => @source; | ||
259 | } | ||||
260 | |||||
261 | # spent 169µs (102+67) within Moose::Meta::Method::Constructor::_generate_slot_assignment which was called 6 times, avg 28µs/call:
# 2 times (50µs+27µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 253, avg 38µs/call
# 2 times (26µs+21µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 212, avg 24µs/call
# 2 times (25µs+19µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 228, avg 22µs/call | ||||
262 | 6 | 3µs | my ($self, $attr, $value, $index) = @_; | ||
263 | |||||
264 | 6 | 700ns | my $source; | ||
265 | |||||
266 | 6 | 11µs | 6 | 6µs | if ($attr->has_initializer) { # spent 6µs making 6 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 1µs/call |
267 | $source = ( | ||||
268 | '$attrs->[' . $index . ']->set_initial_value($instance, ' . $value . ');' | ||||
269 | ); | ||||
270 | } | ||||
271 | else { | ||||
272 | 6 | 29µs | 18 | 47µs | $source = ( # spent 37µs making 6 calls to Class::MOP::Instance::inline_set_slot_value, avg 6µs/call
# spent 8µs making 6 calls to Class::MOP::Method::Constructor::_meta_instance, avg 1µs/call
# spent 3µs making 6 calls to Class::MOP::Mixin::AttributeCore::name, avg 467ns/call |
273 | $self->_meta_instance->inline_set_slot_value( | ||||
274 | '$instance', | ||||
275 | $attr->name, | ||||
276 | $value | ||||
277 | ) . ';' | ||||
278 | ); | ||||
279 | } | ||||
280 | |||||
281 | 6 | 16µs | 6 | 4µs | my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME # spent 4µs making 6 calls to UNIVERSAL::isa, avg 700ns/call |
282 | |||||
283 | 6 | 11µs | 6 | 9µs | if ($is_moose && $attr->is_weak_ref) { # spent 9µs making 6 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 2µs/call |
284 | $source .= ( | ||||
285 | "\n" . | ||||
286 | $self->_meta_instance->inline_weaken_slot_value( | ||||
287 | '$instance', | ||||
288 | $attr->name | ||||
289 | ) . | ||||
290 | ' if ref ' . $value . ';' | ||||
291 | ); | ||||
292 | } | ||||
293 | |||||
294 | 6 | 16µs | return $source; | ||
295 | } | ||||
296 | |||||
297 | # spent 19µs (15+4) within Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion which was called 4 times, avg 5µs/call:
# 2 times (9µs+2µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 210, avg 6µs/call
# 2 times (6µs+2µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 226, avg 4µs/call | ||||
298 | 4 | 2µs | my ($self, $attr, $index) = @_; | ||
299 | |||||
300 | 4 | 12µs | 4 | 4µs | return unless $attr->has_type_constraint; # spent 4µs making 4 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call |
301 | |||||
302 | my @source; | ||||
303 | if ($attr->should_coerce && $attr->type_constraint->has_coercion) { | ||||
304 | push @source => $self->_generate_type_coercion( | ||||
305 | $attr, | ||||
306 | '$type_constraints[' . $index . ']', | ||||
307 | '$val', | ||||
308 | '$val' | ||||
309 | ); | ||||
310 | } | ||||
311 | push @source => $self->_generate_type_constraint_check( | ||||
312 | $attr, | ||||
313 | ('$type_constraint_bodies[' . $index . ']'), | ||||
314 | ('$type_constraints[' . $index . ']'), | ||||
315 | '$val' | ||||
316 | ); | ||||
317 | return @source; | ||||
318 | } | ||||
319 | |||||
320 | sub _generate_type_coercion { | ||||
321 | my ($self, $attr, $type_constraint_name, $value_name, $return_value_name) = @_; | ||||
322 | return ($return_value_name . ' = ' . $type_constraint_name . '->coerce(' . $value_name . ');'); | ||||
323 | } | ||||
324 | |||||
325 | sub _generate_type_constraint_check { | ||||
326 | my ($self, $attr, $type_constraint_cv, $type_constraint_obj, $value_name) = @_; | ||||
327 | return ( | ||||
328 | $self->_inline_throw_error('"Attribute (' # FIXME add 'dad' | ||||
329 | . quotemeta( $attr->name ) | ||||
330 | . ') does not pass the type constraint because: " . ' | ||||
331 | . $type_constraint_obj . '->get_message(' . $value_name . ')') | ||||
332 | . "\n\t unless " . $type_constraint_cv . '->(' . $value_name . ');' | ||||
333 | ); | ||||
334 | } | ||||
335 | |||||
336 | # spent 16µs (11+5) within Moose::Meta::Method::Constructor::_generate_default_value which was called 2 times, avg 8µs/call:
# 2 times (11µs+5µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 216, avg 8µs/call | ||||
337 | 2 | 2µs | my ($self, $attr, $index) = @_; | ||
338 | # NOTE: | ||||
339 | # default values can either be CODE refs | ||||
340 | # in which case we need to call them. Or | ||||
341 | # they can be scalars (strings/numbers) | ||||
342 | # in which case we can just deal with them | ||||
343 | # in the code we eval. | ||||
344 | 2 | 8µs | 2 | 5µs | if ($attr->is_default_a_coderef) { # spent 5µs making 2 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 2µs/call |
345 | return '$attrs->[' . $index . ']->default($instance)'; | ||||
346 | } | ||||
347 | else { | ||||
348 | return q{"} . quotemeta( $attr->default ) . q{"}; | ||||
349 | } | ||||
350 | } | ||||
351 | |||||
352 | 1 | 4µs | 1; | ||
353 | |||||
354 | __END__ | ||||
355 | |||||
356 | =pod | ||||
357 | |||||
358 | =head1 NAME | ||||
359 | |||||
360 | Moose::Meta::Method::Constructor - Method Meta Object for constructors | ||||
361 | |||||
362 | =head1 DESCRIPTION | ||||
363 | |||||
364 | This class is a subclass of L<Class::MOP::Class::Constructor> that | ||||
365 | provides additional Moose-specific functionality | ||||
366 | |||||
367 | To understand this class, you should read the the | ||||
368 | L<Class::MOP::Class::Constructor> documentation as well. | ||||
369 | |||||
370 | =head1 INHERITANCE | ||||
371 | |||||
372 | C<Moose::Meta::Method::Constructor> is a subclass of | ||||
373 | L<Moose::Meta::Method> I<and> L<Class::MOP::Method::Constructor>. | ||||
374 | |||||
375 | =head1 BUGS | ||||
376 | |||||
377 | See L<Moose/BUGS> for details on reporting bugs. | ||||
378 | |||||
379 | =head1 AUTHORS | ||||
380 | |||||
381 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
382 | |||||
383 | =head1 COPYRIGHT AND LICENSE | ||||
384 | |||||
385 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
386 | |||||
387 | L<http://www.iinteractive.com> | ||||
388 | |||||
389 | This library is free software; you can redistribute it and/or modify | ||||
390 | it under the same terms as Perl itself. | ||||
391 | |||||
392 | =cut | ||||
393 |