← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/pan_genome_post_analysis
  Run on Fri Mar 27 11:43:32 2015
Reported on Fri Mar 27 11:46:02 2015

Filename/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/Method/Delegation.pm
StatementsExecuted 12 statements in 534µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11113µs26µsMoose::Meta::Method::Delegation::::BEGIN@4Moose::Meta::Method::Delegation::BEGIN@4
11111µs16µsMoose::Meta::Method::Delegation::::BEGIN@5Moose::Meta::Method::Delegation::BEGIN@5
1119µs144µsMoose::Meta::Method::Delegation::::BEGIN@12Moose::Meta::Method::Delegation::BEGIN@12
1118µs36µsMoose::Meta::Method::Delegation::::BEGIN@7Moose::Meta::Method::Delegation::BEGIN@7
1117µs37µsMoose::Meta::Method::Delegation::::BEGIN@9Moose::Meta::Method::Delegation::BEGIN@9
0000s0sMoose::Meta::Method::Delegation::::__ANON__[:111]Moose::Meta::Method::Delegation::__ANON__[:111]
0000s0sMoose::Meta::Method::Delegation::::_get_delegate_accessorMoose::Meta::Method::Delegation::_get_delegate_accessor
0000s0sMoose::Meta::Method::Delegation::::_initialize_bodyMoose::Meta::Method::Delegation::_initialize_body
0000s0sMoose::Meta::Method::Delegation::::_newMoose::Meta::Method::Delegation::_new
0000s0sMoose::Meta::Method::Delegation::::associated_attributeMoose::Meta::Method::Delegation::associated_attribute
0000s0sMoose::Meta::Method::Delegation::::curried_argumentsMoose::Meta::Method::Delegation::curried_arguments
0000s0sMoose::Meta::Method::Delegation::::delegate_to_methodMoose::Meta::Method::Delegation::delegate_to_method
0000s0sMoose::Meta::Method::Delegation::::newMoose::Meta::Method::Delegation::new
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moose::Meta::Method::Delegation;
21600nsour $VERSION = '2.1403';
3
4222µs239µs
# spent 26µs (13+13) within Moose::Meta::Method::Delegation::BEGIN@4 which was called: # once (13µs+13µs) by Moose::Meta::Attribute::BEGIN@14 at line 4
use strict;
# spent 26µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@4 # spent 13µs making 1 call to strict::import
5224µs220µs
# spent 16µs (11+4) within Moose::Meta::Method::Delegation::BEGIN@5 which was called: # once (11µs+4µs) by Moose::Meta::Attribute::BEGIN@14 at line 5
use warnings;
# spent 16µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@5 # spent 4µs making 1 call to warnings::import
6
7226µs265µs
# spent 36µs (8+29) within Moose::Meta::Method::Delegation::BEGIN@7 which was called: # once (8µs+29µs) by Moose::Meta::Attribute::BEGIN@14 at line 7
use Scalar::Util 'blessed', 'weaken';
# spent 36µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@7 # spent 29µs making 1 call to Exporter::import
8
91400ns
# spent 37µs (7+30) within Moose::Meta::Method::Delegation::BEGIN@9 which was called: # once (7µs+30µs) by Moose::Meta::Attribute::BEGIN@14 at line 10
use parent 'Moose::Meta::Method',
10127µs266µs 'Class::MOP::Method::Generated';
# spent 37µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@9 # spent 30µs making 1 call to parent::import
11
122431µs2278µs
# spent 144µs (9+135) within Moose::Meta::Method::Delegation::BEGIN@12 which was called: # once (9µs+135µs) by Moose::Meta::Attribute::BEGIN@14 at line 12
use Moose::Util 'throw_exception';
# spent 144µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@12 # spent 135µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
13
14sub new {
15 my $class = shift;
16 my %options = @_;
17
18 ( exists $options{attribute} )
19 || throw_exception( MustSupplyAnAttributeToConstructWith => params => \%options,
20 class => $class
21 );
22
23 ( blessed( $options{attribute} )
24 && $options{attribute}->isa('Moose::Meta::Attribute') )
25 || throw_exception( MustSupplyAMooseMetaAttributeInstance => params => \%options,
26 class => $class
27 );
28
29 ( $options{package_name} && $options{name} )
30 || throw_exception( MustSupplyPackageNameAndName => params => \%options,
31 class => $class
32 );
33
34 ( $options{delegate_to_method} && ( !ref $options{delegate_to_method} )
35 || ( 'CODE' eq ref $options{delegate_to_method} ) )
36 || throw_exception( MustSupplyADelegateToMethod => params => \%options,
37 class => $class
38 );
39
40 exists $options{curried_arguments}
41 || ( $options{curried_arguments} = [] );
42
43 ( $options{curried_arguments} &&
44 ( 'ARRAY' eq ref $options{curried_arguments} ) )
45 || throw_exception( MustSupplyArrayRefAsCurriedArguments => params => \%options,
46 class_name => $class
47 );
48
49 my $self = $class->_new( \%options );
50
51 weaken( $self->{'attribute'} );
52
53 $self->_initialize_body;
54
55 return $self;
56}
57
58sub _new {
59 my $class = shift;
60 my $options = @_ == 1 ? $_[0] : {@_};
61
62 return bless $options, $class;
63}
64
65sub curried_arguments { (shift)->{'curried_arguments'} }
66
67sub associated_attribute { (shift)->{'attribute'} }
68
69sub delegate_to_method { (shift)->{'delegate_to_method'} }
70
71sub _initialize_body {
72 my $self = shift;
73
74 my $method_to_call = $self->delegate_to_method;
75 return $self->{body} = $method_to_call
76 if ref $method_to_call;
77
78 my $accessor = $self->_get_delegate_accessor;
79
80 my $handle_name = $self->name;
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 };
112}
113
114sub _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
13613µs1;
137
138# ABSTRACT: A Moose Method metaclass for delegation methods
139
140__END__