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