| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Wrapped.pm |
| Statements | Executed 1778 statements in 5.99ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 533 | 1 | 1 | 1.76ms | 6.22ms | Class::MOP::Method::Wrapped::__ANON__[:162] |
| 23 | 1 | 1 | 553µs | 1.48ms | Class::MOP::Method::Wrapped::wrap |
| 23 | 1 | 1 | 395µs | 395µs | Class::MOP::Method::Wrapped::_new |
| 23 | 1 | 1 | 202µs | 397µs | Class::MOP::Method::Wrapped::add_around_modifier |
| 46 | 2 | 1 | 167µs | 167µs | Class::MOP::Method::Wrapped::__ANON__[:71] |
| 23 | 1 | 1 | 128µs | 128µs | Class::MOP::Method::Wrapped::__ANON__[:164] |
| 1 | 1 | 1 | 11µs | 31µs | Class::MOP::Method::Wrapped::BEGIN@14 |
| 1 | 1 | 1 | 9µs | 9µs | Class::MOP::Method::Wrapped::BEGIN@3 |
| 1 | 1 | 1 | 8µs | 38µs | Class::MOP::Method::Wrapped::BEGIN@13 |
| 1 | 1 | 1 | 7µs | 10µs | Class::MOP::Method::Wrapped::BEGIN@10 |
| 1 | 1 | 1 | 7µs | 19µs | Class::MOP::Method::Wrapped::BEGIN@11 |
| 1 | 1 | 1 | 6µs | 67µs | Class::MOP::Method::Wrapped::BEGIN@16 |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:45] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:51] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:66] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:91] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::_make_compatible_with |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::add_after_modifier |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::add_before_modifier |
| 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 | # spent 9µs within Class::MOP::Method::Wrapped::BEGIN@3 which was called:
# once (9µs+0s) by Class::MOP::Class::BEGIN@14 at line 5 | ||||
| 4 | 1 | 4µs | $Class::MOP::Method::Wrapped::AUTHORITY = 'cpan:STEVAN'; | ||
| 5 | 1 | 21µs | 1 | 9µs | } # spent 9µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@3 |
| 6 | { | ||||
| 7 | 2 | 1µs | $Class::MOP::Method::Wrapped::VERSION = '2.0602'; | ||
| 8 | } | ||||
| 9 | |||||
| 10 | 3 | 17µs | 2 | 14µs | # spent 10µs (7+3) within Class::MOP::Method::Wrapped::BEGIN@10 which was called:
# once (7µs+3µs) by Class::MOP::Class::BEGIN@14 at line 10 # spent 10µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@10
# spent 3µs making 1 call to strict::import |
| 11 | 3 | 18µs | 2 | 32µs | # spent 19µs (7+12) within Class::MOP::Method::Wrapped::BEGIN@11 which was called:
# once (7µs+12µs) by Class::MOP::Class::BEGIN@14 at line 11 # spent 19µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@11
# spent 13µs making 1 call to warnings::import |
| 12 | |||||
| 13 | 3 | 22µs | 2 | 68µs | # spent 38µs (8+30) within Class::MOP::Method::Wrapped::BEGIN@13 which was called:
# once (8µs+30µs) by Class::MOP::Class::BEGIN@14 at line 13 # spent 38µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@13
# spent 30µs making 1 call to Exporter::import |
| 14 | 3 | 19µs | 2 | 51µs | # spent 31µs (11+20) within Class::MOP::Method::Wrapped::BEGIN@14 which was called:
# once (11µs+20µs) by Class::MOP::Class::BEGIN@14 at line 14 # spent 31µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@14
# spent 20µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 3 | 765µs | 2 | 128µs | # spent 67µs (6+61) within Class::MOP::Method::Wrapped::BEGIN@16 which was called:
# once (6µs+61µs) by Class::MOP::Class::BEGIN@14 at line 16 # spent 67µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@16
# spent 61µs making 1 call to base::import |
| 17 | |||||
| 18 | # NOTE: | ||||
| 19 | # this ugly beast is the result of trying | ||||
| 20 | # to micro optimize this as much as possible | ||||
| 21 | # while not completely loosing maintainability. | ||||
| 22 | # At this point it's "fast enough", after all | ||||
| 23 | # you can't get something for nothing :) | ||||
| 24 | # spent 167µs within Class::MOP::Method::Wrapped::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Wrapped.pm:71] which was called 46 times, avg 4µs/call:
# 23 times (99µs+0s) by Class::MOP::Method::Wrapped::wrap at line 89, avg 4µs/call
# 23 times (68µs+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 174, avg 3µs/call | ||||
| 25 | 46 | 15µs | my $modifier_table = shift; | ||
| 26 | 46 | 43µs | my ($before, $after, $around) = ( | ||
| 27 | $modifier_table->{before}, | ||||
| 28 | $modifier_table->{after}, | ||||
| 29 | $modifier_table->{around}, | ||||
| 30 | ); | ||||
| 31 | 46 | 133µs | if (@$before && @$after) { | ||
| 32 | $modifier_table->{cache} = sub { | ||||
| 33 | for my $c (@$before) { $c->(@_) }; | ||||
| 34 | my @rval; | ||||
| 35 | ((defined wantarray) ? | ||||
| 36 | ((wantarray) ? | ||||
| 37 | (@rval = $around->{cache}->(@_)) | ||||
| 38 | : | ||||
| 39 | ($rval[0] = $around->{cache}->(@_))) | ||||
| 40 | : | ||||
| 41 | $around->{cache}->(@_)); | ||||
| 42 | for my $c (@$after) { $c->(@_) }; | ||||
| 43 | return unless defined wantarray; | ||||
| 44 | return wantarray ? @rval : $rval[0]; | ||||
| 45 | } | ||||
| 46 | } | ||||
| 47 | elsif (@$before && !@$after) { | ||||
| 48 | $modifier_table->{cache} = sub { | ||||
| 49 | for my $c (@$before) { $c->(@_) }; | ||||
| 50 | return $around->{cache}->(@_); | ||||
| 51 | } | ||||
| 52 | } | ||||
| 53 | elsif (@$after && !@$before) { | ||||
| 54 | $modifier_table->{cache} = sub { | ||||
| 55 | my @rval; | ||||
| 56 | ((defined wantarray) ? | ||||
| 57 | ((wantarray) ? | ||||
| 58 | (@rval = $around->{cache}->(@_)) | ||||
| 59 | : | ||||
| 60 | ($rval[0] = $around->{cache}->(@_))) | ||||
| 61 | : | ||||
| 62 | $around->{cache}->(@_)); | ||||
| 63 | for my $c (@$after) { $c->(@_) }; | ||||
| 64 | return unless defined wantarray; | ||||
| 65 | return wantarray ? @rval : $rval[0]; | ||||
| 66 | } | ||||
| 67 | } | ||||
| 68 | else { | ||||
| 69 | 46 | 24µs | $modifier_table->{cache} = $around->{cache}; | ||
| 70 | } | ||||
| 71 | 1 | 3µs | }; | ||
| 72 | |||||
| 73 | # spent 1.48ms (553µs+931µs) within Class::MOP::Method::Wrapped::wrap which was called 23 times, avg 64µs/call:
# 23 times (553µs+931µs) by Class::MOP::Class::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Class.pm:1072] at line 1058 of Class/MOP/Class.pm, avg 64µs/call | ||||
| 74 | 23 | 38µs | my ( $class, $code, %params ) = @_; | ||
| 75 | |||||
| 76 | 23 | 120µs | 46 | 38µs | (blessed($code) && $code->isa('Class::MOP::Method')) # spent 22µs making 23 calls to UNIVERSAL::isa, avg 935ns/call
# spent 17µs making 23 calls to Scalar::Util::blessed, avg 722ns/call |
| 77 | || confess "Can only wrap blessed CODE"; | ||||
| 78 | |||||
| 79 | 23 | 160µs | 46 | 22µs | my $modifier_table = { # spent 22µs making 46 calls to Class::MOP::Method::body, avg 474ns/call |
| 80 | cache => undef, | ||||
| 81 | orig => $code->body, | ||||
| 82 | before => [], | ||||
| 83 | after => [], | ||||
| 84 | around => { | ||||
| 85 | cache => $code->body, | ||||
| 86 | methods => [], | ||||
| 87 | }, | ||||
| 88 | }; | ||||
| 89 | 23 | 33µs | 23 | 99µs | $_build_wrapped_method->($modifier_table); # spent 99µs making 23 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:71], avg 4µs/call |
| 90 | return $class->SUPER::wrap( | ||||
| 91 | 533 | 1.82ms | 533 | 6.22ms | sub { $modifier_table->{cache}->(@_) }, # spent 6.22ms making 533 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:162], avg 12µs/call |
| 92 | # get these from the original | ||||
| 93 | # unless explicitly overriden | ||||
| 94 | 23 | 242µs | 23 | 772µs | package_name => $params{package_name} || $code->package_name, # spent 772µs making 23 calls to Class::MOP::Method::wrap, avg 34µs/call |
| 95 | name => $params{name} || $code->name, | ||||
| 96 | original_method => $code, | ||||
| 97 | |||||
| 98 | modifier_table => $modifier_table, | ||||
| 99 | ); | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | # spent 395µs within Class::MOP::Method::Wrapped::_new which was called 23 times, avg 17µs/call:
# 23 times (395µs+0s) by Class::MOP::Method::wrap at line 46 of Class/MOP/Method.pm, avg 17µs/call | ||||
| 103 | 23 | 10µs | my $class = shift; | ||
| 104 | 23 | 7µs | return Class::MOP::Class->initialize($class)->new_object(@_) | ||
| 105 | if $class ne __PACKAGE__; | ||||
| 106 | |||||
| 107 | 23 | 10µs | my $params = @_ == 1 ? $_[0] : {@_}; | ||
| 108 | |||||
| 109 | 23 | 384µs | return bless { | ||
| 110 | # inherited from Class::MOP::Method | ||||
| 111 | 'body' => $params->{body}, | ||||
| 112 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||
| 113 | 'package_name' => $params->{package_name}, | ||||
| 114 | 'name' => $params->{name}, | ||||
| 115 | 'original_method' => $params->{original_method}, | ||||
| 116 | |||||
| 117 | # defined in this class | ||||
| 118 | 'modifier_table' => $params->{modifier_table} | ||||
| 119 | } => $class; | ||||
| 120 | } | ||||
| 121 | |||||
| 122 | sub get_original_method { | ||||
| 123 | my $code = shift; | ||||
| 124 | $code->original_method; | ||||
| 125 | } | ||||
| 126 | |||||
| 127 | sub add_before_modifier { | ||||
| 128 | my $code = shift; | ||||
| 129 | my $modifier = shift; | ||||
| 130 | unshift @{$code->{'modifier_table'}->{before}} => $modifier; | ||||
| 131 | $_build_wrapped_method->($code->{'modifier_table'}); | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | sub before_modifiers { | ||||
| 135 | my $code = shift; | ||||
| 136 | return @{$code->{'modifier_table'}->{before}}; | ||||
| 137 | } | ||||
| 138 | |||||
| 139 | sub add_after_modifier { | ||||
| 140 | my $code = shift; | ||||
| 141 | my $modifier = shift; | ||||
| 142 | push @{$code->{'modifier_table'}->{after}} => $modifier; | ||||
| 143 | $_build_wrapped_method->($code->{'modifier_table'}); | ||||
| 144 | } | ||||
| 145 | |||||
| 146 | sub after_modifiers { | ||||
| 147 | my $code = shift; | ||||
| 148 | return @{$code->{'modifier_table'}->{after}}; | ||||
| 149 | } | ||||
| 150 | |||||
| 151 | { | ||||
| 152 | # NOTE: | ||||
| 153 | # this is another possible candidate for | ||||
| 154 | # optimization as well. There is an overhead | ||||
| 155 | # associated with the currying that, if | ||||
| 156 | # eliminated might make around modifiers | ||||
| 157 | # more manageable. | ||||
| 158 | 47 | 15µs | # spent 128µs within Class::MOP::Method::Wrapped::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Wrapped.pm:164] which was called 23 times, avg 6µs/call:
# 23 times (128µs+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 171, avg 6µs/call | ||
| 159 | 23 | 6µs | my $f1 = pop; | ||
| 160 | 46 | 68µs | return $f1 unless @_; | ||
| 161 | 23 | 7µs | my $f2 = pop; | ||
| 162 | 556 | 1.81ms | 533 | 4.46ms | # spent 6.22ms (1.76+4.46) within Class::MOP::Method::Wrapped::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method/Wrapped.pm:162] which was called 533 times, avg 12µs/call:
# 533 times (1.76ms+4.46ms) by Class::MOP::Class::Immutable::Class::MOP::Class::_method_map 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 at line 91, avg 12µs/call # spent 4.46ms making 533 calls to Class::MOP::Class:::around, avg 8µs/call |
| 163 | 23 | 9µs | redo; | ||
| 164 | 1 | 2µs | }}; | ||
| 165 | |||||
| 166 | # spent 397µs (202+195) within Class::MOP::Method::Wrapped::add_around_modifier which was called 23 times, avg 17µs/call:
# 23 times (202µs+195µs) by Class::MOP::Class::add_around_method_modifier at line 1099 of Class/MOP/Class.pm, avg 17µs/call | ||||
| 167 | 23 | 7µs | my $code = shift; | ||
| 168 | 23 | 6µs | my $modifier = shift; | ||
| 169 | 23 | 26µs | unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier; | ||
| 170 | $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->( | ||||
| 171 | 23 | 60µs | 23 | 128µs | @{$code->{'modifier_table'}->{around}->{methods}}, # spent 128µs making 23 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:164], avg 6µs/call |
| 172 | $code->{'modifier_table'}->{orig} | ||||
| 173 | ); | ||||
| 174 | 23 | 66µs | 23 | 68µs | $_build_wrapped_method->($code->{'modifier_table'}); # spent 68µs making 23 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:71], avg 3µs/call |
| 175 | } | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | sub around_modifiers { | ||||
| 179 | my $code = shift; | ||||
| 180 | return @{$code->{'modifier_table'}->{around}->{methods}}; | ||||
| 181 | } | ||||
| 182 | |||||
| 183 | sub _make_compatible_with { | ||||
| 184 | my $self = shift; | ||||
| 185 | my ($other) = @_; | ||||
| 186 | |||||
| 187 | # XXX: this is pretty gross. the issue here is that CMOP::Method::Wrapped | ||||
| 188 | # objects are subclasses of CMOP::Method, but when we get to moose, they'll | ||||
| 189 | # need to be compatible with Moose::Meta::Method, which isn't possible. the | ||||
| 190 | # right solution here is to make ::Wrapped into a role that gets applied to | ||||
| 191 | # whatever the method_metaclass happens to be and get rid of | ||||
| 192 | # wrapped_method_metaclass entirely, but that's not going to happen until | ||||
| 193 | # we ditch cmop and get roles into the bootstrapping, so. i'm not | ||||
| 194 | # maintaining the previous behavior of turning them into instances of the | ||||
| 195 | # new method_metaclass because that's equally broken, and at least this way | ||||
| 196 | # any issues will at least be detectable and potentially fixable. -doy | ||||
| 197 | return $self unless $other->_is_compatible_with($self->_real_ref_name); | ||||
| 198 | |||||
| 199 | return $self->SUPER::_make_compatible_with(@_); | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | 1 | 4µs | 1; | ||
| 203 | |||||
| 204 | # ABSTRACT: Method Meta Object for methods with before/after/around modifiers | ||||
| 205 | |||||
| - - | |||||
| 208 | =pod | ||||
| 209 | |||||
| 210 | =head1 NAME | ||||
| 211 | |||||
| 212 | Class::MOP::Method::Wrapped - Method Meta Object for methods with before/after/around modifiers | ||||
| 213 | |||||
| 214 | =head1 VERSION | ||||
| 215 | |||||
| 216 | version 2.0602 | ||||
| 217 | |||||
| 218 | =head1 DESCRIPTION | ||||
| 219 | |||||
| 220 | This is a L<Class::MOP::Method> subclass which implements before, | ||||
| 221 | after, and around method modifiers. | ||||
| 222 | |||||
| 223 | =head1 METHODS | ||||
| 224 | |||||
| 225 | =head2 Construction | ||||
| 226 | |||||
| 227 | =over 4 | ||||
| 228 | |||||
| 229 | =item B<< Class::MOP::Method::Wrapped->wrap($metamethod, %options) >> | ||||
| 230 | |||||
| 231 | This is the constructor. It accepts a L<Class::MOP::Method> object and | ||||
| 232 | a hash of options. | ||||
| 233 | |||||
| 234 | The options are: | ||||
| 235 | |||||
| 236 | =over 8 | ||||
| 237 | |||||
| 238 | =item * name | ||||
| 239 | |||||
| 240 | The method name (without a package name). This will be taken from the | ||||
| 241 | provided L<Class::MOP::Method> object if it is not provided. | ||||
| 242 | |||||
| 243 | =item * package_name | ||||
| 244 | |||||
| 245 | The package name for the method. This will be taken from the provided | ||||
| 246 | L<Class::MOP::Method> object if it is not provided. | ||||
| 247 | |||||
| 248 | =item * associated_metaclass | ||||
| 249 | |||||
| 250 | An optional L<Class::MOP::Class> object. This is the metaclass for the | ||||
| 251 | method's class. | ||||
| 252 | |||||
| 253 | =back | ||||
| 254 | |||||
| 255 | =item B<< $metamethod->get_original_method >> | ||||
| 256 | |||||
| 257 | This returns the L<Class::MOP::Method> object that was passed to the | ||||
| 258 | constructor. | ||||
| 259 | |||||
| 260 | =item B<< $metamethod->add_before_modifier($code) >> | ||||
| 261 | |||||
| 262 | =item B<< $metamethod->add_after_modifier($code) >> | ||||
| 263 | |||||
| 264 | =item B<< $metamethod->add_around_modifier($code) >> | ||||
| 265 | |||||
| 266 | These methods all take a subroutine reference and apply it as a | ||||
| 267 | modifier to the original method. | ||||
| 268 | |||||
| 269 | =item B<< $metamethod->before_modifiers >> | ||||
| 270 | |||||
| 271 | =item B<< $metamethod->after_modifiers >> | ||||
| 272 | |||||
| 273 | =item B<< $metamethod->around_modifiers >> | ||||
| 274 | |||||
| 275 | These methods all return a list of subroutine references which are | ||||
| 276 | acting as the specified type of modifier. | ||||
| 277 | |||||
| 278 | =back | ||||
| 279 | |||||
| 280 | =head1 AUTHOR | ||||
| 281 | |||||
| 282 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
| 283 | |||||
| 284 | =head1 COPYRIGHT AND LICENSE | ||||
| 285 | |||||
| 286 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
| 287 | |||||
| 288 | This is free software; you can redistribute it and/or modify it under | ||||
| 289 | the same terms as the Perl 5 programming language system itself. | ||||
| 290 | |||||
| 291 | =cut | ||||
| 292 | |||||
| 293 | |||||
| 294 | __END__ |