| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Method/Delegation.pm |
| Statements | Executed 677 statements in 12.3ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 23 | 1 | 1 | 2.60ms | 11.2ms | Moose::Meta::Method::Delegation::new |
| 23 | 1 | 1 | 2.53ms | 2.53ms | Moose::Meta::Method::Delegation::_new |
| 23 | 1 | 1 | 1.80ms | 5.65ms | Moose::Meta::Method::Delegation::_initialize_body |
| 23 | 1 | 1 | 1.55ms | 3.51ms | Moose::Meta::Method::Delegation::_get_delegate_accessor |
| 27 | 2 | 2 | 259µs | 259µs | Moose::Meta::Method::Delegation::delegate_to_method |
| 23 | 1 | 1 | 199µs | 199µs | Moose::Meta::Method::Delegation::associated_attribute |
| 10 | 2 | 1 | 111µs | 111µs | Moose::Meta::Method::Delegation::curried_arguments |
| 1 | 1 | 1 | 71µs | 90µs | Moose::Meta::Method::Delegation::BEGIN@4 |
| 1 | 1 | 1 | 60µs | 226µs | Moose::Meta::Method::Delegation::BEGIN@8 |
| 1 | 1 | 1 | 44µs | 115µs | Moose::Meta::Method::Delegation::BEGIN@5 |
| 1 | 1 | 1 | 41µs | 485µs | Moose::Meta::Method::Delegation::BEGIN@14 |
| 1 | 1 | 1 | 39µs | 202µs | Moose::Meta::Method::Delegation::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Delegation::__ANON__[:109] |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Method::Delegation; | ||||
| 3 | |||||
| 4 | 3 | 180µs | 2 | 109µs | # spent 90µs (71+19) within Moose::Meta::Method::Delegation::BEGIN@4 which was called:
# once (71µs+19µs) by Moose::Meta::Attribute::BEGIN@18 at line 4 # spent 90µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 107µs | 2 | 186µs | # spent 115µs (44+71) within Moose::Meta::Method::Delegation::BEGIN@5 which was called:
# once (44µs+71µs) by Moose::Meta::Attribute::BEGIN@18 at line 5 # spent 115µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@5
# spent 71µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 131µs | 2 | 366µs | # spent 202µs (39+163) within Moose::Meta::Method::Delegation::BEGIN@7 which was called:
# once (39µs+163µs) by Moose::Meta::Attribute::BEGIN@18 at line 7 # spent 202µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@7
# spent 163µs making 1 call to Exporter::import |
| 8 | 3 | 239µs | 2 | 391µs | # spent 226µs (60+166) within Moose::Meta::Method::Delegation::BEGIN@8 which was called:
# once (60µs+166µs) by Moose::Meta::Attribute::BEGIN@18 at line 8 # spent 226µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@8
# spent 166µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 11 | 1 | 60µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 12 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 1 | 444µs | # spent 485µs (41+444) within Moose::Meta::Method::Delegation::BEGIN@14 which was called:
# once (41µs+444µs) by Moose::Meta::Attribute::BEGIN@18 at line 15 # spent 444µs making 1 call to base::import | ||
| 15 | 3 | 1.86ms | 1 | 485µs | 'Class::MOP::Method::Generated'; # spent 485µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@14 |
| 16 | |||||
| 17 | |||||
| 18 | # spent 11.2ms (2.60+8.61) within Moose::Meta::Method::Delegation::new which was called 23 times, avg 487µs/call:
# 23 times (2.60ms+8.61ms) by Moose::Meta::Attribute::_make_delegation_method at line 864 of Moose/Meta/Attribute.pm, avg 487µs/call | ||||
| 19 | 276 | 2.83ms | my $class = shift; | ||
| 20 | my %options = @_; | ||||
| 21 | |||||
| 22 | ( exists $options{attribute} ) | ||||
| 23 | || confess "You must supply an attribute to construct with"; | ||||
| 24 | |||||
| 25 | 46 | 280µs | ( blessed( $options{attribute} ) # spent 145µs making 23 calls to UNIVERSAL::isa, avg 6µs/call
# spent 135µs making 23 calls to Scalar::Util::blessed, avg 6µs/call | ||
| 26 | && $options{attribute}->isa('Moose::Meta::Attribute') ) | ||||
| 27 | || confess | ||||
| 28 | "You must supply an attribute which is a 'Moose::Meta::Attribute' instance"; | ||||
| 29 | |||||
| 30 | ( $options{package_name} && $options{name} ) | ||||
| 31 | || confess | ||||
| 32 | "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT"; | ||||
| 33 | |||||
| 34 | ( $options{delegate_to_method} && ( !ref $options{delegate_to_method} ) | ||||
| 35 | || ( 'CODE' eq ref $options{delegate_to_method} ) ) | ||||
| 36 | || confess | ||||
| 37 | 'You must supply a delegate_to_method which is a method name or a CODE reference'; | ||||
| 38 | |||||
| 39 | exists $options{curried_arguments} | ||||
| 40 | || ( $options{curried_arguments} = [] ); | ||||
| 41 | |||||
| 42 | ( $options{curried_arguments} && | ||||
| 43 | ( 'ARRAY' eq ref $options{curried_arguments} ) ) | ||||
| 44 | || confess 'You must supply a curried_arguments which is an ARRAY reference'; | ||||
| 45 | |||||
| 46 | 23 | 2.53ms | my $self = $class->_new( \%options ); # spent 2.53ms making 23 calls to Moose::Meta::Method::Delegation::_new, avg 110µs/call | ||
| 47 | |||||
| 48 | 23 | 148µs | weaken( $self->{'attribute'} ); # spent 148µs making 23 calls to Scalar::Util::weaken, avg 6µs/call | ||
| 49 | |||||
| 50 | 23 | 5.65ms | $self->_initialize_body; # spent 5.65ms making 23 calls to Moose::Meta::Method::Delegation::_initialize_body, avg 246µs/call | ||
| 51 | |||||
| 52 | return $self; | ||||
| 53 | } | ||||
| 54 | |||||
| 55 | # spent 2.53ms within Moose::Meta::Method::Delegation::_new which was called 23 times, avg 110µs/call:
# 23 times (2.53ms+0s) by Moose::Meta::Method::Delegation::new at line 46, avg 110µs/call | ||||
| 56 | 69 | 2.67ms | my $class = shift; | ||
| 57 | my $options = @_ == 1 ? $_[0] : {@_}; | ||||
| 58 | |||||
| 59 | return bless $options, $class; | ||||
| 60 | } | ||||
| 61 | |||||
| 62 | 10 | 160µs | # spent 111µs within Moose::Meta::Method::Delegation::curried_arguments which was called 10 times, avg 11µs/call:
# 5 times (59µs+0s) by Moose::Meta::Method::Accessor::Native::_inline_curried_arguments at line 56 of Moose/Meta/Method/Accessor/Native.pm, avg 12µs/call
# 5 times (52µs+0s) by Moose::Meta::Method::Accessor::Native::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/Method/Accessor/Native.pm:136] at line 121 of Moose/Meta/Method/Accessor/Native.pm, avg 10µs/call | ||
| 63 | |||||
| 64 | 23 | 294µs | # spent 199µs within Moose::Meta::Method::Delegation::associated_attribute which was called 23 times, avg 9µs/call:
# 23 times (199µs+0s) by Moose::Meta::Method::Delegation::_get_delegate_accessor at line 114, avg 9µs/call | ||
| 65 | |||||
| 66 | 27 | 392µs | # spent 259µs within Moose::Meta::Method::Delegation::delegate_to_method which was called 27 times, avg 10µs/call:
# 23 times (212µs+0s) by Moose::Meta::Method::Delegation::_initialize_body at line 71, avg 9µs/call
# 4 times (47µs+0s) by Moose::Meta::Method::Accessor::Native::_inline_check_argument_count at line 81 of Moose/Meta/Method/Accessor/Native.pm, avg 12µs/call | ||
| 67 | |||||
| 68 | # spent 5.65ms (1.80+3.85) within Moose::Meta::Method::Delegation::_initialize_body which was called 23 times, avg 246µs/call:
# 23 times (1.80ms+3.85ms) by Moose::Meta::Method::Delegation::new at line 50, avg 246µs/call | ||||
| 69 | 138 | 1.84ms | my $self = shift; | ||
| 70 | |||||
| 71 | 23 | 212µs | my $method_to_call = $self->delegate_to_method; # spent 212µs making 23 calls to Moose::Meta::Method::Delegation::delegate_to_method, avg 9µs/call | ||
| 72 | return $self->{body} = $method_to_call | ||||
| 73 | if ref $method_to_call; | ||||
| 74 | |||||
| 75 | 23 | 3.51ms | my $accessor = $self->_get_delegate_accessor; # spent 3.51ms making 23 calls to Moose::Meta::Method::Delegation::_get_delegate_accessor, avg 152µs/call | ||
| 76 | |||||
| 77 | 23 | 131µs | my $handle_name = $self->name; # spent 131µs making 23 calls to Class::MOP::Method::name, avg 6µs/call | ||
| 78 | |||||
| 79 | # NOTE: we used to do a goto here, but the goto didn't handle | ||||
| 80 | # failure correctly (it just returned nothing), so I took that | ||||
| 81 | # out. However, the more I thought about it, the less I liked it | ||||
| 82 | # doing the goto, and I preferred the act of delegation being | ||||
| 83 | # actually represented in the stack trace. - SL | ||||
| 84 | # not inlining this, since it won't really speed things up at | ||||
| 85 | # all... the only thing that would end up different would be | ||||
| 86 | # interpolating in $method_to_call, and a bunch of things in the | ||||
| 87 | # error handling that mostly never gets called - doy | ||||
| 88 | $self->{body} = sub { | ||||
| 89 | my $instance = shift; | ||||
| 90 | my $proxy = $instance->$accessor(); | ||||
| 91 | |||||
| 92 | my $error | ||||
| 93 | = !defined $proxy ? ' is not defined' | ||||
| 94 | : ref($proxy) && !blessed($proxy) ? qq{ is not an object (got '$proxy')} | ||||
| 95 | : undef; | ||||
| 96 | |||||
| 97 | if ($error) { | ||||
| 98 | $self->throw_error( | ||||
| 99 | "Cannot delegate $handle_name to $method_to_call because " | ||||
| 100 | . "the value of " | ||||
| 101 | . $self->associated_attribute->name | ||||
| 102 | . $error, | ||||
| 103 | method_name => $method_to_call, | ||||
| 104 | object => $instance | ||||
| 105 | ); | ||||
| 106 | } | ||||
| 107 | unshift @_, @{ $self->curried_arguments }; | ||||
| 108 | $proxy->$method_to_call(@_); | ||||
| 109 | }; | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | # spent 3.51ms (1.55+1.96) within Moose::Meta::Method::Delegation::_get_delegate_accessor which was called 23 times, avg 152µs/call:
# 23 times (1.55ms+1.96ms) by Moose::Meta::Method::Delegation::_initialize_body at line 75, avg 152µs/call | ||||
| 113 | 115 | 1.50ms | my $self = shift; | ||
| 114 | 23 | 199µs | my $attr = $self->associated_attribute; # spent 199µs making 23 calls to Moose::Meta::Method::Delegation::associated_attribute, avg 9µs/call | ||
| 115 | |||||
| 116 | # NOTE: | ||||
| 117 | # always use a named method when | ||||
| 118 | # possible, if you use the method | ||||
| 119 | # ref and there are modifiers on | ||||
| 120 | # the accessors then it will not | ||||
| 121 | # pick up the modifiers too. Only | ||||
| 122 | # the named method will assure that | ||||
| 123 | # we also have any modifiers run. | ||||
| 124 | # - SL | ||||
| 125 | 46 | 1.65ms | my $accessor = $attr->has_read_method # spent 901µs making 23 calls to Class::MOP::Attribute::get_read_method, avg 39µs/call
# spent 746µs making 23 calls to Class::MOP::Mixin::AttributeCore::has_read_method, avg 32µs/call | ||
| 126 | ? $attr->get_read_method | ||||
| 127 | : $attr->get_read_method_ref; | ||||
| 128 | |||||
| 129 | 23 | 113µs | $accessor = $accessor->body if Scalar::Util::blessed $accessor; # spent 113µs making 23 calls to Scalar::Util::blessed, avg 5µs/call | ||
| 130 | |||||
| 131 | return $accessor; | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 1 | 12µs | 1; | ||
| 135 | |||||
| 136 | __END__ |