| File | /usr/local/lib/perl/5.10.0/Class/MOP/Method/Meta.pm |
| Statements Executed | 752 |
| Total Time | 0.00364349999999999 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 31 | 2 | 2 | 859µs | 15.2ms | Class::MOP::Method::Meta::wrap |
| 31 | 1 | 1 | 349µs | 349µs | Class::MOP::Method::Meta::_generate_meta_method |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Meta::BEGIN |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Meta::__ANON__[:45] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Meta::_is_caller_mop_internal |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Meta::_make_compatible_with |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | ||||
| 2 | package Class::MOP::Method::Meta; | |||
| 3 | ||||
| 4 | 3 | 26µs | 9µs | use strict; # spent 9µs making 1 call to strict::import |
| 5 | 3 | 30µs | 10µs | use warnings; # spent 25µs making 1 call to warnings::import |
| 6 | ||||
| 7 | 3 | 24µs | 8µs | use Carp 'confess'; # spent 38µs making 1 call to Exporter::import |
| 8 | 3 | 79µs | 26µs | use Scalar::Util 'blessed'; # spent 35µs making 1 call to Exporter::import |
| 9 | ||||
| 10 | 1 | 800ns | 800ns | our $VERSION = '1.09'; |
| 11 | 1 | 19µs | 19µs | $VERSION = eval $VERSION; |
| 12 | 1 | 600ns | 600ns | our $AUTHORITY = 'cpan:STEVAN'; |
| 13 | ||||
| 14 | 3 | 39µs | 13µs | use constant DEBUG_NO_META => $ENV{DEBUG_NO_META} ? 1 : 0; # spent 54µs making 1 call to constant::import |
| 15 | ||||
| 16 | 3 | 339µs | 113µs | use base 'Class::MOP::Method'; # spent 2.15ms making 1 call to base::import |
| 17 | ||||
| 18 | sub _is_caller_mop_internal { | |||
| 19 | my $self = shift; | |||
| 20 | my ($caller) = @_; | |||
| 21 | return $caller =~ /^(?:Class::MOP|metaclass)(?:::|$)/; | |||
| 22 | } | |||
| 23 | ||||
| 24 | # spent 349µs within Class::MOP::Method::Meta::_generate_meta_method which was called 31 times, avg 11µs/call:
# 31 times (349µs+0s) by Class::MOP::Method::Meta::wrap at line 57, avg 11µs/call | |||
| 25 | 93 | 263µs | 3µs | my $method_self = shift; |
| 26 | my $metaclass = shift; | |||
| 27 | sub { | |||
| 28 | # this will be compiled out if the env var wasn't set | |||
| 29 | 420 | 1.79ms | 4µs | if (DEBUG_NO_META) { |
| 30 | confess "'meta' method called by MOP internals" | |||
| 31 | # it's okay to call meta methods on metaclasses, since we | |||
| 32 | # explicitly ask for them | |||
| 33 | if !$_[0]->isa('Class::MOP::Object') | |||
| 34 | && !$_[0]->isa('Class::MOP::Mixin') | |||
| 35 | # it's okay if the test itself calls ->meta, we only care about | |||
| 36 | # if the mop internals call ->meta | |||
| 37 | && $method_self->_is_caller_mop_internal(scalar caller); | |||
| 38 | } | |||
| 39 | # we must re-initialize so that it | |||
| 40 | # works as expected in subclasses, | |||
| 41 | # since metaclass instances are | |||
| 42 | # singletons, this is not really a | |||
| 43 | # big deal anyway. | |||
| 44 | $metaclass->initialize(blessed($_[0]) || $_[0]) # spent 7.71ms making 210 calls to Class::MOP::Class::initialize, avg 36µs/call, max recursion depth 1
# spent 598µs making 210 calls to Scalar::Util::blessed, avg 3µs/call | |||
| 45 | }; | |||
| 46 | } | |||
| 47 | ||||
| 48 | # spent 15.2ms (859µs+14.3) within Class::MOP::Method::Meta::wrap which was called 31 times, avg 491µs/call:
# 23 times (634µs+8.96ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 30 of /usr/local/lib/perl/5.10.0/Class/MOP/Mixin/HasMethods.pm, avg 417µs/call
# 8 times (224µs+5.39ms) by Moose::Meta::Method::Meta::wrap at line 24 of /usr/local/lib/perl/5.10.0/Moose/Meta/Method/Meta.pm, avg 702µs/call | |||
| 49 | 217 | 1.03ms | 5µs | my ($class, @args) = @_; |
| 50 | ||||
| 51 | unshift @args, 'body' if @args % 2 == 1; | |||
| 52 | my %params = @args; | |||
| 53 | confess "Overriding the body of meta methods is not allowed" | |||
| 54 | if $params{body}; | |||
| 55 | ||||
| 56 | my $metaclass_class = $params{associated_metaclass}->meta; # spent 670µs making 31 calls to Class::MOP::Object::meta, avg 22µs/call | |||
| 57 | $params{body} = $class->_generate_meta_method($metaclass_class); # spent 349µs making 31 calls to Class::MOP::Method::Meta::_generate_meta_method, avg 11µs/call | |||
| 58 | return $class->SUPER::wrap(%params); # spent 13.3ms making 31 calls to Class::MOP::Method::wrap, avg 430µs/call | |||
| 59 | } | |||
| 60 | ||||
| 61 | sub _make_compatible_with { | |||
| 62 | my $self = shift; | |||
| 63 | my ($other) = @_; | |||
| 64 | ||||
| 65 | # XXX: this is pretty gross. the issue here is that CMOP::Method::Meta | |||
| 66 | # objects are subclasses of CMOP::Method, but when we get to moose, they'll | |||
| 67 | # need to be compatible with Moose::Meta::Method, which isn't possible. the | |||
| 68 | # right solution here is to make ::Meta into a role that gets applied to | |||
| 69 | # whatever the method_metaclass happens to be and get rid of | |||
| 70 | # _meta_method_metaclass entirely, but that's not going to happen until | |||
| 71 | # we ditch cmop and get roles into the bootstrapping, so. i'm not | |||
| 72 | # maintaining the previous behavior of turning them into instances of the | |||
| 73 | # new method_metaclass because that's equally broken, and at least this way | |||
| 74 | # any issues will at least be detectable and potentially fixable. -doy | |||
| 75 | return $self unless $other->_is_compatible_with($self->_real_ref_name); | |||
| 76 | ||||
| 77 | return $self->SUPER::_make_compatible_with(@_); | |||
| 78 | } | |||
| 79 | ||||
| 80 | 1 | 4µs | 4µs | 1; |
| 81 | ||||
| 82 | __END__ | |||
| 83 | ||||
| 84 | =pod | |||
| 85 | ||||
| 86 | =head1 NAME | |||
| 87 | ||||
| 88 | Class::MOP::Method::Meta - Method Meta Object for C<meta> methods | |||
| 89 | ||||
| 90 | =head1 DESCRIPTION | |||
| 91 | ||||
| 92 | This is a L<Class::MOP::Method> subclass which represents C<meta> | |||
| 93 | methods installed into classes by Class::MOP. | |||
| 94 | ||||
| 95 | =head1 METHODS | |||
| 96 | ||||
| 97 | =over 4 | |||
| 98 | ||||
| 99 | =item B<< Class::MOP::Method::Wrapped->wrap($metamethod, %options) >> | |||
| 100 | ||||
| 101 | This is the constructor. It accepts a L<Class::MOP::Method> object and | |||
| 102 | a hash of options. The options accepted are identical to the ones | |||
| 103 | accepted by L<Class::MOP::Method>, except that C<body> cannot be passed | |||
| 104 | (it will be generated automatically). | |||
| 105 | ||||
| 106 | =back | |||
| 107 | ||||
| 108 | =head1 AUTHORS | |||
| 109 | ||||
| 110 | Jesse Luehrs E<lt>doy at tozt dot netE<gt> | |||
| 111 | ||||
| 112 | =head1 COPYRIGHT AND LICENSE | |||
| 113 | ||||
| 114 | Copyright 2006-2010 by Infinity Interactive, Inc. | |||
| 115 | ||||
| 116 | L<http://www.iinteractive.com> | |||
| 117 | ||||
| 118 | This library is free software; you can redistribute it and/or modify | |||
| 119 | it under the same terms as Perl itself. | |||
| 120 | ||||
| 121 | =cut | |||
| 122 |