| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Constructor.pm |
| Statements | Executed 4739 statements in 61.3ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 265 | 1 | 1 | 21.4ms | 104ms | Class::MOP::Method::Constructor::_generate_slot_initializer |
| 31 | 1 | 1 | 16.3ms | 183ms | Class::MOP::Method::Constructor::_generate_constructor_method_inline |
| 485 | 8 | 3 | 8.12ms | 36.5ms | Class::MOP::Method::Constructor::_attributes |
| 145 | 2 | 2 | 4.54ms | 7.27ms | Class::MOP::Method::Constructor::_generate_default_value |
| 31 | 1 | 1 | 3.32ms | 192ms | Class::MOP::Method::Constructor::new |
| 31 | 1 | 1 | 2.29ms | 2.29ms | Class::MOP::Method::Constructor::_new |
| 31 | 1 | 1 | 1.51ms | 185ms | Class::MOP::Method::Constructor::_initialize_body |
| 1 | 1 | 1 | 73µs | 93µs | Class::MOP::Method::Constructor::BEGIN@4 |
| 1 | 1 | 1 | 43µs | 3.72ms | Class::MOP::Method::Constructor::BEGIN@14 |
| 1 | 1 | 1 | 41µs | 211µs | Class::MOP::Method::Constructor::BEGIN@7 |
| 1 | 1 | 1 | 41µs | 208µs | Class::MOP::Method::Constructor::BEGIN@8 |
| 1 | 1 | 1 | 40µs | 109µs | Class::MOP::Method::Constructor::BEGIN@5 |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Constructor::__ANON__[:92] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Constructor::_generate_constructor_method |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Class::MOP::Method::Constructor; | ||||
| 3 | |||||
| 4 | 3 | 102µs | 2 | 112µs | # spent 93µs (73+20) within Class::MOP::Method::Constructor::BEGIN@4 which was called:
# once (73µs+20µs) by Class::MOP::Class::BEGIN@10 at line 4 # spent 93µs making 1 call to Class::MOP::Method::Constructor::BEGIN@4
# spent 20µs making 1 call to strict::import |
| 5 | 3 | 104µs | 2 | 178µs | # spent 109µs (40+69) within Class::MOP::Method::Constructor::BEGIN@5 which was called:
# once (40µs+69µs) by Class::MOP::Class::BEGIN@10 at line 5 # spent 109µs making 1 call to Class::MOP::Method::Constructor::BEGIN@5
# spent 69µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 139µs | 2 | 382µs | # spent 211µs (41+170) within Class::MOP::Method::Constructor::BEGIN@7 which was called:
# once (41µs+170µs) by Class::MOP::Class::BEGIN@10 at line 7 # spent 211µs making 1 call to Class::MOP::Method::Constructor::BEGIN@7
# spent 170µs making 1 call to Exporter::import |
| 8 | 3 | 232µs | 2 | 376µs | # spent 208µs (41+168) within Class::MOP::Method::Constructor::BEGIN@8 which was called:
# once (41µs+168µs) by Class::MOP::Class::BEGIN@10 at line 8 # spent 208µs making 1 call to Class::MOP::Method::Constructor::BEGIN@8
# spent 168µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 5µs | our $VERSION = '1.11'; | ||
| 11 | 1 | 62µs | $VERSION = eval $VERSION; # spent 12µs executing statements in string eval | ||
| 12 | 1 | 3µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 3.42ms | 2 | 3.72ms | # spent 3.72ms (43µs+3.68) within Class::MOP::Method::Constructor::BEGIN@14 which was called:
# once (43µs+3.68ms) by Class::MOP::Class::BEGIN@10 at line 14 # spent 3.72ms making 1 call to Class::MOP::Method::Constructor::BEGIN@14
# spent 3.68ms making 1 call to base::import, recursion: max depth 1, sum of overlapping time 3.68ms |
| 15 | |||||
| 16 | # spent 192ms (3.32+188) within Class::MOP::Method::Constructor::new which was called 31 times, avg 6.18ms/call:
# 31 times (3.32ms+188ms) by Class::MOP::Class::_inline_constructor at line 1330 of Class/MOP/Class.pm, avg 6.18ms/call | ||||
| 17 | 31 | 119µs | my $class = shift; | ||
| 18 | 31 | 357µs | my %options = @_; | ||
| 19 | |||||
| 20 | 31 | 1.23ms | 62 | 423µs | (blessed $options{metaclass} && $options{metaclass}->isa('Class::MOP::Class')) # spent 223µs making 31 calls to UNIVERSAL::isa, avg 7µs/call
# spent 200µs making 31 calls to Scalar::Util::blessed, avg 6µs/call |
| 21 | || confess "You must pass a metaclass instance if you want to inline" | ||||
| 22 | if $options{is_inline}; | ||||
| 23 | |||||
| 24 | 31 | 117µs | ($options{package_name} && $options{name}) | ||
| 25 | || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT"; | ||||
| 26 | |||||
| 27 | 31 | 427µs | 31 | 2.29ms | my $self = $class->_new(\%options); # spent 2.29ms making 31 calls to Class::MOP::Method::Constructor::_new, avg 74µs/call |
| 28 | |||||
| 29 | # we don't want this creating | ||||
| 30 | # a cycle in the code, if not | ||||
| 31 | # needed | ||||
| 32 | 31 | 633µs | 31 | 233µs | weaken($self->{'associated_metaclass'}); # spent 233µs making 31 calls to Scalar::Util::weaken, avg 8µs/call |
| 33 | |||||
| 34 | 31 | 346µs | 31 | 185ms | $self->_initialize_body; # spent 185ms making 31 calls to Class::MOP::Method::Constructor::_initialize_body, avg 5.98ms/call |
| 35 | |||||
| 36 | 31 | 582µs | return $self; | ||
| 37 | } | ||||
| 38 | |||||
| 39 | # spent 2.29ms within Class::MOP::Method::Constructor::_new which was called 31 times, avg 74µs/call:
# 31 times (2.29ms+0s) by Class::MOP::Method::Constructor::new at line 27, avg 74µs/call | ||||
| 40 | 31 | 103µs | my $class = shift; | ||
| 41 | |||||
| 42 | 31 | 88µs | return Class::MOP::Class->initialize($class)->new_object(@_) | ||
| 43 | if $class ne __PACKAGE__; | ||||
| 44 | |||||
| 45 | 31 | 132µs | my $params = @_ == 1 ? $_[0] : {@_}; | ||
| 46 | |||||
| 47 | 31 | 2.13ms | return bless { | ||
| 48 | # inherited from Class::MOP::Method | ||||
| 49 | body => $params->{body}, | ||||
| 50 | # associated_metaclass => $params->{associated_metaclass}, # overriden | ||||
| 51 | package_name => $params->{package_name}, | ||||
| 52 | name => $params->{name}, | ||||
| 53 | original_method => $params->{original_method}, | ||||
| 54 | |||||
| 55 | # inherited from Class::MOP::Generated | ||||
| 56 | is_inline => $params->{is_inline} || 0, | ||||
| 57 | definition_context => $params->{definition_context}, | ||||
| 58 | |||||
| 59 | # inherited from Class::MOP::Inlined | ||||
| 60 | _expected_method_class => $params->{_expected_method_class}, | ||||
| 61 | |||||
| 62 | # defined in this subclass | ||||
| 63 | options => $params->{options} || {}, | ||||
| 64 | associated_metaclass => $params->{metaclass}, | ||||
| 65 | }, $class; | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | ## accessors | ||||
| 69 | |||||
| 70 | 73 | 1.05ms | sub options { (shift)->{'options'} } | ||
| 71 | 155 | 2.10ms | sub associated_metaclass { (shift)->{'associated_metaclass'} } | ||
| 72 | |||||
| 73 | ## cached values ... | ||||
| 74 | |||||
| 75 | # spent 36.5ms (8.12+28.4) within Class::MOP::Method::Constructor::_attributes which was called 485 times, avg 75µs/call:
# 130 times (1.57ms+0s) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 222 of Moose/Meta/Method/Constructor.pm, avg 12µs/call
# 130 times (1.44ms+0s) by Moose::Meta::Method::Constructor::_generate_triggers at line 194 of Moose/Meta/Method/Constructor.pm, avg 11µs/call
# 42 times (1.88ms+14.9ms) by Moose::Meta::Method::Constructor::_generate_slot_initializers at line 140 of Moose/Meta/Method/Constructor.pm, avg 401µs/call
# 42 times (519µs+0s) by Moose::Meta::Method::Constructor::_generate_triggers at line 193 of Moose/Meta/Method/Constructor.pm, avg 12µs/call
# 42 times (487µs+0s) by Moose::Meta::Method::Constructor::_initialize_body at line 89 of Moose/Meta/Method/Constructor.pm, avg 12µs/call
# 37 times (519µs+0s) by Class::MOP::Class:::around at line 25 of MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm, avg 14µs/call
# 31 times (1.33ms+13.5ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 98, avg 477µs/call
# 31 times (369µs+0s) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 116, avg 12µs/call | ||||
| 76 | 485 | 1.29ms | my $self = shift; | ||
| 77 | 485 | 8.37ms | 146 | 28.4ms | $self->{'attributes'} ||= [ $self->associated_metaclass->get_all_attributes ] # spent 27.8ms making 73 calls to Class::MOP::Class::get_all_attributes, avg 381µs/call
# spent 342µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 8µs/call
# spent 281µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 9µs/call |
| 78 | } | ||||
| 79 | |||||
| 80 | ## method | ||||
| 81 | |||||
| 82 | # spent 185ms (1.51+184) within Class::MOP::Method::Constructor::_initialize_body which was called 31 times, avg 5.98ms/call:
# 31 times (1.51ms+184ms) by Class::MOP::Method::Constructor::new at line 34, avg 5.98ms/call | ||||
| 83 | 31 | 96µs | my $self = shift; | ||
| 84 | 31 | 84µs | my $method_name = '_generate_constructor_method'; | ||
| 85 | |||||
| 86 | 31 | 372µs | 31 | 319µs | $method_name .= '_inline' if $self->is_inline; # spent 319µs making 31 calls to Class::MOP::Method::Generated::is_inline, avg 10µs/call |
| 87 | |||||
| 88 | 31 | 818µs | 31 | 183ms | $self->{'body'} = $self->$method_name; # spent 183ms making 31 calls to Class::MOP::Method::Constructor::_generate_constructor_method_inline, avg 5.92ms/call |
| 89 | } | ||||
| 90 | |||||
| 91 | sub _generate_constructor_method { | ||||
| 92 | return sub { Class::MOP::Class->initialize(shift)->new_object(@_) } | ||||
| 93 | } | ||||
| 94 | |||||
| 95 | # spent 183ms (16.3+167) within Class::MOP::Method::Constructor::_generate_constructor_method_inline which was called 31 times, avg 5.92ms/call:
# 31 times (16.3ms+167ms) by Class::MOP::Method::Constructor::_initialize_body at line 88, avg 5.92ms/call | ||||
| 96 | 31 | 96µs | my $self = shift; | ||
| 97 | |||||
| 98 | 296 | 3.95ms | 296 | 18.4ms | my $defaults = [map { $_->default } @{ $self->_attributes }]; # spent 14.8ms making 31 calls to Class::MOP::Method::Constructor::_attributes, avg 477µs/call
# spent 3.64ms making 265 calls to Class::MOP::Mixin::AttributeCore::default, avg 14µs/call |
| 99 | |||||
| 100 | 31 | 200µs | my $close_over = { | ||
| 101 | '$defaults' => \$defaults, | ||||
| 102 | }; | ||||
| 103 | |||||
| 104 | 31 | 80µs | my $source = 'sub {'; | ||
| 105 | 31 | 103µs | $source .= "\n" . 'my $class = shift;'; | ||
| 106 | |||||
| 107 | 31 | 96µs | $source .= "\n" . 'return Class::MOP::Class->initialize($class)->new_object(@_)'; | ||
| 108 | 31 | 900µs | 62 | 481µs | $source .= "\n" . ' if $class ne \'' . $self->associated_metaclass->name . '\';'; # spent 293µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 9µs/call
# spent 189µs making 31 calls to Class::MOP::Package::name, avg 6µs/call |
| 109 | |||||
| 110 | 31 | 76µs | $source .= "\n" . 'my $params = @_ == 1 ? $_[0] : {@_};'; | ||
| 111 | |||||
| 112 | 31 | 668µs | 62 | 10.0ms | $source .= "\n" . 'my $instance = ' . $self->associated_metaclass->inline_create_instance('$class'); # spent 9.74ms making 31 calls to Class::MOP::Class::inline_create_instance, avg 314µs/call
# spent 264µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 9µs/call |
| 113 | 31 | 80µs | my $idx = 0; | ||
| 114 | 265 | 3.22ms | 265 | 104ms | $source .= ";\n" . (join ";\n" => map { # spent 104ms making 265 calls to Class::MOP::Method::Constructor::_generate_slot_initializer, avg 392µs/call |
| 115 | $self->_generate_slot_initializer($_, $idx++) | ||||
| 116 | 31 | 1.81ms | 31 | 369µs | } @{ $self->_attributes }); # spent 369µs making 31 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call |
| 117 | 31 | 1.10ms | 93 | 1.34ms | if (Class::MOP::metaclass_is_weak($self->associated_metaclass->name)) { # spent 806µs making 31 calls to Class::MOP::metaclass_is_weak, avg 26µs/call
# spent 333µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 11µs/call
# spent 198µs making 31 calls to Class::MOP::Package::name, avg 6µs/call |
| 118 | $source .= ";\n" . $self->associated_metaclass->_inline_set_mop_slot('$instance', 'Class::MOP::class_of($class)'); | ||||
| 119 | } | ||||
| 120 | 31 | 100µs | $source .= ";\n" . 'return $instance'; | ||
| 121 | 31 | 68µs | $source .= ";\n" . '}'; | ||
| 122 | 31 | 453µs | 31 | 355µs | warn $source if $self->options->{debug}; # spent 355µs making 31 calls to Class::MOP::Method::Constructor::options, avg 11µs/call |
| 123 | |||||
| 124 | 31 | 505µs | 31 | 32.2ms | my ( $code, $e ) = $self->_eval_closure( # spent 32.2ms making 31 calls to Class::MOP::Method::Generated::_eval_closure, avg 1.04ms/call |
| 125 | $close_over, | ||||
| 126 | $source | ||||
| 127 | ); | ||||
| 128 | 31 | 65µs | confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e" if $e; | ||
| 129 | |||||
| 130 | 31 | 485µs | return $code; | ||
| 131 | } | ||||
| 132 | |||||
| 133 | # spent 104ms (21.4+82.6) within Class::MOP::Method::Constructor::_generate_slot_initializer which was called 265 times, avg 392µs/call:
# 265 times (21.4ms+82.6ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 114, avg 392µs/call | ||||
| 134 | 265 | 740µs | my $self = shift; | ||
| 135 | 265 | 577µs | my $attr = shift; | ||
| 136 | 265 | 540µs | my $idx = shift; | ||
| 137 | |||||
| 138 | 265 | 501µs | my $default; | ||
| 139 | 265 | 5.24ms | 530 | 8.90ms | if ($attr->has_default) { # spent 4.49ms making 87 calls to Class::MOP::Method::Constructor::_generate_default_value, avg 52µs/call
# spent 2.62ms making 265 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call
# spent 1.78ms making 178 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 10µs/call |
| 140 | $default = $self->_generate_default_value($attr, $idx); | ||||
| 141 | } elsif( $attr->has_builder ) { | ||||
| 142 | $default = '$instance->'.$attr->builder; | ||||
| 143 | } | ||||
| 144 | |||||
| 145 | 265 | 10.7ms | 606 | 73.7ms | if ( defined( my $init_arg = $attr->init_arg ) ) { # spent 69.8ms making 339 calls to Class::MOP::Attribute::inline_set, avg 206µs/call
# spent 2.66ms making 265 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call
# spent 1.19ms making 2 calls to Moose::Meta::Attribute::inline_set, avg 595µs/call |
| 146 | return ( | ||||
| 147 | 'if(exists $params->{\'' | ||||
| 148 | . $init_arg . '\'}){' . "\n" | ||||
| 149 | . $attr->inline_set( | ||||
| 150 | '$instance', | ||||
| 151 | '$params->{\'' . $init_arg . '\'}' | ||||
| 152 | ) | ||||
| 153 | . "\n" . '} ' | ||||
| 154 | . ( | ||||
| 155 | !defined $default ? '' : 'else {' . "\n" | ||||
| 156 | . $attr->inline_set( | ||||
| 157 | '$instance', | ||||
| 158 | $default | ||||
| 159 | ) | ||||
| 160 | . "\n" . '}' | ||||
| 161 | ) | ||||
| 162 | ); | ||||
| 163 | } | ||||
| 164 | elsif ( defined $default ) { | ||||
| 165 | return ( | ||||
| 166 | $attr->inline_set( | ||||
| 167 | '$instance', | ||||
| 168 | $default | ||||
| 169 | ) | ||||
| 170 | . "\n" | ||||
| 171 | ); | ||||
| 172 | } | ||||
| 173 | else { | ||||
| 174 | 1 | 13µs | return ''; | ||
| 175 | } | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | # spent 7.27ms (4.54+2.73) within Class::MOP::Method::Constructor::_generate_default_value which was called 145 times, avg 50µs/call:
# 87 times (2.75ms+1.74ms) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 139, avg 52µs/call
# 58 times (1.79ms+991µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 244 of Moose/Meta/Method/Constructor.pm, avg 48µs/call | ||||
| 179 | 145 | 539µs | my ($self, $attr, $index) = @_; | ||
| 180 | # NOTE: | ||||
| 181 | # default values can either be CODE refs | ||||
| 182 | # in which case we need to call them. Or | ||||
| 183 | # they can be scalars (strings/numbers) | ||||
| 184 | # in which case we can just deal with them | ||||
| 185 | # in the code we eval. | ||||
| 186 | 145 | 2.88ms | 145 | 2.73ms | if ($attr->is_default_a_coderef) { # spent 2.73ms making 145 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 19µs/call |
| 187 | return '$defaults->[' . $index . ']->($instance)'; | ||||
| 188 | } | ||||
| 189 | else { | ||||
| 190 | 57 | 972µs | return '$defaults->[' . $index . ']'; | ||
| 191 | } | ||||
| 192 | } | ||||
| 193 | |||||
| 194 | 1 | 13µs | 1; | ||
| 195 | |||||
| 196 | __END__ |