Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Method/Delegation.pm |
Statements | Executed 19 statements in 543µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 8µs | 33µs | BEGIN@13 | Moose::Meta::Method::Delegation::
1 | 1 | 1 | 8µs | 8µs | BEGIN@3 | Moose::Meta::Method::Delegation::
1 | 1 | 1 | 8µs | 16µs | BEGIN@11 | Moose::Meta::Method::Delegation::
1 | 1 | 1 | 7µs | 10µs | BEGIN@10 | Moose::Meta::Method::Delegation::
1 | 1 | 1 | 7µs | 31µs | BEGIN@14 | Moose::Meta::Method::Delegation::
1 | 1 | 1 | 7µs | 100µs | BEGIN@16 | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | __ANON__[:111] | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | _get_delegate_accessor | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | _initialize_body | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | _new | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | associated_attribute | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | curried_arguments | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | delegate_to_method | Moose::Meta::Method::Delegation::
0 | 0 | 0 | 0s | 0s | new | Moose::Meta::Method::Delegation::
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 | 22µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@3 |
6 | { | ||||
7 | 2 | 1µs | $Moose::Meta::Method::Delegation::VERSION = '2.0602'; | ||
8 | } | ||||
9 | |||||
10 | 3 | 18µs | 2 | 13µs | # spent 10µs (7+3) within Moose::Meta::Method::Delegation::BEGIN@10 which was called:
# once (7µs+3µs) by Moose::Meta::Attribute::BEGIN@22 at line 10 # spent 10µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@10
# spent 3µs making 1 call to strict::import |
11 | 3 | 22µs | 2 | 25µs | # spent 16µs (8+9) within Moose::Meta::Method::Delegation::BEGIN@11 which was called:
# once (8µs+9µs) by Moose::Meta::Attribute::BEGIN@22 at line 11 # spent 16µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@11
# spent 9µs making 1 call to warnings::import |
12 | |||||
13 | 3 | 24µs | 2 | 58µs | # spent 33µs (8+25) within Moose::Meta::Method::Delegation::BEGIN@13 which was called:
# once (8µs+25µs) by Moose::Meta::Attribute::BEGIN@22 at line 13 # spent 33µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@13
# spent 25µs making 1 call to Exporter::import |
14 | 3 | 20µs | 2 | 56µs | # spent 31µs (7+24) within Moose::Meta::Method::Delegation::BEGIN@14 which was called:
# once (7µs+24µs) by Moose::Meta::Attribute::BEGIN@22 at line 14 # spent 31µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@14
# spent 24µs making 1 call to Exporter::import |
15 | |||||
16 | 1 | 94µs | # spent 100µs (7+93) within Moose::Meta::Method::Delegation::BEGIN@16 which was called:
# once (7µs+93µs) by Moose::Meta::Attribute::BEGIN@22 at line 17 # spent 94µs making 1 call to base::import | ||
17 | 3 | 431µs | 1 | 100µs | 'Class::MOP::Method::Generated'; # spent 100µs making 1 call to Moose::Meta::Method::Delegation::BEGIN@16 |
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 | sub curried_arguments { (shift)->{'curried_arguments'} } | ||||
65 | |||||
66 | sub associated_attribute { (shift)->{'attribute'} } | ||||
67 | |||||
68 | sub delegate_to_method { (shift)->{'delegate_to_method'} } | ||||
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 | 2µs | 1; | ||
137 | |||||
138 | # ABSTRACT: A Moose Method metaclass for delegation methods | ||||
139 | |||||
- - | |||||
142 | =pod | ||||
143 | |||||
144 | =head1 NAME | ||||
145 | |||||
146 | Moose::Meta::Method::Delegation - A Moose Method metaclass for delegation methods | ||||
147 | |||||
148 | =head1 VERSION | ||||
149 | |||||
150 | version 2.0602 | ||||
151 | |||||
152 | =head1 DESCRIPTION | ||||
153 | |||||
154 | This is a subclass of L<Moose::Meta::Method> for delegation | ||||
155 | methods. | ||||
156 | |||||
157 | =head1 METHODS | ||||
158 | |||||
159 | =over 4 | ||||
160 | |||||
161 | =item B<< Moose::Meta::Method::Delegation->new(%options) >> | ||||
162 | |||||
163 | This creates the delegation methods based on the provided C<%options>. | ||||
164 | |||||
165 | =over 4 | ||||
166 | |||||
167 | =item I<attribute> | ||||
168 | |||||
169 | This must be an instance of C<Moose::Meta::Attribute> which this | ||||
170 | accessor is being generated for. This options is B<required>. | ||||
171 | |||||
172 | =item I<delegate_to_method> | ||||
173 | |||||
174 | The method in the associated attribute's value to which we | ||||
175 | delegate. This can be either a method name or a code reference. | ||||
176 | |||||
177 | =item I<curried_arguments> | ||||
178 | |||||
179 | An array reference of arguments that will be prepended to the argument list for | ||||
180 | any call to the delegating method. | ||||
181 | |||||
182 | =back | ||||
183 | |||||
184 | =item B<< $metamethod->associated_attribute >> | ||||
185 | |||||
186 | Returns the attribute associated with this method. | ||||
187 | |||||
188 | =item B<< $metamethod->curried_arguments >> | ||||
189 | |||||
190 | Return any curried arguments that will be passed to the delegated method. | ||||
191 | |||||
192 | =item B<< $metamethod->delegate_to_method >> | ||||
193 | |||||
194 | Returns the method to which this method delegates, as passed to the | ||||
195 | constructor. | ||||
196 | |||||
197 | =back | ||||
198 | |||||
199 | =head1 BUGS | ||||
200 | |||||
201 | See L<Moose/BUGS> for details on reporting bugs. | ||||
202 | |||||
203 | =head1 AUTHOR | ||||
204 | |||||
205 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
206 | |||||
207 | =head1 COPYRIGHT AND LICENSE | ||||
208 | |||||
209 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
210 | |||||
211 | This is free software; you can redistribute it and/or modify it under | ||||
212 | the same terms as the Perl 5 programming language system itself. | ||||
213 | |||||
214 | =cut | ||||
215 | |||||
216 | |||||
217 | __END__ |