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