| 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 | use base 'Moose::Meta::Method', # spent 156µs making 1 call to base::import | |||
| 13 | 3 | 1.95ms | 651µ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 | 63 | 892µs | 14µs | my $class = shift; |
| 17 | my %options = @_; | |||
| 18 | ||||
| 19 | my $meta = $options{metaclass}; | |||
| 20 | ||||
| 21 | (ref $options{options} eq 'HASH') | |||
| 22 | || $class->throw_error("You must pass a hash of options", data => $options{options}); | |||
| 23 | ||||
| 24 | ($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 | 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 | weaken($self->{'associated_metaclass'}); # spent 27µs making 7 calls to Scalar::Util::weaken, avg 4µs/call | |||
| 40 | ||||
| 41 | $self->_initialize_body; # spent 13.2ms making 7 calls to Moose::Meta::Method::Constructor::_initialize_body, avg 1.89ms/call | |||
| 42 | ||||
| 43 | 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 | 184 | 791µs | 4µs | 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 | my $source = 'sub {'; | |||
| 58 | $source .= "\n" . 'my $_instance = shift;'; | |||
| 59 | ||||
| 60 | $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;'; | |||
| 61 | ||||
| 62 | $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 | $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 | $source .= "\n}\n"; | |||
| 67 | ||||
| 68 | $source .= $self->_generate_params('$params', '$class'); # spent 3.20ms making 7 calls to Moose::Meta::Method::Constructor::_generate_params, avg 458µs/call | |||
| 69 | $source .= $self->_generate_instance('$instance', '$class'); # spent 542µs making 7 calls to Moose::Meta::Method::Constructor::_generate_instance, avg 78µs/call | |||
| 70 | $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 | $source .= $self->_generate_triggers(); # spent 305µs making 7 calls to Moose::Meta::Method::Constructor::_generate_triggers, avg 44µs/call | |||
| 73 | $source .= ";\n" . $self->_generate_BUILDALL(); # spent 1.79ms making 7 calls to Moose::Meta::Method::Constructor::_generate_BUILDALL, avg 256µs/call | |||
| 74 | ||||
| 75 | $source .= ";\nreturn \$instance"; | |||
| 76 | $source .= ";\n" . '}'; | |||
| 77 | 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 | my $attrs = $self->_attributes; # spent 31µs making 7 calls to Class::MOP::Method::Constructor::_attributes, avg 4µs/call | |||
| 89 | ||||
| 90 | 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 | $_->can('type_constraint') ? $_->type_constraint : undef | |||
| 92 | } @$attrs; | |||
| 93 | ||||
| 94 | my @type_constraint_bodies = map { # spent 34µs making 6 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 6µs/call | |||
| 95 | defined $_ ? $_->_compiled_type_constraint : undef; | |||
| 96 | } @type_constraints; | |||
| 97 | ||||
| 98 | my $defaults = [map { $_->default } @$attrs]; # spent 58µs making 10 calls to Class::MOP::Mixin::AttributeCore::default, avg 6µs/call | |||
| 99 | ||||
| 100 | 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 | $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 | $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 | 14 | 24µs | 2µs | my ( $self, $class_var ) = @_; |
| 121 | "${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 | 14 | 69µs | 5µs | my ( $self, $var, $class_var ) = @_; |
| 126 | "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 | 14 | 94µs | 7µs | my ( $self, $var, $class_var ) = @_; |
| 131 | "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 | 24 | 164µs | 7µs | my ($self) = @_; |
| 137 | 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 | } 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 | 21 | 193µs | 9µs | my ( $self, $class, $args ) = @_; |
| 144 | ||||
| 145 | 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 | 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 | 28 | 96µs | 3µs | my $self = shift; |
| 162 | my @BUILD_calls; | |||
| 163 | 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 | 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 | 48 | 228µs | 5µs | my $self = shift; |
| 171 | my @trigger_calls; | |||
| 172 | foreach my $i ( 0 .. $#{ $self->_attributes } ) { # spent 30µs making 7 calls to Class::MOP::Method::Constructor::_attributes, avg 4µs/call | |||
| 173 | my $attr = $self->_attributes->[$i]; # spent 38µs making 10 calls to Class::MOP::Method::Constructor::_attributes, avg 4µs/call | |||
| 174 | ||||
| 175 | 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 | 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 | 186 | 882µs | 5µs | my $self = shift; |
| 199 | my $index = shift; | |||
| 200 | ||||
| 201 | my $attr = $self->_attributes->[$index]; # spent 41µs making 10 calls to Class::MOP::Method::Constructor::_attributes, avg 4µs/call | |||
| 202 | ||||
| 203 | my @source = ('## ' . $attr->name); # spent 35µs making 10 calls to Class::MOP::Mixin::AttributeCore::name, avg 3µs/call | |||
| 204 | ||||
| 205 | 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 | 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 | 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 | 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 | push @source => 'if (exists $params->{\'' . $init_arg . '\'}) {'; | |||
| 216 | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | |||
| 217 | 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 | 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 | push @source => "} else {"; | |||
| 221 | } | |||
| 222 | my $default; | |||
| 223 | 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 | push @source => '{'; # wrap this to avoid my $val overwrite warnings | |||
| 232 | push @source => ('my $val = ' . $default . ';'); | |||
| 233 | 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 | 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 | push @source => '}'; # close - wrap this to avoid my $val overrite warnings | |||
| 237 | ||||
| 238 | 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 | push @source => '(exists $params->{\'' . $init_arg . '\'}) && do {'; | |||
| 242 | ||||
| 243 | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | |||
| 244 | 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 | 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 | 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 | 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 | push @source => "}"; | |||
| 263 | } | |||
| 264 | ||||
| 265 | 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 | 64 | 194µs | 3µs | my ($self, $attr, $value, $index) = @_; |
| 270 | ||||
| 271 | my $source; | |||
| 272 | ||||
| 273 | 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 | 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 | 64 | 198µs | 3µs | my ($self, $attr, $index) = @_; |
| 292 | ||||
| 293 | 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 | my @source; | |||
| 296 | 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 | 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 | 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 | 22 | 146µs | 7µs | my ($self, $attr, $type_constraint_cv, $type_constraint_obj, $value_name) = @_; |
| 320 | return ( | |||
| 321 | $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 |