| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/Method/Constructor.pm |
| Statements Executed | 1328 |
| Statement Execution Time | 5.22ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 32 | 1 | 1 | 1.32ms | 3.13ms | Moose::Meta::Method::Constructor::_generate_slot_initializer |
| 6 | 1 | 1 | 903µs | 9.91ms | Moose::Meta::Method::Constructor::new |
| 39 | 3 | 1 | 584µs | 1.04ms | Moose::Meta::Method::Constructor::_generate_slot_assignment |
| 6 | 1 | 1 | 574µs | 9.00ms | Moose::Meta::Method::Constructor::_initialize_body |
| 6 | 1 | 1 | 310µs | 436µs | Moose::Meta::Method::Constructor::_generate_triggers |
| 6 | 1 | 1 | 191µs | 3.60ms | Moose::Meta::Method::Constructor::_generate_slot_initializers |
| 6 | 1 | 1 | 128µs | 863µs | Moose::Meta::Method::Constructor::_generate_BUILDARGS |
| 14 | 2 | 1 | 121µs | 225µs | Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion |
| 15 | 2 | 1 | 107µs | 142µs | Moose::Meta::Method::Constructor::_generate_type_constraint_check |
| 6 | 1 | 1 | 75µs | 718µs | Moose::Meta::Method::Constructor::_generate_BUILDALL |
| 6 | 1 | 1 | 74µs | 162µs | Moose::Meta::Method::Constructor::_generate_instance |
| 7 | 1 | 1 | 59µs | 85µs | Moose::Meta::Method::Constructor::_generate_default_value |
| 6 | 1 | 1 | 56µs | 919µs | Moose::Meta::Method::Constructor::_generate_params |
| 1 | 1 | 1 | 14µs | 17µs | Moose::Meta::Method::Constructor::BEGIN@4 |
| 1 | 1 | 1 | 7µs | 16µs | Moose::Meta::Method::Constructor::BEGIN@5 |
| 1 | 1 | 1 | 7µs | 88µs | Moose::Meta::Method::Constructor::BEGIN@12 |
| 1 | 1 | 1 | 6µs | 43µs | Moose::Meta::Method::Constructor::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Constructor::_generate_type_coercion |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Method::Constructor; | ||||
| 3 | |||||
| 4 | 3 | 20µs | 2 | 20µs | # spent 17µs (14+3) within Moose::Meta::Method::Constructor::BEGIN@4 which was called
# once (14µs+3µs) by Moose::Meta::Class::BEGIN@22 at line 4 # spent 17µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@4
# spent 3µs making 1 call to strict::import |
| 5 | 3 | 22µs | 2 | 25µs | # spent 16µs (7+9) within Moose::Meta::Method::Constructor::BEGIN@5 which was called
# once (7µs+9µs) by Moose::Meta::Class::BEGIN@22 at line 5 # spent 16µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@5
# spent 9µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 45µs | 2 | 80µs | # spent 43µs (6+37) within Moose::Meta::Method::Constructor::BEGIN@7 which was called
# once (6µs+37µs) by Moose::Meta::Class::BEGIN@22 at line 7 # spent 43µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@7
# spent 37µs making 1 call to Exporter::import |
| 8 | |||||
| 9 | 1 | 700ns | our $VERSION = '0.98'; | ||
| 10 | 1 | 200ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 11 | |||||
| 12 | 1 | 4µs | 1 | 81µs | # spent 88µs (7+81) within Moose::Meta::Method::Constructor::BEGIN@12 which was called
# once (7µs+81µs) by Moose::Meta::Class::BEGIN@22 at line 13 # spent 81µs making 1 call to base::import |
| 13 | 2 | 1.45ms | 1 | 88µs | 'Class::MOP::Method::Constructor'; # spent 88µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@12 |
| 14 | |||||
| 15 | # spent 9.91ms (903µs+9.01) within Moose::Meta::Method::Constructor::new which was called 6 times, avg 1.65ms/call:
# 6 times (903µs+9.01ms) by Class::MOP::Class::_inline_constructor at line 1055 of Class/MOP/Class.pm, avg 1.65ms/call | ||||
| 16 | 6 | 11µs | my $class = shift; | ||
| 17 | 6 | 18µs | my %options = @_; | ||
| 18 | |||||
| 19 | 6 | 4µs | my $meta = $options{metaclass}; | ||
| 20 | |||||
| 21 | 6 | 7µs | (ref $options{options} eq 'HASH') | ||
| 22 | || $class->throw_error("You must pass a hash of options", data => $options{options}); | ||||
| 23 | |||||
| 24 | 6 | 6µ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 | 6 | 790µ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 | 6 | 26µs | 6 | 6µs | weaken($self->{'associated_metaclass'}); # spent 6µs making 6 calls to Scalar::Util::weaken, avg 1µs/call |
| 40 | |||||
| 41 | 6 | 14µs | 6 | 9.00ms | $self->_initialize_body; # spent 9.00ms making 6 calls to Moose::Meta::Method::Constructor::_initialize_body, avg 1.50ms/call |
| 42 | |||||
| 43 | 6 | 24µs | return $self; | ||
| 44 | } | ||||
| 45 | |||||
| 46 | ## method | ||||
| 47 | |||||
| 48 | # spent 9.00ms (574µs+8.43) within Moose::Meta::Method::Constructor::_initialize_body which was called 6 times, avg 1.50ms/call:
# 6 times (574µs+8.43ms) by Moose::Meta::Method::Constructor::new at line 41, avg 1.50ms/call | ||||
| 49 | 6 | 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 | 6 | 5µs | my $source = 'sub {'; | ||
| 58 | 6 | 3µs | $source .= "\n" . 'my $_instance = shift;'; | ||
| 59 | |||||
| 60 | 6 | 3µs | $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;'; | ||
| 61 | |||||
| 62 | 6 | 2µs | $source .= "\n" . 'return $class->Moose::Object::new(@_)'; | ||
| 63 | 6 | 37µs | 12 | 18µs | $source .= "\n if \$class ne '" . $self->associated_metaclass->name # spent 15µs making 6 calls to Class::MOP::Method::associated_metaclass, avg 2µs/call
# spent 4µs making 6 calls to Class::MOP::Package::name, avg 600ns/call |
| 64 | . "';\n"; | ||||
| 65 | |||||
| 66 | 6 | 16µs | 6 | 919µs | $source .= $self->_generate_params('$params', '$class'); # spent 919µs making 6 calls to Moose::Meta::Method::Constructor::_generate_params, avg 153µs/call |
| 67 | 6 | 19µs | 6 | 162µs | $source .= $self->_generate_instance('$instance', '$class'); # spent 162µs making 6 calls to Moose::Meta::Method::Constructor::_generate_instance, avg 27µs/call |
| 68 | 6 | 27µs | 6 | 3.60ms | $source .= $self->_generate_slot_initializers; # spent 3.60ms making 6 calls to Moose::Meta::Method::Constructor::_generate_slot_initializers, avg 600µs/call |
| 69 | |||||
| 70 | 6 | 19µs | 6 | 436µs | $source .= $self->_generate_triggers(); # spent 436µs making 6 calls to Moose::Meta::Method::Constructor::_generate_triggers, avg 73µs/call |
| 71 | 6 | 18µs | 6 | 718µs | $source .= ";\n" . $self->_generate_BUILDALL(); # spent 718µs making 6 calls to Moose::Meta::Method::Constructor::_generate_BUILDALL, avg 120µs/call |
| 72 | |||||
| 73 | 6 | 3µs | $source .= ";\nreturn \$instance"; | ||
| 74 | 6 | 2µs | $source .= ";\n" . '}'; | ||
| 75 | 6 | 24µs | 6 | 19µs | warn $source if $self->options->{debug}; # spent 19µs making 6 calls to Class::MOP::Method::Constructor::options, avg 3µs/call |
| 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 | 6 | 10µs | 6 | 9µs | my $attrs = $self->_attributes; # spent 9µs making 6 calls to Class::MOP::Method::Constructor::_attributes, avg 1µs/call |
| 87 | |||||
| 88 | 32 | 110µs | 64 | 62µs | my @type_constraints = map { # spent 40µs making 32 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 1µs/call
# spent 22µs making 32 calls to UNIVERSAL::can, avg 684ns/call |
| 89 | 6 | 23µs | $_->can('type_constraint') ? $_->type_constraint : undef | ||
| 90 | } @$attrs; | ||||
| 91 | |||||
| 92 | 32 | 22µs | 11 | 131µs | my @type_constraint_bodies = map { # spent 131µs making 11 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 12µs/call |
| 93 | 6 | 15µs | defined $_ ? $_->_compiled_type_constraint : undef; | ||
| 94 | } @type_constraints; | ||||
| 95 | |||||
| 96 | 6 | 42µs | 6 | 2.35ms | my ( $code, $e ) = $self->_compile_code( # spent 2.35ms making 6 calls to Class::MOP::Method::Generated::_compile_code, avg 392µs/call |
| 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 | 6 | 2µs | $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 | 6 | 25µs | $self->{'body'} = $code; | ||
| 112 | } | ||||
| 113 | |||||
| 114 | # spent 919µs (56+863) within Moose::Meta::Method::Constructor::_generate_params which was called 6 times, avg 153µs/call:
# 6 times (56µs+863µs) by Moose::Meta::Method::Constructor::_initialize_body at line 66, avg 153µs/call | ||||
| 115 | 6 | 6µs | my ( $self, $var, $class_var ) = @_; | ||
| 116 | 6 | 46µs | 6 | 863µs | "my $var = " . $self->_generate_BUILDARGS( $class_var, '@_' ) . ";\n"; # spent 863µs making 6 calls to Moose::Meta::Method::Constructor::_generate_BUILDARGS, avg 144µs/call |
| 117 | } | ||||
| 118 | |||||
| 119 | # spent 162µs (74+88) within Moose::Meta::Method::Constructor::_generate_instance which was called 6 times, avg 27µs/call:
# 6 times (74µs+88µs) by Moose::Meta::Method::Constructor::_initialize_body at line 67, avg 27µs/call | ||||
| 120 | 6 | 6µs | my ( $self, $var, $class_var ) = @_; | ||
| 121 | 6 | 54µs | 12 | 88µs | "my $var = " # spent 69µs making 6 calls to Class::MOP::Method::Constructor::_meta_instance, avg 12µs/call
# spent 19µs making 6 calls to Class::MOP::Instance::inline_create_instance, avg 3µs/call |
| 122 | . $self->_meta_instance->inline_create_instance($class_var) . ";\n"; | ||||
| 123 | } | ||||
| 124 | |||||
| 125 | # spent 3.60ms (191µs+3.41) within Moose::Meta::Method::Constructor::_generate_slot_initializers which was called 6 times, avg 600µs/call:
# 6 times (191µs+3.41ms) by Moose::Meta::Method::Constructor::_initialize_body at line 68, avg 600µs/call | ||||
| 126 | 6 | 2µs | my ($self) = @_; | ||
| 127 | 32 | 41µs | 32 | 3.13ms | return (join ";\n" => map { # spent 3.13ms making 32 calls to Moose::Meta::Method::Constructor::_generate_slot_initializer, avg 98µs/call |
| 128 | $self->_generate_slot_initializer($_) | ||||
| 129 | 6 | 107µs | 6 | 276µs | } 0 .. (@{$self->_attributes} - 1)) . ";\n"; # spent 276µs making 6 calls to Class::MOP::Method::Constructor::_attributes, avg 46µs/call |
| 130 | } | ||||
| 131 | |||||
| 132 | # spent 863µs (128+735) within Moose::Meta::Method::Constructor::_generate_BUILDARGS which was called 6 times, avg 144µs/call:
# 6 times (128µs+735µs) by Moose::Meta::Method::Constructor::_generate_params at line 116, avg 144µs/call | ||||
| 133 | 6 | 6µs | my ( $self, $class, $args ) = @_; | ||
| 134 | |||||
| 135 | 6 | 29µs | 12 | 713µs | my $buildargs = $self->associated_metaclass->find_method_by_name("BUILDARGS"); # spent 708µs making 6 calls to Class::MOP::Class::find_method_by_name, avg 118µs/call
# spent 4µs making 6 calls to Class::MOP::Method::associated_metaclass, avg 750ns/call |
| 136 | |||||
| 137 | 6 | 75µs | 12 | 22µs | if ( $args eq '@_' and ( !$buildargs or $buildargs->body == \&Moose::Object::BUILDARGS ) ) { # spent 18µs making 6 calls to Moose::Meta::Method::_inline_throw_error, avg 3µs/call
# spent 4µs making 6 calls to Class::MOP::Method::body, avg 650ns/call |
| 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 718µs (75+643) within Moose::Meta::Method::Constructor::_generate_BUILDALL which was called 6 times, avg 120µs/call:
# 6 times (75µs+643µs) by Moose::Meta::Method::Constructor::_initialize_body at line 71, avg 120µs/call | ||||
| 151 | 6 | 3µs | my $self = shift; | ||
| 152 | 6 | 2µs | my @BUILD_calls; | ||
| 153 | 6 | 38µs | 12 | 643µs | foreach my $method (reverse $self->associated_metaclass->find_all_methods_by_name('BUILD')) { # spent 636µs making 6 calls to Class::MOP::Class::find_all_methods_by_name, avg 106µs/call
# spent 7µs making 6 calls to Class::MOP::Method::associated_metaclass, avg 1µs/call |
| 154 | push @BUILD_calls => '$instance->' . $method->{class} . '::BUILD($params)'; | ||||
| 155 | } | ||||
| 156 | 6 | 22µs | return join ";\n" => @BUILD_calls; | ||
| 157 | } | ||||
| 158 | |||||
| 159 | # spent 436µs (310+125) within Moose::Meta::Method::Constructor::_generate_triggers which was called 6 times, avg 73µs/call:
# 6 times (310µs+125µs) by Moose::Meta::Method::Constructor::_initialize_body at line 70, avg 73µs/call | ||||
| 160 | 6 | 4µs | my $self = shift; | ||
| 161 | 6 | 2µs | my @trigger_calls; | ||
| 162 | 6 | 43µs | 6 | 8µs | foreach my $i ( 0 .. $#{ $self->_attributes } ) { # spent 8µs making 6 calls to Class::MOP::Method::Constructor::_attributes, avg 1µs/call |
| 163 | 32 | 32µs | 32 | 36µs | my $attr = $self->_attributes->[$i]; # spent 36µs making 32 calls to Class::MOP::Method::Constructor::_attributes, avg 1µs/call |
| 164 | |||||
| 165 | 32 | 124µs | 64 | 68µs | next unless $attr->can('has_trigger') && $attr->has_trigger; # spent 39µs making 32 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 1µs/call
# spent 28µs making 32 calls to UNIVERSAL::can, avg 891ns/call |
| 166 | |||||
| 167 | 1 | 2µs | 1 | 2µs | my $init_arg = $attr->init_arg; # spent 2µs making 1 call to Class::MOP::Mixin::AttributeCore::init_arg |
| 168 | |||||
| 169 | 1 | 500ns | next unless defined $init_arg; | ||
| 170 | |||||
| 171 | 1 | 18µs | 3 | 12µs | push @trigger_calls => '(exists $params->{\'' # spent 8µs making 1 call to Class::MOP::Instance::inline_get_slot_value
# spent 2µs making 1 call to Class::MOP::Method::Constructor::_meta_instance
# spent 1µs making 1 call to Class::MOP::Mixin::AttributeCore::name |
| 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 | 6 | 25µs | return join ";\n" => @trigger_calls; | ||
| 188 | } | ||||
| 189 | |||||
| 190 | # spent 3.13ms (1.32+1.82) within Moose::Meta::Method::Constructor::_generate_slot_initializer which was called 32 times, avg 98µs/call:
# 32 times (1.32ms+1.82ms) by Moose::Meta::Method::Constructor::_generate_slot_initializers at line 127, avg 98µs/call | ||||
| 191 | 32 | 9µs | my $self = shift; | ||
| 192 | 32 | 10µs | my $index = shift; | ||
| 193 | |||||
| 194 | 32 | 33µs | 32 | 37µs | my $attr = $self->_attributes->[$index]; # spent 37µs making 32 calls to Class::MOP::Method::Constructor::_attributes, avg 1µs/call |
| 195 | |||||
| 196 | 32 | 99µs | 32 | 20µs | my @source = ('## ' . $attr->name); # spent 20µs making 32 calls to Class::MOP::Mixin::AttributeCore::name, avg 613ns/call |
| 197 | |||||
| 198 | 32 | 85µs | 32 | 22µs | my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME # spent 22µs making 32 calls to UNIVERSAL::isa, avg 678ns/call |
| 199 | |||||
| 200 | 32 | 190µs | 124 | 162µs | if ($is_moose && defined($attr->init_arg) && $attr->is_required && !$attr->has_default && !$attr->has_builder) { # spent 56µs making 44 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 1µs/call
# spent 48µs making 32 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 2µs/call
# spent 24µs making 12 calls to Moose::Meta::Method::_inline_throw_error, avg 2µs/call
# spent 15µs making 12 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 1µs/call
# spent 13µs making 12 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call
# spent 5µs making 12 calls to Class::MOP::Mixin::AttributeCore::name, avg 425ns/call |
| 201 | push @source => ('(exists $params->{\'' . $attr->init_arg . '\'}) ' . | ||||
| 202 | '|| ' . $self->_inline_throw_error('"Attribute (' . quotemeta($attr->name) . ') is required"') .';'); | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | 32 | 107µs | 89 | 95µs | if (($attr->has_default || $attr->has_builder) && !($is_moose && $attr->is_lazy)) { # spent 37µs making 32 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call
# spent 23µs making 25 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 904ns/call
# spent 21µs making 21 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 995ns/call
# spent 14µs making 11 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 1µs/call |
| 206 | |||||
| 207 | 7 | 10µs | 7 | 6µs | if ( defined( my $init_arg = $attr->init_arg ) ) { # spent 6µs making 7 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 900ns/call |
| 208 | 7 | 7µs | push @source => 'if (exists $params->{\'' . $init_arg . '\'}) {'; | ||
| 209 | 7 | 4µs | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | ||
| 210 | 7 | 13µs | 7 | 134µs | push @source => $self->_generate_type_constraint_and_coercion($attr, $index) # spent 134µs making 7 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 19µs/call |
| 211 | if $is_moose; | ||||
| 212 | 7 | 14µs | 7 | 196µs | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 196µs making 7 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 28µs/call |
| 213 | 7 | 4µs | push @source => "} else {"; | ||
| 214 | } | ||||
| 215 | 7 | 1µs | my $default; | ||
| 216 | 7 | 22µs | 14 | 93µs | if ( $attr->has_default ) { # spent 85µs making 7 calls to Moose::Meta::Method::Constructor::_generate_default_value, avg 12µs/call
# spent 8µs making 7 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 | 7 | 4µs | push @source => '{'; # wrap this to avoid my $val overwrite warnings | ||
| 225 | 7 | 7µs | push @source => ('my $val = ' . $default . ';'); | ||
| 226 | 7 | 11µs | 7 | 91µs | push @source => $self->_generate_type_constraint_and_coercion($attr, $index) # spent 91µs making 7 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 13µs/call |
| 227 | if $is_moose; | ||||
| 228 | 7 | 12µs | 7 | 188µs | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 188µs making 7 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 27µs/call |
| 229 | 7 | 4µs | push @source => '}'; # close - wrap this to avoid my $val overrite warnings | ||
| 230 | |||||
| 231 | 7 | 13µs | 7 | 8µs | push @source => "}" if defined $attr->init_arg; # spent 8µs making 7 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 1µs/call |
| 232 | } | ||||
| 233 | elsif ( defined( my $init_arg = $attr->init_arg ) ) { | ||||
| 234 | 25 | 21µs | push @source => '(exists $params->{\'' . $init_arg . '\'}) && do {'; | ||
| 235 | |||||
| 236 | 25 | 13µs | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | ||
| 237 | 25 | 34µs | 25 | 33µs | if ($is_moose && $attr->has_type_constraint) { # spent 33µs making 25 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call |
| 238 | 7 | 7µs | 7 | 9µs | if ($attr->should_coerce && $attr->type_constraint->has_coercion) { # spent 9µs making 7 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 1µs/call |
| 239 | push @source => $self->_generate_type_coercion( | ||||
| 240 | $attr, | ||||
| 241 | '$type_constraints[' . $index . ']', | ||||
| 242 | '$val', | ||||
| 243 | '$val' | ||||
| 244 | ); | ||||
| 245 | } | ||||
| 246 | 7 | 16µs | 7 | 66µs | push @source => $self->_generate_type_constraint_check( # spent 66µs making 7 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_check, avg 9µs/call |
| 247 | $attr, | ||||
| 248 | '$type_constraint_bodies[' . $index . ']', | ||||
| 249 | '$type_constraints[' . $index . ']', | ||||
| 250 | '$val' | ||||
| 251 | ); | ||||
| 252 | } | ||||
| 253 | 25 | 40µs | 25 | 659µs | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 659µs making 25 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 26µs/call |
| 254 | |||||
| 255 | 25 | 11µs | push @source => "}"; | ||
| 256 | } | ||||
| 257 | |||||
| 258 | 32 | 134µs | return join "\n" => @source; | ||
| 259 | } | ||||
| 260 | |||||
| 261 | # spent 1.04ms (584µs+458µs) within Moose::Meta::Method::Constructor::_generate_slot_assignment which was called 39 times, avg 27µs/call:
# 25 times (366µs+293µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 253, avg 26µs/call
# 7 times (112µs+84µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 212, avg 28µs/call
# 7 times (106µs+82µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 228, avg 27µs/call | ||||
| 262 | 39 | 21µs | my ($self, $attr, $value, $index) = @_; | ||
| 263 | |||||
| 264 | 39 | 2µs | my $source; | ||
| 265 | |||||
| 266 | 39 | 58µs | 39 | 48µs | if ($attr->has_initializer) { # spent 48µs making 39 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 | 39 | 166µs | 117 | 328µs | $source = ( # spent 247µs making 39 calls to Class::MOP::Instance::inline_set_slot_value, avg 6µs/call
# spent 61µs making 39 calls to Class::MOP::Method::Constructor::_meta_instance, avg 2µs/call
# spent 20µs making 39 calls to Class::MOP::Mixin::AttributeCore::name, avg 515ns/call |
| 273 | $self->_meta_instance->inline_set_slot_value( | ||||
| 274 | '$instance', | ||||
| 275 | $attr->name, | ||||
| 276 | $value | ||||
| 277 | ) . ';' | ||||
| 278 | ); | ||||
| 279 | } | ||||
| 280 | |||||
| 281 | 39 | 99µs | 39 | 28µs | my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME # spent 28µs making 39 calls to UNIVERSAL::isa, avg 718ns/call |
| 282 | |||||
| 283 | 39 | 43µs | 39 | 54µs | if ($is_moose && $attr->is_weak_ref) { # spent 54µs making 39 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 1µ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 | 39 | 91µs | return $source; | ||
| 295 | } | ||||
| 296 | |||||
| 297 | # spent 225µs (121+104) within Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion which was called 14 times, avg 16µs/call:
# 7 times (76µs+58µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 210, avg 19µs/call
# 7 times (45µs+46µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 226, avg 13µs/call | ||||
| 298 | 14 | 7µs | my ($self, $attr, $index) = @_; | ||
| 299 | |||||
| 300 | 14 | 39µs | 14 | 19µs | return unless $attr->has_type_constraint; # spent 19µs making 14 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call |
| 301 | |||||
| 302 | 8 | 500ns | my @source; | ||
| 303 | 8 | 7µs | 8 | 9µs | if ($attr->should_coerce && $attr->type_constraint->has_coercion) { # spent 9µs making 8 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 1µs/call |
| 304 | push @source => $self->_generate_type_coercion( | ||||
| 305 | $attr, | ||||
| 306 | '$type_constraints[' . $index . ']', | ||||
| 307 | '$val', | ||||
| 308 | '$val' | ||||
| 309 | ); | ||||
| 310 | } | ||||
| 311 | 8 | 16µs | 8 | 76µs | push @source => $self->_generate_type_constraint_check( # spent 76µs making 8 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_check, avg 9µs/call |
| 312 | $attr, | ||||
| 313 | ('$type_constraint_bodies[' . $index . ']'), | ||||
| 314 | ('$type_constraints[' . $index . ']'), | ||||
| 315 | '$val' | ||||
| 316 | ); | ||||
| 317 | 8 | 19µs | 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 | # spent 142µs (107+35) within Moose::Meta::Method::Constructor::_generate_type_constraint_check which was called 15 times, avg 9µs/call:
# 8 times (57µs+18µs) by Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion at line 311, avg 9µs/call
# 7 times (49µs+17µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 246, avg 9µs/call | ||||
| 326 | 15 | 10µs | my ($self, $attr, $type_constraint_cv, $type_constraint_obj, $value_name) = @_; | ||
| 327 | return ( | ||||
| 328 | 15 | 96µs | 30 | 35µs | $self->_inline_throw_error('"Attribute (' # FIXME add 'dad' # spent 29µs making 15 calls to Moose::Meta::Method::_inline_throw_error, avg 2µs/call
# spent 7µs making 15 calls to Class::MOP::Mixin::AttributeCore::name, avg 433ns/call |
| 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 85µs (59+26) within Moose::Meta::Method::Constructor::_generate_default_value which was called 7 times, avg 12µs/call:
# 7 times (59µs+26µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 216, avg 12µs/call | ||||
| 337 | 7 | 4µ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 | 7 | 21µs | 7 | 16µs | if ($attr->is_default_a_coderef) { # spent 16µs making 7 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 2µs/call |
| 345 | return '$attrs->[' . $index . ']->default($instance)'; | ||||
| 346 | } | ||||
| 347 | else { | ||||
| 348 | 4 | 21µs | 4 | 10µs | return q{"} . quotemeta( $attr->default ) . q{"}; # spent 10µs making 4 calls to Class::MOP::Mixin::AttributeCore::default, avg 2µs/call |
| 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 |