| Filename | /home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm |
| Statements | Executed 4123 statements in 68.1ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1063 | 1 | 1 | 21.0ms | 124ms | Class::MOP::Method::Wrapped::__ANON__[:159] (recurses: max depth 3, inclusive time 5.27ms) |
| 66 | 2 | 1 | 8.23ms | 21.7ms | Class::MOP::Method::Wrapped::wrap |
| 61 | 1 | 1 | 4.09ms | 8.24ms | Class::MOP::Method::Wrapped::add_around_modifier |
| 66 | 1 | 1 | 3.79ms | 3.79ms | Class::MOP::Method::Wrapped::_new |
| 134 | 4 | 1 | 3.57ms | 3.57ms | Class::MOP::Method::Wrapped::__ANON__[:69] |
| 61 | 1 | 1 | 2.36ms | 2.36ms | Class::MOP::Method::Wrapped::__ANON__[:161] |
| 5 | 1 | 1 | 244µs | 438µs | Class::MOP::Method::Wrapped::add_before_modifier |
| 2 | 1 | 1 | 179µs | 719ms | Class::MOP::Method::Wrapped::__ANON__[:43] |
| 2 | 1 | 1 | 111µs | 3.27ms | Class::MOP::Method::Wrapped::__ANON__[:49] |
| 2 | 1 | 1 | 71µs | 146µs | Class::MOP::Method::Wrapped::add_after_modifier |
| 1 | 1 | 1 | 67µs | 86µs | Class::MOP::Method::Wrapped::BEGIN@4 |
| 1 | 1 | 1 | 39µs | 295µs | Class::MOP::Method::Wrapped::BEGIN@14 |
| 1 | 1 | 1 | 38µs | 107µs | Class::MOP::Method::Wrapped::BEGIN@5 |
| 1 | 1 | 1 | 37µs | 194µs | Class::MOP::Method::Wrapped::BEGIN@7 |
| 1 | 1 | 1 | 36µs | 163µs | Class::MOP::Method::Wrapped::BEGIN@8 |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:64] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:89] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::_make_compatible_with |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::after_modifiers |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::around_modifiers |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::before_modifiers |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::get_original_method |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Class::MOP::Method::Wrapped; | ||||
| 3 | |||||
| 4 | 3 | 97µs | 2 | 104µs | # spent 86µs (67+19) within Class::MOP::Method::Wrapped::BEGIN@4 which was called:
# once (67µs+19µs) by Class::MOP::Class::BEGIN@8 at line 4 # spent 86µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@4
# spent 18µs making 1 call to strict::import |
| 5 | 3 | 102µs | 2 | 176µs | # spent 107µs (38+69) within Class::MOP::Method::Wrapped::BEGIN@5 which was called:
# once (38µs+69µs) by Class::MOP::Class::BEGIN@8 at line 5 # spent 107µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@5
# spent 69µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 101µs | 2 | 351µs | # spent 194µs (37+157) within Class::MOP::Method::Wrapped::BEGIN@7 which was called:
# once (37µs+157µs) by Class::MOP::Class::BEGIN@8 at line 7 # spent 194µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@7
# spent 157µs making 1 call to Exporter::import |
| 8 | 3 | 231µs | 2 | 290µs | # spent 163µs (36+127) within Class::MOP::Method::Wrapped::BEGIN@8 which was called:
# once (36µs+127µs) by Class::MOP::Class::BEGIN@8 at line 8 # spent 163µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@8
# spent 127µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 6µs | our $VERSION = '1.11'; | ||
| 11 | 1 | 62µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 12 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 3.37ms | 2 | 551µs | # spent 295µs (39+256) within Class::MOP::Method::Wrapped::BEGIN@14 which was called:
# once (39µs+256µs) by Class::MOP::Class::BEGIN@8 at line 14 # spent 295µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@14
# spent 256µs making 1 call to base::import |
| 15 | |||||
| 16 | # NOTE: | ||||
| 17 | # this ugly beast is the result of trying | ||||
| 18 | # to micro optimize this as much as possible | ||||
| 19 | # while not completely loosing maintainability. | ||||
| 20 | # At this point it's "fast enough", after all | ||||
| 21 | # you can't get something for nothing :) | ||||
| 22 | # spent 3.57ms within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:69] which was called 134 times, avg 27µs/call:
# 66 times (1.82ms+0s) by Class::MOP::Method::Wrapped::wrap at line 87, avg 28µs/call
# 61 times (1.49ms+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 171, avg 24µs/call
# 5 times (194µs+0s) by Class::MOP::Method::Wrapped::add_before_modifier at line 128, avg 39µs/call
# 2 times (75µs+0s) by Class::MOP::Method::Wrapped::add_after_modifier at line 140, avg 37µs/call | ||||
| 23 | 536 | 4.12ms | my $modifier_table = shift; | ||
| 24 | my ($before, $after, $around) = ( | ||||
| 25 | $modifier_table->{before}, | ||||
| 26 | $modifier_table->{after}, | ||||
| 27 | $modifier_table->{around}, | ||||
| 28 | ); | ||||
| 29 | if (@$before && @$after) { | ||||
| 30 | # spent 719ms (179µs+719) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:43] which was called 2 times, avg 360ms/call:
# 2 times (179µs+719ms) by Class::MOP::Class::__ANON__::SERIAL::2::install_accessors or Class::MOP::Class::__ANON__::SERIAL::5::install_accessors at line 89, avg 360ms/call | ||||
| 31 | 14 | 200µs | 2 | 674ms | for my $c (@$before) { $c->(@_) }; # spent 674ms making 2 calls to Class::MOP::Class:::before, avg 337ms/call |
| 32 | my @rval; | ||||
| 33 | 2 | 44.8ms | ((defined wantarray) ? # spent 44.8ms making 2 calls to Moose::Meta::Attribute::install_accessors, avg 22.4ms/call | ||
| 34 | ((wantarray) ? | ||||
| 35 | (@rval = $around->{cache}->(@_)) | ||||
| 36 | : | ||||
| 37 | ($rval[0] = $around->{cache}->(@_))) | ||||
| 38 | : | ||||
| 39 | $around->{cache}->(@_)); | ||||
| 40 | 2 | 95µs | for my $c (@$after) { $c->(@_) }; # spent 95µs making 2 calls to Class::MOP::Class:::after, avg 47µs/call | ||
| 41 | return unless defined wantarray; | ||||
| 42 | return wantarray ? @rval : $rval[0]; | ||||
| 43 | } | ||||
| 44 | } | ||||
| 45 | elsif (@$before && !@$after) { | ||||
| 46 | # spent 3.27ms (111µs+3.16) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:49] which was called 2 times, avg 1.63ms/call:
# 2 times (111µs+3.16ms) by Class::MOP::Class::__ANON__::SERIAL::2::_process_options or Class::MOP::Class::__ANON__::SERIAL::5::_process_options at line 89, avg 1.63ms/call | ||||
| 47 | 6 | 109µs | 2 | 1.80ms | for my $c (@$before) { $c->(@_) }; # spent 1.80ms making 2 calls to Class::MOP::Class:::before, avg 902µs/call |
| 48 | 2 | 1.35ms | return $around->{cache}->(@_); # spent 1.35ms making 2 calls to Moose::Meta::Attribute::_process_options, avg 677µs/call | ||
| 49 | } | ||||
| 50 | } | ||||
| 51 | elsif (@$after && !@$before) { | ||||
| 52 | $modifier_table->{cache} = sub { | ||||
| 53 | my @rval; | ||||
| 54 | ((defined wantarray) ? | ||||
| 55 | ((wantarray) ? | ||||
| 56 | (@rval = $around->{cache}->(@_)) | ||||
| 57 | : | ||||
| 58 | ($rval[0] = $around->{cache}->(@_))) | ||||
| 59 | : | ||||
| 60 | $around->{cache}->(@_)); | ||||
| 61 | for my $c (@$after) { $c->(@_) }; | ||||
| 62 | return unless defined wantarray; | ||||
| 63 | return wantarray ? @rval : $rval[0]; | ||||
| 64 | } | ||||
| 65 | } | ||||
| 66 | else { | ||||
| 67 | $modifier_table->{cache} = $around->{cache}; | ||||
| 68 | } | ||||
| 69 | 1 | 13µs | }; | ||
| 70 | |||||
| 71 | # spent 21.7ms (8.23+13.5) within Class::MOP::Method::Wrapped::wrap which was called 66 times, avg 329µs/call:
# 61 times (7.66ms+12.6ms) by Class::MOP::Class::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Class.pm:1108] at line 1094 of Class/MOP/Class.pm, avg 332µs/call
# 5 times (565µs+892µs) by Class::MOP::Class::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Class.pm:1108] at line 1101 of Class/MOP/Class.pm, avg 291µs/call | ||||
| 72 | 330 | 9.15ms | my ( $class, $code, %params ) = @_; | ||
| 73 | |||||
| 74 | 132 | 816µs | (blessed($code) && $code->isa('Class::MOP::Method')) # spent 454µs making 66 calls to UNIVERSAL::isa, avg 7µs/call
# spent 361µs making 66 calls to Scalar::Util::blessed, avg 5µs/call | ||
| 75 | || confess "Can only wrap blessed CODE"; | ||||
| 76 | |||||
| 77 | 66 | 347µs | my $modifier_table = { # spent 347µs making 66 calls to Class::MOP::Method::body, avg 5µs/call | ||
| 78 | cache => undef, | ||||
| 79 | orig => $code, | ||||
| 80 | before => [], | ||||
| 81 | after => [], | ||||
| 82 | around => { | ||||
| 83 | cache => $code->body, | ||||
| 84 | methods => [], | ||||
| 85 | }, | ||||
| 86 | }; | ||||
| 87 | 66 | 1.82ms | $_build_wrapped_method->($modifier_table); # spent 1.82ms making 66 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 28µs/call | ||
| 88 | return $class->SUPER::wrap( | ||||
| 89 | 1067 | 20.4ms | 1067 | 847ms | sub { $modifier_table->{cache}->(@_) }, # spent 719ms making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:43], avg 360ms/call
# spent 130ms making 1063 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:159], avg 122µs/call, recursion: max depth 3, sum of overlapping time 5.27ms
# spent 3.27ms making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:49], avg 1.63ms/call |
| 90 | # get these from the original | ||||
| 91 | # unless explicitly overriden | ||||
| 92 | 66 | 10.5ms | package_name => $params{package_name} || $code->package_name, # spent 10.5ms making 66 calls to Class::MOP::Method::wrap, avg 159µs/call | ||
| 93 | name => $params{name} || $code->name, | ||||
| 94 | |||||
| 95 | modifier_table => $modifier_table, | ||||
| 96 | ); | ||||
| 97 | } | ||||
| 98 | |||||
| 99 | # spent 3.79ms within Class::MOP::Method::Wrapped::_new which was called 66 times, avg 57µs/call:
# 66 times (3.79ms+0s) by Class::MOP::Method::wrap at line 44 of Class/MOP/Method.pm, avg 57µs/call | ||||
| 100 | 264 | 4.05ms | my $class = shift; | ||
| 101 | return Class::MOP::Class->initialize($class)->new_object(@_) | ||||
| 102 | if $class ne __PACKAGE__; | ||||
| 103 | |||||
| 104 | my $params = @_ == 1 ? $_[0] : {@_}; | ||||
| 105 | |||||
| 106 | return bless { | ||||
| 107 | # inherited from Class::MOP::Method | ||||
| 108 | 'body' => $params->{body}, | ||||
| 109 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||
| 110 | 'package_name' => $params->{package_name}, | ||||
| 111 | 'name' => $params->{name}, | ||||
| 112 | 'original_method' => $params->{original_method}, | ||||
| 113 | |||||
| 114 | # defined in this class | ||||
| 115 | 'modifier_table' => $params->{modifier_table} | ||||
| 116 | } => $class; | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | sub get_original_method { | ||||
| 120 | my $code = shift; | ||||
| 121 | $code->{'modifier_table'}->{orig}; | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | # spent 438µs (244+194) within Class::MOP::Method::Wrapped::add_before_modifier which was called 5 times, avg 88µs/call:
# 5 times (244µs+194µs) by Class::MOP::Class::add_before_method_modifier at line 1115 of Class/MOP/Class.pm, avg 88µs/call | ||||
| 125 | 20 | 231µs | my $code = shift; | ||
| 126 | my $modifier = shift; | ||||
| 127 | unshift @{$code->{'modifier_table'}->{before}} => $modifier; | ||||
| 128 | 5 | 194µs | $_build_wrapped_method->($code->{'modifier_table'}); # spent 194µs making 5 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 39µs/call | ||
| 129 | } | ||||
| 130 | |||||
| 131 | sub before_modifiers { | ||||
| 132 | my $code = shift; | ||||
| 133 | return @{$code->{'modifier_table'}->{before}}; | ||||
| 134 | } | ||||
| 135 | |||||
| 136 | # spent 146µs (71+75) within Class::MOP::Method::Wrapped::add_after_modifier which was called 2 times, avg 73µs/call:
# 2 times (71µs+75µs) by Class::MOP::Class::add_after_method_modifier at line 1125 of Class/MOP/Class.pm, avg 73µs/call | ||||
| 137 | 8 | 64µs | my $code = shift; | ||
| 138 | my $modifier = shift; | ||||
| 139 | push @{$code->{'modifier_table'}->{after}} => $modifier; | ||||
| 140 | 2 | 75µs | $_build_wrapped_method->($code->{'modifier_table'}); # spent 75µs making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 37µs/call | ||
| 141 | } | ||||
| 142 | |||||
| 143 | sub after_modifiers { | ||||
| 144 | my $code = shift; | ||||
| 145 | return @{$code->{'modifier_table'}->{after}}; | ||||
| 146 | } | ||||
| 147 | |||||
| 148 | { | ||||
| 149 | # NOTE: | ||||
| 150 | # this is another possible candidate for | ||||
| 151 | # optimization as well. There is an overhead | ||||
| 152 | # associated with the currying that, if | ||||
| 153 | # eliminated might make around modifiers | ||||
| 154 | # more manageable. | ||||
| 155 | 1 | 4µs | # spent 2.36ms within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:161] which was called 61 times, avg 39µs/call:
# 61 times (2.36ms+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 168, avg 39µs/call | ||
| 156 | 488 | 2.69ms | my $f1 = pop; | ||
| 157 | return $f1 unless @_; | ||||
| 158 | my $f2 = pop; | ||||
| 159 | 1063 | 19.2ms | 1063 | 104ms | # spent 124ms (21.0+103) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:159] which was called 1063 times, avg 117µs/call:
# 1063 times (21.0ms+103ms) by Class::MOP::Class::Immutable::Class::MOP::Class::_method_map or Class::MOP::Class::Immutable::Class::MOP::Class::class_precedence_list or Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes or Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance or Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable or Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa or Class::MOP::Class::Immutable::Class::MOP::Class::superclasses or Class::MOP::Class::Immutable::Moose::Meta::Class::_method_map or Class::MOP::Class::Immutable::Moose::Meta::Class::class_precedence_list or Class::MOP::Class::Immutable::Moose::Meta::Class::is_immutable or Class::MOP::Class::Immutable::Moose::Meta::Class::linearized_isa or Class::MOP::Class::Immutable::Moose::Meta::Class::superclasses or Class::MOP::Class::__ANON__::SERIAL::2::_canonicalize_handles or Class::MOP::Class::__ANON__::SERIAL::2::_make_delegation_method or Class::MOP::Class::__ANON__::SERIAL::3::new or Class::MOP::Class::__ANON__::SERIAL::4::new or Class::MOP::Class::__ANON__::SERIAL::5::_canonicalize_handles or Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method or Class::MOP::Class::__ANON__::SERIAL::6::_eval_environment or Class::MOP::Class::__ANON__::SERIAL::6::_inline_tc_code or Class::MOP::Class::__ANON__::SERIAL::6::new or Class::MOP::Class::__ANON__::SERIAL::7::new or Class::MOP::Class::__ANON__::SERIAL::8::_eval_environment or Class::MOP::Class::__ANON__::SERIAL::8::_inline_tc_code or Class::MOP::Class::__ANON__::SERIAL::8::new at line 89, avg 117µs/call # spent 109ms making 1063 calls to Class::MOP::Class:::around, avg 102µs/call, recursion: max depth 3, sum of overlapping time 5.06ms |
| 160 | redo; | ||||
| 161 | 1 | 8µs | }}; | ||
| 162 | |||||
| 163 | # spent 8.24ms (4.09+4.15) within Class::MOP::Method::Wrapped::add_around_modifier which was called 61 times, avg 135µs/call:
# 61 times (4.09ms+4.15ms) by Class::MOP::Class::add_around_method_modifier at line 1135 of Class/MOP/Class.pm, avg 135µs/call | ||||
| 164 | 305 | 3.95ms | my $code = shift; | ||
| 165 | my $modifier = shift; | ||||
| 166 | unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier; | ||||
| 167 | $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->( | ||||
| 168 | 122 | 2.67ms | @{$code->{'modifier_table'}->{around}->{methods}}, # spent 2.36ms making 61 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:161], avg 39µs/call
# spent 304µs making 61 calls to Class::MOP::Method::body, avg 5µs/call | ||
| 169 | $code->{'modifier_table'}->{orig}->body | ||||
| 170 | ); | ||||
| 171 | 61 | 1.49ms | $_build_wrapped_method->($code->{'modifier_table'}); # spent 1.49ms making 61 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 24µs/call | ||
| 172 | } | ||||
| 173 | } | ||||
| 174 | |||||
| 175 | sub around_modifiers { | ||||
| 176 | my $code = shift; | ||||
| 177 | return @{$code->{'modifier_table'}->{around}->{methods}}; | ||||
| 178 | } | ||||
| 179 | |||||
| 180 | sub _make_compatible_with { | ||||
| 181 | my $self = shift; | ||||
| 182 | my ($other) = @_; | ||||
| 183 | |||||
| 184 | # XXX: this is pretty gross. the issue here is that CMOP::Method::Wrapped | ||||
| 185 | # objects are subclasses of CMOP::Method, but when we get to moose, they'll | ||||
| 186 | # need to be compatible with Moose::Meta::Method, which isn't possible. the | ||||
| 187 | # right solution here is to make ::Wrapped into a role that gets applied to | ||||
| 188 | # whatever the method_metaclass happens to be and get rid of | ||||
| 189 | # wrapped_method_metaclass entirely, but that's not going to happen until | ||||
| 190 | # we ditch cmop and get roles into the bootstrapping, so. i'm not | ||||
| 191 | # maintaining the previous behavior of turning them into instances of the | ||||
| 192 | # new method_metaclass because that's equally broken, and at least this way | ||||
| 193 | # any issues will at least be detectable and potentially fixable. -doy | ||||
| 194 | return $self unless $other->_is_compatible_with($self->_real_ref_name); | ||||
| 195 | |||||
| 196 | return $self->SUPER::_make_compatible_with(@_); | ||||
| 197 | } | ||||
| 198 | |||||
| 199 | 1 | 16µs | 1; | ||
| 200 | |||||
| 201 | __END__ |