| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/Method/Delegation.pm |
| Statements | Executed 68 statements in 469µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2 | 1 | 1 | 66µs | 137µs | Moose::Meta::Method::Delegation::new |
| 2 | 1 | 1 | 21µs | 65µs | Moose::Meta::Method::Delegation::_initialize_body |
| 2 | 1 | 1 | 19µs | 41µs | Moose::Meta::Method::Delegation::_get_delegate_accessor |
| 1 | 1 | 1 | 9µs | 11µs | Moose::Meta::Method::Delegation::BEGIN@4 |
| 1 | 1 | 1 | 5µs | 93µs | Moose::Meta::Method::Delegation::BEGIN@12 |
| 1 | 1 | 1 | 5µs | 8µs | Moose::Meta::Method::Delegation::BEGIN@5 |
| 1 | 1 | 1 | 4µs | 24µs | Moose::Meta::Method::Delegation::BEGIN@9 |
| 1 | 1 | 1 | 4µs | 25µs | Moose::Meta::Method::Delegation::BEGIN@7 |
| 2 | 1 | 1 | 4µs | 4µs | Moose::Meta::Method::Delegation::_new |
| 2 | 1 | 1 | 2µs | 2µs | Moose::Meta::Method::Delegation::delegate_to_method |
| 2 | 1 | 1 | 1µs | 1µs | Moose::Meta::Method::Delegation::associated_attribute |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Delegation::__ANON__[:111] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Delegation::curried_arguments |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::Method::Delegation; | ||||
| 2 | 1 | 200ns | our $VERSION = '2.1605'; | ||
| 3 | |||||
| 4 | 2 | 15µs | 2 | 12µs | # spent 11µs (9+1) within Moose::Meta::Method::Delegation::BEGIN@4 which was called:
# once (9µs+1µs) by Moose::Meta::Attribute::BEGIN@14 at line 4 # spent 11µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@4
# spent 2µs making 1 call to strict::import |
| 5 | 2 | 14µs | 2 | 12µs | # spent 8µs (5+3) within Moose::Meta::Method::Delegation::BEGIN@5 which was called:
# once (5µs+3µs) by Moose::Meta::Attribute::BEGIN@14 at line 5 # spent 8µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@5
# spent 3µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 2 | 18µs | 2 | 47µs | # spent 25µs (4+21) within Moose::Meta::Method::Delegation::BEGIN@7 which was called:
# once (4µs+21µs) by Moose::Meta::Attribute::BEGIN@14 at line 7 # spent 25µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@7
# spent 22µs making 1 call to Exporter::import |
| 8 | |||||
| 9 | 1 | 2µs | 1 | 20µs | # spent 24µs (4+20) within Moose::Meta::Method::Delegation::BEGIN@9 which was called:
# once (4µs+20µs) by Moose::Meta::Attribute::BEGIN@14 at line 10 # spent 20µs making 1 call to parent::import |
| 10 | 1 | 14µs | 1 | 24µs | 'Class::MOP::Method::Generated'; # spent 24µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@9 |
| 11 | |||||
| 12 | 2 | 290µs | 2 | 180µs | # spent 93µs (5+88) within Moose::Meta::Method::Delegation::BEGIN@12 which was called:
# once (5µs+88µs) by Moose::Meta::Attribute::BEGIN@14 at line 12 # spent 93µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@12
# spent 88µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 13 | |||||
| 14 | # spent 137µs (66+71) within Moose::Meta::Method::Delegation::new which was called 2 times, avg 68µs/call:
# 2 times (66µs+71µs) by Moose::Meta::Attribute::_make_delegation_method at line 1236 of Moose/Meta/Attribute.pm, avg 68µs/call | ||||
| 15 | 2 | 400ns | my $class = shift; | ||
| 16 | 2 | 3µs | my %options = @_; | ||
| 17 | |||||
| 18 | ( exists $options{attribute} ) | ||||
| 19 | 2 | 700ns | || throw_exception( MustSupplyAnAttributeToConstructWith => params => \%options, | ||
| 20 | class => $class | ||||
| 21 | ); | ||||
| 22 | |||||
| 23 | ( blessed( $options{attribute} ) | ||||
| 24 | 2 | 8µs | 4 | 2µs | && $options{attribute}->isa('Moose::Meta::Attribute') ) # spent 1µs making 2 calls to Scalar::Util::blessed, avg 500ns/call
# spent 1µs making 2 calls to UNIVERSAL::isa, avg 500ns/call |
| 25 | || throw_exception( MustSupplyAMooseMetaAttributeInstance => params => \%options, | ||||
| 26 | class => $class | ||||
| 27 | ); | ||||
| 28 | |||||
| 29 | ( $options{package_name} && $options{name} ) | ||||
| 30 | 2 | 800ns | || throw_exception( MustSupplyPackageNameAndName => params => \%options, | ||
| 31 | class => $class | ||||
| 32 | ); | ||||
| 33 | |||||
| 34 | ( $options{delegate_to_method} && ( !ref $options{delegate_to_method} ) | ||||
| 35 | 2 | 800ns | || ( 'CODE' eq ref $options{delegate_to_method} ) ) | ||
| 36 | || throw_exception( MustSupplyADelegateToMethod => params => \%options, | ||||
| 37 | class => $class | ||||
| 38 | ); | ||||
| 39 | |||||
| 40 | exists $options{curried_arguments} | ||||
| 41 | 2 | 200ns | || ( $options{curried_arguments} = [] ); | ||
| 42 | |||||
| 43 | ( $options{curried_arguments} && | ||||
| 44 | 2 | 1µs | ( 'ARRAY' eq ref $options{curried_arguments} ) ) | ||
| 45 | || throw_exception( MustSupplyArrayRefAsCurriedArguments => params => \%options, | ||||
| 46 | class_name => $class | ||||
| 47 | ); | ||||
| 48 | |||||
| 49 | 2 | 2µs | 2 | 4µs | my $self = $class->_new( \%options ); # spent 4µs making 2 calls to Moose::Meta::Method::Delegation::_new, avg 2µs/call |
| 50 | |||||
| 51 | 2 | 41µs | 2 | 700ns | weaken( $self->{'attribute'} ); # spent 700ns making 2 calls to Scalar::Util::weaken, avg 350ns/call |
| 52 | |||||
| 53 | 2 | 2µs | 2 | 65µs | $self->_initialize_body; # spent 65µs making 2 calls to Moose::Meta::Method::Delegation::_initialize_body, avg 32µs/call |
| 54 | |||||
| 55 | 2 | 3µs | return $self; | ||
| 56 | } | ||||
| 57 | |||||
| 58 | # spent 4µs within Moose::Meta::Method::Delegation::_new which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by Moose::Meta::Method::Delegation::new at line 49, avg 2µs/call | ||||
| 59 | 2 | 600ns | my $class = shift; | ||
| 60 | 2 | 1µs | my $options = @_ == 1 ? $_[0] : {@_}; | ||
| 61 | |||||
| 62 | 2 | 5µs | return bless $options, $class; | ||
| 63 | } | ||||
| 64 | |||||
| 65 | sub curried_arguments { (shift)->{'curried_arguments'} } | ||||
| 66 | |||||
| 67 | 2 | 3µs | # spent 1µs within Moose::Meta::Method::Delegation::associated_attribute which was called 2 times, avg 650ns/call:
# 2 times (1µs+0s) by Moose::Meta::Method::Delegation::_get_delegate_accessor at line 116, avg 650ns/call | ||
| 68 | |||||
| 69 | 2 | 3µs | # spent 2µs within Moose::Meta::Method::Delegation::delegate_to_method which was called 2 times, avg 900ns/call:
# 2 times (2µs+0s) by Moose::Meta::Method::Delegation::_initialize_body at line 74, avg 900ns/call | ||
| 70 | |||||
| 71 | # spent 65µs (21+44) within Moose::Meta::Method::Delegation::_initialize_body which was called 2 times, avg 32µs/call:
# 2 times (21µs+44µs) by Moose::Meta::Method::Delegation::new at line 53, avg 32µs/call | ||||
| 72 | 2 | 700ns | my $self = shift; | ||
| 73 | |||||
| 74 | 2 | 2µs | 2 | 2µs | my $method_to_call = $self->delegate_to_method; # spent 2µs making 2 calls to Moose::Meta::Method::Delegation::delegate_to_method, avg 900ns/call |
| 75 | 2 | 400ns | return $self->{body} = $method_to_call | ||
| 76 | if ref $method_to_call; | ||||
| 77 | |||||
| 78 | 2 | 2µs | 2 | 41µs | my $accessor = $self->_get_delegate_accessor; # spent 41µs making 2 calls to Moose::Meta::Method::Delegation::_get_delegate_accessor, avg 20µs/call |
| 79 | |||||
| 80 | 2 | 6µs | 2 | 1µs | my $handle_name = $self->name; # spent 1µs making 2 calls to Class::MOP::Method::name, avg 500ns/call |
| 81 | |||||
| 82 | # NOTE: we used to do a goto here, but the goto didn't handle | ||||
| 83 | # failure correctly (it just returned nothing), so I took that | ||||
| 84 | # out. However, the more I thought about it, the less I liked it | ||||
| 85 | # doing the goto, and I preferred the act of delegation being | ||||
| 86 | # actually represented in the stack trace. - SL | ||||
| 87 | # not inlining this, since it won't really speed things up at | ||||
| 88 | # all... the only thing that would end up different would be | ||||
| 89 | # interpolating in $method_to_call, and a bunch of things in the | ||||
| 90 | # error handling that mostly never gets called - doy | ||||
| 91 | $self->{body} = sub { | ||||
| 92 | my $instance = shift; | ||||
| 93 | my $proxy = $instance->$accessor(); | ||||
| 94 | |||||
| 95 | if( !defined $proxy ) { | ||||
| 96 | throw_exception( AttributeValueIsNotDefined => method => $self, | ||||
| 97 | instance => $instance, | ||||
| 98 | attribute => $self->associated_attribute, | ||||
| 99 | ); | ||||
| 100 | } | ||||
| 101 | elsif( ref($proxy) && !blessed($proxy) ) { | ||||
| 102 | throw_exception( AttributeValueIsNotAnObject => method => $self, | ||||
| 103 | instance => $instance, | ||||
| 104 | attribute => $self->associated_attribute, | ||||
| 105 | given_value => $proxy | ||||
| 106 | ); | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | unshift @_, @{ $self->curried_arguments }; | ||||
| 110 | $proxy->$method_to_call(@_); | ||||
| 111 | 2 | 8µs | }; | ||
| 112 | } | ||||
| 113 | |||||
| 114 | # spent 41µs (19+22) within Moose::Meta::Method::Delegation::_get_delegate_accessor which was called 2 times, avg 20µs/call:
# 2 times (19µs+22µs) by Moose::Meta::Method::Delegation::_initialize_body at line 78, avg 20µs/call | ||||
| 115 | 2 | 400ns | my $self = shift; | ||
| 116 | 2 | 2µs | 2 | 1µs | my $attr = $self->associated_attribute; # spent 1µs making 2 calls to Moose::Meta::Method::Delegation::associated_attribute, avg 650ns/call |
| 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 | 2 | 7µs | 4 | 20µs | my $accessor = $attr->has_read_method # spent 11µs making 2 calls to Class::MOP::Attribute::get_read_method, avg 6µs/call
# spent 9µs making 2 calls to Class::MOP::Mixin::AttributeCore::has_read_method, avg 5µs/call |
| 128 | ? $attr->get_read_method | ||||
| 129 | : $attr->get_read_method_ref; | ||||
| 130 | |||||
| 131 | 2 | 3µs | 2 | 400ns | $accessor = $accessor->body if Scalar::Util::blessed $accessor; # spent 400ns making 2 calls to Scalar::Util::blessed, avg 200ns/call |
| 132 | |||||
| 133 | 2 | 4µs | return $accessor; | ||
| 134 | } | ||||
| 135 | |||||
| 136 | 1 | 2µs | 1; | ||
| 137 | |||||
| 138 | # ABSTRACT: A Moose Method metaclass for delegation methods | ||||
| 139 | |||||
| 140 | __END__ |