| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Method/Constructor.pm |
| Statements | Executed 6061 statements in 88.0ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 130 | 1 | 1 | 29.6ms | 90.3ms | Moose::Meta::Method::Constructor::_generate_slot_initializer |
| 42 | 1 | 1 | 17.5ms | 357ms | Moose::Meta::Method::Constructor::_initialize_body |
| 170 | 3 | 1 | 7.39ms | 39.0ms | Moose::Meta::Method::Constructor::_generate_slot_assignment |
| 42 | 1 | 1 | 6.70ms | 10.1ms | Moose::Meta::Method::Constructor::_generate_triggers |
| 42 | 1 | 1 | 5.70ms | 363ms | Moose::Meta::Method::Constructor::new |
| 42 | 1 | 1 | 4.20ms | 111ms | Moose::Meta::Method::Constructor::_generate_slot_initializers |
| 42 | 1 | 1 | 3.73ms | 53.3ms | Moose::Meta::Method::Constructor::_generate_BUILDARGS |
| 64 | 2 | 1 | 2.86ms | 4.19ms | Moose::Meta::Method::Constructor::_generate_type_constraint_check |
| 42 | 2 | 2 | 2.15ms | 50.8ms | Moose::Meta::Method::Constructor::_generate_BUILDALL |
| 26 | 2 | 1 | 1.90ms | 4.18ms | Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion |
| 42 | 1 | 1 | 1.80ms | 16.1ms | Moose::Meta::Method::Constructor::_generate_instance |
| 42 | 1 | 1 | 1.44ms | 54.7ms | Moose::Meta::Method::Constructor::_generate_params |
| 42 | 1 | 1 | 610µs | 610µs | Moose::Meta::Method::Constructor::_generate_fallback_constructor |
| 1 | 1 | 1 | 75µs | 94µs | Moose::Meta::Method::Constructor::BEGIN@4 |
| 1 | 1 | 1 | 41µs | 469µs | Moose::Meta::Method::Constructor::BEGIN@13 |
| 1 | 1 | 1 | 39µs | 323µs | Moose::Meta::Method::Constructor::BEGIN@8 |
| 1 | 1 | 1 | 37µs | 106µs | Moose::Meta::Method::Constructor::BEGIN@5 |
| 1 | 1 | 1 | 18µs | 18µ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 | 100µs | 2 | 112µs | # spent 94µs (75+19) within Moose::Meta::Method::Constructor::BEGIN@4 which was called:
# once (75µs+19µs) by Moose::Meta::Class::BEGIN@23 at line 4 # spent 94µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 92µs | 2 | 175µs | # spent 106µs (37+69) within Moose::Meta::Method::Constructor::BEGIN@5 which was called:
# once (37µs+69µs) by Moose::Meta::Class::BEGIN@23 at line 5 # spent 106µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@5
# spent 69µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 112µs | 1 | 18µs | # spent 18µs within Moose::Meta::Method::Constructor::BEGIN@7 which was called:
# once (18µs+0s) by Moose::Meta::Class::BEGIN@23 at line 7 # spent 18µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@7 |
| 8 | 3 | 233µs | 2 | 608µs | # spent 323µs (39+285) within Moose::Meta::Method::Constructor::BEGIN@8 which was called:
# once (39µs+285µs) by Moose::Meta::Class::BEGIN@23 at line 8 # spent 323µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@8
# spent 285µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 32µs | our $VERSION = '1.19'; | ||
| 11 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 12 | |||||
| 13 | 1 | 25µs | 1 | 428µs | # spent 469µs (41+429) within Moose::Meta::Method::Constructor::BEGIN@13 which was called:
# once (41µs+429µs) by Moose::Meta::Class::BEGIN@23 at line 14 # spent 428µs making 1 call to base::import |
| 14 | 2 | 5.63ms | 1 | 469µs | 'Class::MOP::Method::Constructor'; # spent 469µs making 1 call to Moose::Meta::Method::Constructor::BEGIN@13 |
| 15 | |||||
| 16 | # spent 363ms (5.70+358) within Moose::Meta::Method::Constructor::new which was called 42 times, avg 8.65ms/call:
# 42 times (5.70ms+358ms) by Class::MOP::Class::_inline_constructor at line 1330 of Class/MOP/Class.pm, avg 8.65ms/call | ||||
| 17 | 42 | 174µs | my $class = shift; | ||
| 18 | 42 | 481µs | my %options = @_; | ||
| 19 | |||||
| 20 | 42 | 153µs | my $meta = $options{metaclass}; | ||
| 21 | |||||
| 22 | 42 | 183µs | (ref $options{options} eq 'HASH') | ||
| 23 | || $class->throw_error("You must pass a hash of options", data => $options{options}); | ||||
| 24 | |||||
| 25 | 42 | 118µs | ($options{package_name} && $options{name}) | ||
| 26 | || $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT"); | ||||
| 27 | |||||
| 28 | 42 | 2.60ms | my $self = bless { | ||
| 29 | 'body' => undef, | ||||
| 30 | 'package_name' => $options{package_name}, | ||||
| 31 | 'name' => $options{name}, | ||||
| 32 | 'options' => $options{options}, | ||||
| 33 | 'associated_metaclass' => $meta, | ||||
| 34 | '_expected_method_class' => $options{_expected_method_class} || 'Moose::Object', | ||||
| 35 | } => $class; | ||||
| 36 | |||||
| 37 | # we don't want this creating | ||||
| 38 | # a cycle in the code, if not | ||||
| 39 | # needed | ||||
| 40 | 42 | 940µs | 42 | 327µs | weaken($self->{'associated_metaclass'}); # spent 327µs making 42 calls to Scalar::Util::weaken, avg 8µs/call |
| 41 | |||||
| 42 | 42 | 455µs | 42 | 357ms | $self->_initialize_body; # spent 357ms making 42 calls to Moose::Meta::Method::Constructor::_initialize_body, avg 8.51ms/call |
| 43 | |||||
| 44 | 42 | 887µs | return $self; | ||
| 45 | } | ||||
| 46 | |||||
| 47 | ## method | ||||
| 48 | |||||
| 49 | # spent 357ms (17.5+340) within Moose::Meta::Method::Constructor::_initialize_body which was called 42 times, avg 8.51ms/call:
# 42 times (17.5ms+340ms) by Moose::Meta::Method::Constructor::new at line 42, avg 8.51ms/call | ||||
| 50 | 42 | 136µs | my $self = shift; | ||
| 51 | # TODO: | ||||
| 52 | # the %options should also include a both | ||||
| 53 | # a call 'initializer' and call 'SUPER::' | ||||
| 54 | # options, which should cover approx 90% | ||||
| 55 | # of the possible use cases (even if it | ||||
| 56 | # requires some adaption on the part of | ||||
| 57 | # the author, after all, nothing is free) | ||||
| 58 | 42 | 160µs | my $source = 'sub {'; | ||
| 59 | 42 | 182µs | $source .= "\n" . 'my $_instance = shift;'; | ||
| 60 | |||||
| 61 | 42 | 94µs | $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;'; | ||
| 62 | |||||
| 63 | 42 | 1.26ms | 84 | 683µs | $source .= "\n" . "if (\$class ne '" . $self->associated_metaclass->name # spent 463µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 11µs/call
# spent 220µs making 42 calls to Class::MOP::Package::name, avg 5µs/call |
| 64 | . "') {"; | ||||
| 65 | 42 | 536µs | 42 | 610µs | $source .= "\n return " # spent 610µs making 42 calls to Moose::Meta::Method::Constructor::_generate_fallback_constructor, avg 15µs/call |
| 66 | . $self->_generate_fallback_constructor('$class') . ";"; | ||||
| 67 | 42 | 86µs | $source .= "\n}\n"; | ||
| 68 | |||||
| 69 | 42 | 704µs | 42 | 54.7ms | $source .= $self->_generate_params('$params', '$class'); # spent 54.7ms making 42 calls to Moose::Meta::Method::Constructor::_generate_params, avg 1.30ms/call |
| 70 | 42 | 628µs | 42 | 16.1ms | $source .= $self->_generate_instance('$instance', '$class'); # spent 16.1ms making 42 calls to Moose::Meta::Method::Constructor::_generate_instance, avg 383µs/call |
| 71 | 42 | 745µs | 42 | 111ms | $source .= $self->_generate_slot_initializers; # spent 111ms making 42 calls to Moose::Meta::Method::Constructor::_generate_slot_initializers, avg 2.65ms/call |
| 72 | |||||
| 73 | 42 | 607µs | 42 | 10.1ms | $source .= $self->_generate_triggers(); # spent 10.1ms making 42 calls to Moose::Meta::Method::Constructor::_generate_triggers, avg 241µs/call |
| 74 | 42 | 689µs | 42 | 58.5ms | $source .= ";\n" . $self->_generate_BUILDALL(); # spent 48.2ms making 37 calls to Class::MOP::Class::__ANON__::SERIAL::2::_generate_BUILDALL, avg 1.30ms/call
# spent 10.3ms making 5 calls to Moose::Meta::Method::Constructor::_generate_BUILDALL, avg 2.07ms/call |
| 75 | |||||
| 76 | 42 | 108µs | $source .= ";\nreturn \$instance"; | ||
| 77 | 42 | 97µs | $source .= ";\n" . '}'; | ||
| 78 | 42 | 612µs | 42 | 461µs | warn $source if $self->options->{debug}; # spent 461µs making 42 calls to Class::MOP::Method::Constructor::options, avg 11µs/call |
| 79 | |||||
| 80 | # We need to check if the attribute ->can('type_constraint') | ||||
| 81 | # since we may be trying to immutabilize a Moose meta class, | ||||
| 82 | # which in turn has attributes which are Class::MOP::Attribute | ||||
| 83 | # objects, rather than Moose::Meta::Attribute. And | ||||
| 84 | # Class::MOP::Attribute attributes have no type constraints. | ||||
| 85 | # However we need to make sure we leave an undef value there | ||||
| 86 | # because the inlined code is using the index of the attributes | ||||
| 87 | # to determine where to find the type constraint | ||||
| 88 | |||||
| 89 | 42 | 503µs | 42 | 487µs | my $attrs = $self->_attributes; # spent 487µs making 42 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call |
| 90 | |||||
| 91 | 130 | 2.76ms | 190 | 1.55ms | my @type_constraints = map { # spent 786µs making 130 calls to UNIVERSAL::can, avg 6µs/call
# spent 761µs making 60 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 13µs/call |
| 92 | 42 | 606µs | $_->can('type_constraint') ? $_->type_constraint : undef | ||
| 93 | } @$attrs; | ||||
| 94 | |||||
| 95 | 130 | 1.08ms | 60 | 6.83ms | my @type_constraint_bodies = map { # spent 6.61ms making 46 calls to MooseX::Types::TypeDecorator::AUTOLOAD, avg 144µs/call
# spent 225µs making 14 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 16µs/call |
| 96 | 42 | 505µs | defined $_ ? $_->_compiled_type_constraint : undef; | ||
| 97 | } @type_constraints; | ||||
| 98 | |||||
| 99 | 172 | 2.18ms | 130 | 1.87ms | my $defaults = [map { $_->default } @$attrs]; # spent 1.87ms making 130 calls to Class::MOP::Mixin::AttributeCore::default, avg 14µs/call |
| 100 | |||||
| 101 | 42 | 1.21ms | 42 | 76.4ms | my ( $code, $e ) = $self->_compile_code( # spent 76.4ms making 42 calls to Class::MOP::Method::Generated::_compile_code, avg 1.82ms/call |
| 102 | code => $source, | ||||
| 103 | environment => { | ||||
| 104 | '$meta' => \$self, | ||||
| 105 | '$attrs' => \$attrs, | ||||
| 106 | '$defaults' => \$defaults, | ||||
| 107 | '@type_constraints' => \@type_constraints, | ||||
| 108 | '@type_constraint_bodies' => \@type_constraint_bodies, | ||||
| 109 | }, | ||||
| 110 | ); | ||||
| 111 | |||||
| 112 | 42 | 90µs | $self->throw_error( | ||
| 113 | "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e", | ||||
| 114 | error => $e, data => $source ) | ||||
| 115 | if $e; | ||||
| 116 | |||||
| 117 | 42 | 877µs | $self->{'body'} = $code; | ||
| 118 | } | ||||
| 119 | |||||
| 120 | # spent 610µs within Moose::Meta::Method::Constructor::_generate_fallback_constructor which was called 42 times, avg 15µs/call:
# 42 times (610µs+0s) by Moose::Meta::Method::Constructor::_initialize_body at line 65, avg 15µs/call | ||||
| 121 | 42 | 164µs | my ( $self, $class_var ) = @_; | ||
| 122 | 42 | 596µs | "${class_var}->Moose::Object::new(\@_)"; | ||
| 123 | } | ||||
| 124 | |||||
| 125 | # spent 54.7ms (1.44+53.3) within Moose::Meta::Method::Constructor::_generate_params which was called 42 times, avg 1.30ms/call:
# 42 times (1.44ms+53.3ms) by Moose::Meta::Method::Constructor::_initialize_body at line 69, avg 1.30ms/call | ||||
| 126 | 42 | 182µs | my ( $self, $var, $class_var ) = @_; | ||
| 127 | 42 | 1.29ms | 42 | 53.3ms | "my $var = " . $self->_generate_BUILDARGS( $class_var, '@_' ) . ";\n"; # spent 53.3ms making 42 calls to Moose::Meta::Method::Constructor::_generate_BUILDARGS, avg 1.27ms/call |
| 128 | } | ||||
| 129 | |||||
| 130 | # spent 16.1ms (1.80+14.3) within Moose::Meta::Method::Constructor::_generate_instance which was called 42 times, avg 383µs/call:
# 42 times (1.80ms+14.3ms) by Moose::Meta::Method::Constructor::_initialize_body at line 70, avg 383µs/call | ||||
| 131 | 42 | 176µs | my ( $self, $var, $class_var ) = @_; | ||
| 132 | 42 | 1.42ms | 84 | 14.3ms | "my $var = " # spent 13.9ms making 42 calls to Class::MOP::Class::inline_create_instance, avg 330µs/call
# spent 412µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 10µs/call |
| 133 | . $self->associated_metaclass->inline_create_instance($class_var) . ";\n"; | ||||
| 134 | } | ||||
| 135 | |||||
| 136 | # spent 111ms (4.20+107) within Moose::Meta::Method::Constructor::_generate_slot_initializers which was called 42 times, avg 2.65ms/call:
# 42 times (4.20ms+107ms) by Moose::Meta::Method::Constructor::_initialize_body at line 71, avg 2.65ms/call | ||||
| 137 | 42 | 147µs | my ($self) = @_; | ||
| 138 | 130 | 1.52ms | 130 | 90.3ms | return (join ";\n" => map { # spent 90.3ms making 130 calls to Moose::Meta::Method::Constructor::_generate_slot_initializer, avg 694µs/call |
| 139 | $self->_generate_slot_initializer($_) | ||||
| 140 | 42 | 2.05ms | 42 | 16.8ms | } 0 .. (@{$self->_attributes} - 1)) . ";\n"; # spent 16.8ms making 42 calls to Class::MOP::Method::Constructor::_attributes, avg 401µs/call |
| 141 | } | ||||
| 142 | |||||
| 143 | # spent 53.3ms (3.73+49.6) within Moose::Meta::Method::Constructor::_generate_BUILDARGS which was called 42 times, avg 1.27ms/call:
# 42 times (3.73ms+49.6ms) by Moose::Meta::Method::Constructor::_generate_params at line 127, avg 1.27ms/call | ||||
| 144 | 42 | 187µs | my ( $self, $class, $args ) = @_; | ||
| 145 | |||||
| 146 | 42 | 921µs | 84 | 48.5ms | my $buildargs = $self->associated_metaclass->find_method_by_name("BUILDARGS"); # spent 48.2ms making 42 calls to Class::MOP::Class::find_method_by_name, avg 1.15ms/call
# spent 350µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 8µs/call |
| 147 | |||||
| 148 | 42 | 2.47ms | 81 | 1.04ms | if ( $args eq '@_' # spent 823µs making 42 calls to Moose::Meta::Method::_inline_throw_error, avg 20µs/call
# spent 212µs making 39 calls to Class::MOP::Method::body, avg 5µs/call |
| 149 | and ( !$buildargs or $buildargs->body == \&Moose::Object::BUILDARGS ) | ||||
| 150 | ) { | ||||
| 151 | |||||
| 152 | # This is the same logic as Moose::Object::BUILDARGS | ||||
| 153 | return sprintf( <<'EOF', $self->_inline_throw_error( q{'Single parameters to new() must be a HASH ref'}, 'data => $_[0]' ) ); | ||||
| 154 | do { | ||||
| 155 | my $params; | ||||
| 156 | if ( scalar @_ == 1 ) { | ||||
| 157 | unless ( defined $_[0] && ref $_[0] eq 'HASH' ) { | ||||
| 158 | %s | ||||
| 159 | } | ||||
| 160 | $params = { %%{ $_[0] } }; | ||||
| 161 | } | ||||
| 162 | elsif ( @_ %% 2 ) { | ||||
| 163 | Carp::carp( | ||||
| 164 | "The new() method for $class expects a hash reference or a key/value list." | ||||
| 165 | . " You passed an odd number of arguments" ); | ||||
| 166 | $params = { @_, undef }; | ||||
| 167 | } | ||||
| 168 | else { | ||||
| 169 | $params = {@_}; | ||||
| 170 | } | ||||
| 171 | $params | ||||
| 172 | }; | ||||
| 173 | EOF | ||||
| 174 | ; | ||||
| 175 | } | ||||
| 176 | else { | ||||
| 177 | return $class . "->BUILDARGS($args)"; | ||||
| 178 | } | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | # spent 50.8ms (2.15+48.6) within Moose::Meta::Method::Constructor::_generate_BUILDALL which was called 42 times, avg 1.21ms/call:
# 37 times (1.89ms+38.6ms) by Class::MOP::Class:::around at line 18 of MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm, avg 1.09ms/call
# 5 times (268µs+10.1ms) by Moose::Meta::Method::Constructor::_initialize_body at line 74, avg 2.07ms/call | ||||
| 182 | 42 | 118µs | my $self = shift; | ||
| 183 | 42 | 122µs | my @BUILD_calls; | ||
| 184 | 42 | 1.13ms | 84 | 48.6ms | foreach my $method (reverse $self->associated_metaclass->find_all_methods_by_name('BUILD')) { # spent 48.3ms making 42 calls to Class::MOP::Class::find_all_methods_by_name, avg 1.15ms/call
# spent 390µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 9µs/call |
| 185 | 1 | 14µs | push @BUILD_calls => '$instance->' . $method->{class} . '::BUILD($params)'; | ||
| 186 | } | ||||
| 187 | 42 | 659µs | return join ";\n" => @BUILD_calls; | ||
| 188 | } | ||||
| 189 | |||||
| 190 | # spent 10.1ms (6.70+3.44) within Moose::Meta::Method::Constructor::_generate_triggers which was called 42 times, avg 241µs/call:
# 42 times (6.70ms+3.44ms) by Moose::Meta::Method::Constructor::_initialize_body at line 73, avg 241µs/call | ||||
| 191 | 42 | 213µs | my $self = shift; | ||
| 192 | 42 | 80µs | my @trigger_calls; | ||
| 193 | 42 | 1.31ms | 42 | 519µs | foreach my $i ( 0 .. $#{ $self->_attributes } ) { # spent 519µs making 42 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call |
| 194 | 130 | 1.45ms | 130 | 1.44ms | my $attr = $self->_attributes->[$i]; # spent 1.44ms making 130 calls to Class::MOP::Method::Constructor::_attributes, avg 11µs/call |
| 195 | |||||
| 196 | 130 | 3.04ms | 190 | 1.49ms | next unless $attr->can('has_trigger') && $attr->has_trigger; # spent 872µs making 130 calls to UNIVERSAL::can, avg 7µs/call
# spent 616µs making 60 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 10µs/call |
| 197 | |||||
| 198 | my $init_arg = $attr->init_arg; | ||||
| 199 | |||||
| 200 | next unless defined $init_arg; | ||||
| 201 | |||||
| 202 | push @trigger_calls => '(exists $params->{\'' | ||||
| 203 | . $init_arg | ||||
| 204 | . '\'}) && do {' | ||||
| 205 | . "\n " | ||||
| 206 | . '$attrs->[' | ||||
| 207 | . $i | ||||
| 208 | . ']->trigger->(' | ||||
| 209 | . '$instance, ' | ||||
| 210 | . $attr->inline_get('$instance') | ||||
| 211 | . ', ' | ||||
| 212 | . ');' . "\n}"; | ||||
| 213 | } | ||||
| 214 | |||||
| 215 | 42 | 631µs | return join ";\n" => @trigger_calls; | ||
| 216 | } | ||||
| 217 | |||||
| 218 | # spent 90.3ms (29.6+60.7) within Moose::Meta::Method::Constructor::_generate_slot_initializer which was called 130 times, avg 694µs/call:
# 130 times (29.6ms+60.7ms) by Moose::Meta::Method::Constructor::_generate_slot_initializers at line 138, avg 694µs/call | ||||
| 219 | 130 | 399µs | my $self = shift; | ||
| 220 | 130 | 313µs | my $index = shift; | ||
| 221 | |||||
| 222 | 130 | 1.51ms | 130 | 1.57ms | my $attr = $self->_attributes->[$index]; # spent 1.57ms making 130 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call |
| 223 | |||||
| 224 | 130 | 2.95ms | 130 | 866µs | my @source = ('## ' . $attr->name); # spent 866µs making 130 calls to Class::MOP::Mixin::AttributeCore::name, avg 7µs/call |
| 225 | |||||
| 226 | 130 | 2.97ms | 130 | 1.19ms | my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME # spent 1.19ms making 130 calls to UNIVERSAL::isa, avg 9µs/call |
| 227 | |||||
| 228 | 130 | 3.43ms | 248 | 2.88ms | if ($is_moose && defined($attr->init_arg) && $attr->is_required && !$attr->has_default && !$attr->has_builder) { # spent 971µs making 88 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 11µs/call
# spent 683µs making 48 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 14µs/call
# spent 475µs making 28 calls to Moose::Meta::Method::_inline_throw_error, avg 17µs/call
# spent 308µs making 28 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 11µs/call
# spent 300µs making 28 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 11µs/call
# spent 140µs making 28 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call |
| 229 | push @source => ('(exists $params->{\'' . $attr->init_arg . '\'}) ' . | ||||
| 230 | '|| ' . $self->_inline_throw_error('"Attribute (' . quotemeta($attr->name) . ') is required"') .';'); | ||||
| 231 | } | ||||
| 232 | |||||
| 233 | 130 | 3.55ms | 294 | 3.04ms | if (($attr->has_default || $attr->has_builder) && !($is_moose && $attr->is_lazy)) { # spent 1.32ms making 130 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call
# spent 728µs making 72 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call
# spent 698µs making 70 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 10µs/call
# spent 293µs making 22 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 13µs/call |
| 234 | |||||
| 235 | 58 | 836µs | 58 | 626µs | if ( defined( my $init_arg = $attr->init_arg ) ) { # spent 626µs making 58 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 11µs/call |
| 236 | 46 | 268µs | push @source => 'if (exists $params->{\'' . $init_arg . '\'}) {'; | ||
| 237 | 46 | 187µs | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | ||
| 238 | 46 | 228µs | 10 | 1.81ms | push @source => $self->_generate_type_constraint_and_coercion($attr, $index) # spent 1.81ms making 10 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 181µs/call |
| 239 | if $is_moose; | ||||
| 240 | 46 | 624µs | 46 | 10.4ms | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 10.4ms making 46 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 227µs/call |
| 241 | 46 | 184µs | push @source => "} else {"; | ||
| 242 | } | ||||
| 243 | 58 | 107µs | my $default; | ||
| 244 | 58 | 1.37ms | 116 | 3.35ms | if ( $attr->has_default ) { # spent 2.78ms making 58 calls to Class::MOP::Method::Constructor::_generate_default_value, avg 48µs/call
# spent 568µs making 58 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call |
| 245 | $default = $self->_generate_default_value($attr, $index); | ||||
| 246 | } | ||||
| 247 | else { | ||||
| 248 | my $builder = $attr->builder; | ||||
| 249 | $default = '$instance->' . $builder; | ||||
| 250 | } | ||||
| 251 | |||||
| 252 | 58 | 209µs | push @source => '{'; # wrap this to avoid my $val overwrite warnings | ||
| 253 | 58 | 258µs | push @source => ('my $val = ' . $default . ';'); | ||
| 254 | 58 | 279µs | 16 | 2.37ms | push @source => $self->_generate_type_constraint_and_coercion($attr, $index) # spent 2.37ms making 16 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion, avg 148µs/call |
| 255 | if $is_moose; | ||||
| 256 | 58 | 761µs | 58 | 13.1ms | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 13.1ms making 58 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 225µs/call |
| 257 | 58 | 178µs | push @source => '}'; # close - wrap this to avoid my $val overrite warnings | ||
| 258 | |||||
| 259 | 58 | 869µs | 58 | 599µs | push @source => "}" if defined $attr->init_arg; # spent 599µs making 58 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call |
| 260 | } | ||||
| 261 | elsif ( defined( my $init_arg = $attr->init_arg ) ) { | ||||
| 262 | 66 | 359µs | push @source => '(exists $params->{\'' . $init_arg . '\'}) && do {'; | ||
| 263 | |||||
| 264 | 66 | 271µs | push @source => ('my $val = $params->{\'' . $init_arg . '\'};'); | ||
| 265 | 66 | 631µs | 38 | 415µs | if ($is_moose && $attr->has_type_constraint) { # spent 415µs making 38 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 11µs/call |
| 266 | 38 | 460µs | 38 | 492µs | if ($attr->should_coerce && $attr->type_constraint->has_coercion) { # spent 492µs making 38 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 13µs/call |
| 267 | push @source => $self->_generate_type_coercion( | ||||
| 268 | $attr, | ||||
| 269 | '$type_constraints[' . $index . ']', | ||||
| 270 | '$val', | ||||
| 271 | '$val' | ||||
| 272 | ); | ||||
| 273 | } | ||||
| 274 | 38 | 687µs | 38 | 2.48ms | push @source => $self->_generate_type_constraint_check( # spent 2.48ms making 38 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_check, avg 65µs/call |
| 275 | $attr, | ||||
| 276 | '$type_constraint_bodies[' . $index . ']', | ||||
| 277 | '$type_constraints[' . $index . ']', | ||||
| 278 | '$val' | ||||
| 279 | ); | ||||
| 280 | } | ||||
| 281 | 66 | 879µs | 66 | 15.5ms | push @source => $self->_generate_slot_assignment($attr, '$val', $index); # spent 15.5ms making 66 calls to Moose::Meta::Method::Constructor::_generate_slot_assignment, avg 235µs/call |
| 282 | |||||
| 283 | 66 | 254µs | push @source => "}"; | ||
| 284 | } | ||||
| 285 | |||||
| 286 | 130 | 2.94ms | return join "\n" => @source; | ||
| 287 | } | ||||
| 288 | |||||
| 289 | # spent 39.0ms (7.39+31.6) within Moose::Meta::Method::Constructor::_generate_slot_assignment which was called 170 times, avg 229µs/call:
# 66 times (2.86ms+12.7ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 281, avg 235µs/call
# 58 times (2.60ms+10.5ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 256, avg 225µs/call
# 46 times (1.93ms+8.49ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 240, avg 227µs/call | ||||
| 290 | 170 | 662µs | my ($self, $attr, $value, $index) = @_; | ||
| 291 | |||||
| 292 | 170 | 275µs | my $source; | ||
| 293 | |||||
| 294 | 170 | 1.85ms | 170 | 1.65ms | if ( $attr->has_initializer ) { # spent 1.65ms making 170 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 10µs/call |
| 295 | return | ||||
| 296 | '$attrs->[' | ||||
| 297 | . $index | ||||
| 298 | . ']->set_initial_value($instance, ' | ||||
| 299 | . $value . ');'; | ||||
| 300 | } | ||||
| 301 | else { | ||||
| 302 | 170 | 3.94ms | 170 | 30.0ms | return $attr->inline_set( # spent 17.4ms making 106 calls to Class::MOP::Attribute::inline_set, avg 164µs/call
# spent 12.6ms making 64 calls to Moose::Meta::Attribute::inline_set, avg 197µs/call |
| 303 | '$instance', | ||||
| 304 | $value | ||||
| 305 | ) . ';'; | ||||
| 306 | } | ||||
| 307 | |||||
| 308 | return $source; | ||||
| 309 | } | ||||
| 310 | |||||
| 311 | # spent 4.18ms (1.90+2.27) within Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion which was called 26 times, avg 161µs/call:
# 16 times (1.01ms+1.36ms) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 254, avg 148µs/call
# 10 times (890µs+915µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 238, avg 181µs/call | ||||
| 312 | 26 | 96µs | my ($self, $attr, $index) = @_; | ||
| 313 | |||||
| 314 | 26 | 272µs | 26 | 254µs | return unless $attr->has_type_constraint; # spent 254µs making 26 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 10µs/call |
| 315 | |||||
| 316 | 26 | 48µs | my @source; | ||
| 317 | 26 | 289µs | 26 | 310µs | if ($attr->should_coerce && $attr->type_constraint->has_coercion) { # spent 310µs making 26 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 12µs/call |
| 318 | push @source => $self->_generate_type_coercion( | ||||
| 319 | $attr, | ||||
| 320 | '$type_constraints[' . $index . ']', | ||||
| 321 | '$val', | ||||
| 322 | '$val' | ||||
| 323 | ); | ||||
| 324 | } | ||||
| 325 | 26 | 439µs | 26 | 1.71ms | push @source => $self->_generate_type_constraint_check( # spent 1.71ms making 26 calls to Moose::Meta::Method::Constructor::_generate_type_constraint_check, avg 66µs/call |
| 326 | $attr, | ||||
| 327 | ('$type_constraint_bodies[' . $index . ']'), | ||||
| 328 | ('$type_constraints[' . $index . ']'), | ||||
| 329 | '$val' | ||||
| 330 | ); | ||||
| 331 | 26 | 487µs | return @source; | ||
| 332 | } | ||||
| 333 | |||||
| 334 | sub _generate_type_coercion { | ||||
| 335 | my ($self, $attr, $type_constraint_name, $value_name, $return_value_name) = @_; | ||||
| 336 | return ($return_value_name . ' = ' . $type_constraint_name . '->coerce(' . $value_name . ');'); | ||||
| 337 | } | ||||
| 338 | |||||
| 339 | # spent 4.19ms (2.86+1.32) within Moose::Meta::Method::Constructor::_generate_type_constraint_check which was called 64 times, avg 65µs/call:
# 38 times (1.71ms+764µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 274, avg 65µs/call
# 26 times (1.15ms+559µs) by Moose::Meta::Method::Constructor::_generate_type_constraint_and_coercion at line 325, avg 66µs/call | ||||
| 340 | 64 | 325µs | my ($self, $attr, $type_constraint_cv, $type_constraint_obj, $value_name) = @_; | ||
| 341 | return ( | ||||
| 342 | 64 | 2.79ms | 128 | 1.32ms | $self->_inline_throw_error('"Attribute (' # FIXME add 'dad' # spent 1.01ms making 64 calls to Moose::Meta::Method::_inline_throw_error, avg 16µs/call
# spent 310µs making 64 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call |
| 343 | . quotemeta( $attr->name ) | ||||
| 344 | . ') does not pass the type constraint because: " . ' | ||||
| 345 | . $type_constraint_obj . '->get_message(' . $value_name . ')') | ||||
| 346 | . "\n\t unless " . $type_constraint_cv . '->(' . $value_name . ');' | ||||
| 347 | ); | ||||
| 348 | } | ||||
| 349 | |||||
| 350 | 1 | 14µs | 1; | ||
| 351 | |||||
| 352 | __END__ |