File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Method.pm |
Statements Executed | 2455 |
Statement Execution Time | 6.60ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
145 | 3 | 3 | 2.15ms | 3.85ms | wrap | Class::MOP::Method::
1 | 1 | 1 | 1.72ms | 1.91ms | BEGIN@19 | Class::MOP::Method::
304 | 1 | 1 | 1.05ms | 1.27ms | attach_to_class | Class::MOP::Method::
50 | 2 | 2 | 450µs | 1.48ms | _new | Class::MOP::Method::
550 | 6 | 5 | 313µs | 313µs | body (xsub) | Class::MOP::Method::
304 | 1 | 2 | 140µs | 140µs | package_name (xsub) | Class::MOP::Method::
1 | 1 | 1 | 53µs | 62µs | BEGIN@4 | Class::MOP::Method::
77 | 4 | 3 | 48µs | 48µs | name (xsub) | Class::MOP::Method::
1 | 1 | 1 | 24µs | 111µs | BEGIN@14 | Class::MOP::Method::
1 | 1 | 1 | 22µs | 100µs | BEGIN@7 | Class::MOP::Method::
1 | 1 | 1 | 22µs | 52µs | BEGIN@5 | Class::MOP::Method::
12 | 1 | 1 | 18µs | 18µs | _set_original_method | Class::MOP::Method::
1 | 1 | 1 | 14µs | 80µs | BEGIN@8 | Class::MOP::Method::
8 | 7 | 4 | 9µs | 9µs | associated_metaclass | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | __ANON__[:19] | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | detach_from_class | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | execute | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | fully_qualified_name | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | original_fully_qualified_name | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | original_method | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | original_name | Class::MOP::Method::
0 | 0 | 0 | 0s | 0s | original_package_name | Class::MOP::Method::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Class::MOP::Method; | ||||
3 | |||||
4 | 3 | 74µs | 2 | 72µs | # spent 62µs (53+9) within Class::MOP::Method::BEGIN@4 which was called
# once (53µs+9µs) by base::import at line 4 # spent 62µs making 1 call to Class::MOP::Method::BEGIN@4
# spent 9µs making 1 call to strict::import |
5 | 3 | 86µs | 2 | 81µs | # spent 52µs (22+30) within Class::MOP::Method::BEGIN@5 which was called
# once (22µs+30µs) by base::import at line 5 # spent 52µs making 1 call to Class::MOP::Method::BEGIN@5
# spent 30µs making 1 call to warnings::import |
6 | |||||
7 | 3 | 71µs | 2 | 178µs | # spent 100µs (22+78) within Class::MOP::Method::BEGIN@7 which was called
# once (22µs+78µs) by base::import at line 7 # spent 100µs making 1 call to Class::MOP::Method::BEGIN@7
# spent 78µs making 1 call to Exporter::import |
8 | 3 | 90µs | 2 | 145µs | # spent 80µs (14+65) within Class::MOP::Method::BEGIN@8 which was called
# once (14µs+65µs) by base::import at line 8 # spent 80µs making 1 call to Class::MOP::Method::BEGIN@8
# spent 66µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 1µs | our $VERSION = '0.98'; | ||
11 | 1 | 23µs | $VERSION = eval $VERSION; | ||
12 | 1 | 600ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
13 | |||||
14 | 3 | 93µs | 2 | 111µs | # spent 111µs (24+87) within Class::MOP::Method::BEGIN@14 which was called
# once (24µs+87µs) by base::import at line 14 # spent 111µs making 1 call to Class::MOP::Method::BEGIN@14
# spent 87µs making 1 call to base::import, recursion: max depth 1, time 87µs |
15 | |||||
16 | # NOTE: | ||||
17 | # if poked in the right way, | ||||
18 | # they should act like CODE refs. | ||||
19 | 3 | 2.04ms | 2 | 1.95ms | # spent 1.91ms (1.72+183µs) within Class::MOP::Method::BEGIN@19 which was called
# once (1.72ms+183µs) by base::import at line 19 # spent 1.91ms making 1 call to Class::MOP::Method::BEGIN@19
# spent 44µs making 1 call to overload::import |
20 | |||||
21 | # construction | ||||
22 | |||||
23 | # spent 3.85ms (2.15+1.70) within Class::MOP::Method::wrap which was called 145 times, avg 27µs/call:
# 57 times (854µs+693µs) by Class::MOP::Attribute::_process_accessors at line 310 of Class/MOP/Attribute.pm, avg 27µs/call
# 52 times (787µs+635µs) by Class::MOP::Mixin::HasMethods::wrap_method_body at line 31 of Class/MOP/Mixin/HasMethods.pm, avg 27µs/call
# 36 times (513µs+370µs) by Class::MOP::Method::Wrapped::wrap at line 92 of Class/MOP/Method/Wrapped.pm, avg 25µs/call | ||||
24 | 1305 | 2.29ms | my ( $class, @args ) = @_; | ||
25 | |||||
26 | unshift @args, 'body' if @args % 2 == 1; | ||||
27 | |||||
28 | my %params = @args; | ||||
29 | my $code = $params{body}; | ||||
30 | |||||
31 | if (blessed($code) && $code->isa(__PACKAGE__)) { # spent 92µs making 145 calls to Scalar::Util::blessed, avg 636ns/call
# spent 77µs making 145 calls to Scalar::Util::reftype, avg 532ns/call | ||||
32 | my $method = $code->clone; | ||||
33 | delete $params{body}; | ||||
34 | Class::MOP::class_of($class)->rebless_instance($method, %params); | ||||
35 | return $method; | ||||
36 | } | ||||
37 | elsif (!ref $code || 'CODE' ne reftype($code)) { | ||||
38 | confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")"; | ||||
39 | } | ||||
40 | |||||
41 | ($params{package_name} && $params{name}) | ||||
42 | || confess "You must supply the package_name and name parameters"; | ||||
43 | |||||
44 | my $self = $class->_new(\%params); # spent 628µs making 57 calls to Class::MOP::Method::Accessor::_new, avg 11µs/call
# spent 435µs making 48 calls to Class::MOP::Method::_new, avg 9µs/call
# spent 327µs making 36 calls to Class::MOP::Method::Wrapped::_new, avg 9µs/call
# spent 89µs making 4 calls to Moose::Meta::Method::_new, avg 22µs/call | ||||
45 | |||||
46 | weaken($self->{associated_metaclass}) if $self->{associated_metaclass}; # spent 49µs making 52 calls to Scalar::Util::weaken, avg 944ns/call | ||||
47 | |||||
48 | return $self; | ||||
49 | } | ||||
50 | |||||
51 | # spent 1.48ms (450µs+1.03) within Class::MOP::Method::_new which was called 50 times, avg 30µs/call:
# 48 times (435µs+0s) by Class::MOP::Method::wrap at line 44, avg 9µs/call
# 2 times (15µs+1.03ms) by Class::MOP::Method::Accessor::new at line 32 of Class/MOP/Method/Accessor.pm, avg 521µs/call | ||||
52 | 196 | 443µs | my $class = shift; | ||
53 | |||||
54 | return Class::MOP::Class->initialize($class)->new_object(@_) # spent 971µs making 2 calls to Class::MOP::Class::new_object, avg 486µs/call
# spent 55µs making 2 calls to Class::MOP::Class::initialize, avg 27µs/call | ||||
55 | if $class ne __PACKAGE__; | ||||
56 | |||||
57 | my $params = @_ == 1 ? $_[0] : {@_}; | ||||
58 | |||||
59 | return bless { | ||||
60 | 'body' => $params->{body}, | ||||
61 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||
62 | 'package_name' => $params->{package_name}, | ||||
63 | 'name' => $params->{name}, | ||||
64 | 'original_method' => $params->{original_method}, | ||||
65 | } => $class; | ||||
66 | } | ||||
67 | |||||
68 | ## accessors | ||||
69 | |||||
70 | 8 | 23µs | # spent 9µs within Class::MOP::Method::associated_metaclass which was called 8 times, avg 1µs/call:
# 2 times (2µs+0s) by Class::MOP::Method::Inlined::can_be_inlined at line 34 of Class/MOP/Method/Inlined.pm, avg 1µs/call
# once (2µs+0s) by Moose::Meta::Method::Constructor::_initialize_body at line 63 of Moose/Meta/Method/Constructor.pm
# once (1µs+0s) by Moose::Meta::Method::Constructor::_generate_BUILDALL at line 153 of Moose/Meta/Method/Constructor.pm
# once (1µs+0s) by Class::MOP::Method::Constructor::_meta_instance at line 77 of Class/MOP/Method/Constructor.pm
# once (1µs+0s) by Moose::Meta::Method::Destructor::_initialize_body at line 81 of Moose/Meta/Method/Destructor.pm
# once (800ns+0s) by Class::MOP::Method::Constructor::_attributes at line 82 of Class/MOP/Method/Constructor.pm
# once (700ns+0s) by Moose::Meta::Method::Constructor::_generate_BUILDARGS at line 135 of Moose/Meta/Method/Constructor.pm | ||
71 | |||||
72 | # spent 1.27ms (1.05+217µs) within Class::MOP::Method::attach_to_class which was called 304 times, avg 4µs/call:
# 304 times (1.05ms+217µs) by Class::MOP::Mixin::HasMethods::add_method at line 52 of Class/MOP/Mixin/HasMethods.pm, avg 4µs/call | ||||
73 | 912 | 1.34ms | my ( $self, $class ) = @_; | ||
74 | $self->{associated_metaclass} = $class; | ||||
75 | weaken($self->{associated_metaclass}); # spent 217µs making 304 calls to Scalar::Util::weaken, avg 715ns/call | ||||
76 | } | ||||
77 | |||||
78 | sub detach_from_class { | ||||
79 | my $self = shift; | ||||
80 | delete $self->{associated_metaclass}; | ||||
81 | } | ||||
82 | |||||
83 | sub fully_qualified_name { | ||||
84 | my $self = shift; | ||||
85 | $self->package_name . '::' . $self->name; | ||||
86 | } | ||||
87 | |||||
88 | sub original_method { (shift)->{'original_method'} } | ||||
89 | |||||
90 | 12 | 26µs | # spent 18µs within Class::MOP::Method::_set_original_method which was called 12 times, avg 1µs/call:
# 12 times (18µs+0s) by Class::MOP::Method::clone at line 539 of Class/MOP.pm, avg 1µs/call | ||
91 | |||||
92 | # It's possible that this could cause a loop if there is a circular | ||||
93 | # reference in here. That shouldn't ever happen in normal | ||||
94 | # circumstances, since original method only gets set when clone is | ||||
95 | # called. We _could_ check for such a loop, but it'd involve some sort | ||||
96 | # of package-lexical variable, and wouldn't be terribly subclassable. | ||||
97 | sub original_package_name { | ||||
98 | my $self = shift; | ||||
99 | |||||
100 | $self->original_method | ||||
101 | ? $self->original_method->original_package_name | ||||
102 | : $self->package_name; | ||||
103 | } | ||||
104 | |||||
105 | sub original_name { | ||||
106 | my $self = shift; | ||||
107 | |||||
108 | $self->original_method | ||||
109 | ? $self->original_method->original_name | ||||
110 | : $self->name; | ||||
111 | } | ||||
112 | |||||
113 | sub original_fully_qualified_name { | ||||
114 | my $self = shift; | ||||
115 | |||||
116 | $self->original_method | ||||
117 | ? $self->original_method->original_fully_qualified_name | ||||
118 | : $self->fully_qualified_name; | ||||
119 | } | ||||
120 | |||||
121 | sub execute { | ||||
122 | my $self = shift; | ||||
123 | $self->body->(@_); | ||||
124 | } | ||||
125 | |||||
126 | # NOTE: | ||||
127 | # the Class::MOP bootstrap | ||||
128 | # will create this for us | ||||
129 | # - SL | ||||
130 | # sub clone { ... } | ||||
131 | |||||
132 | 1 | 7µs | 1; | ||
133 | |||||
134 | __END__ | ||||
135 | |||||
136 | =pod | ||||
137 | |||||
138 | =head1 NAME | ||||
139 | |||||
140 | Class::MOP::Method - Method Meta Object | ||||
141 | |||||
142 | =head1 DESCRIPTION | ||||
143 | |||||
144 | The Method Protocol is very small, since methods in Perl 5 are just | ||||
145 | subroutines in a specific package. We provide a very basic | ||||
146 | introspection interface. | ||||
147 | |||||
148 | =head1 METHODS | ||||
149 | |||||
150 | =over 4 | ||||
151 | |||||
152 | =item B<< Class::MOP::Method->wrap($code, %options) >> | ||||
153 | |||||
154 | This is the constructor. It accepts a method body in the form of | ||||
155 | either a code reference or a L<Class::MOP::Method> instance, followed | ||||
156 | by a hash of options. | ||||
157 | |||||
158 | The options are: | ||||
159 | |||||
160 | =over 8 | ||||
161 | |||||
162 | =item * name | ||||
163 | |||||
164 | The method name (without a package name). This is required if C<$code> | ||||
165 | is a coderef. | ||||
166 | |||||
167 | =item * package_name | ||||
168 | |||||
169 | The package name for the method. This is required if C<$code> is a | ||||
170 | coderef. | ||||
171 | |||||
172 | =item * associated_metaclass | ||||
173 | |||||
174 | An optional L<Class::MOP::Class> object. This is the metaclass for the | ||||
175 | method's class. | ||||
176 | |||||
177 | =back | ||||
178 | |||||
179 | =item B<< $metamethod->clone(%params) >> | ||||
180 | |||||
181 | This makes a shallow clone of the method object. In particular, | ||||
182 | subroutine reference itself is shared between all clones of a given | ||||
183 | method. | ||||
184 | |||||
185 | When a method is cloned, the original method object will be available | ||||
186 | by calling C<original_method> on the clone. | ||||
187 | |||||
188 | =item B<< $metamethod->body >> | ||||
189 | |||||
190 | This returns a reference to the method's subroutine. | ||||
191 | |||||
192 | =item B<< $metamethod->name >> | ||||
193 | |||||
194 | This returns the method's name | ||||
195 | |||||
196 | =item B<< $metamethod->package_name >> | ||||
197 | |||||
198 | This returns the method's package name. | ||||
199 | |||||
200 | =item B<< $metamethod->fully_qualified_name >> | ||||
201 | |||||
202 | This returns the method's fully qualified name (package name and | ||||
203 | method name). | ||||
204 | |||||
205 | =item B<< $metamethod->associated_metaclass >> | ||||
206 | |||||
207 | This returns the L<Class::MOP::Class> object for the method, if one | ||||
208 | exists. | ||||
209 | |||||
210 | =item B<< $metamethod->original_method >> | ||||
211 | |||||
212 | If this method object was created as a clone of some other method | ||||
213 | object, this returns the object that was cloned. | ||||
214 | |||||
215 | =item B<< $metamethod->original_name >> | ||||
216 | |||||
217 | This returns the method's original name, wherever it was first | ||||
218 | defined. | ||||
219 | |||||
220 | If this method is a clone of a clone (of a clone, etc.), this method | ||||
221 | returns the name from the I<first> method in the chain of clones. | ||||
222 | |||||
223 | =item B<< $metamethod->original_package_name >> | ||||
224 | |||||
225 | This returns the method's original package name, wherever it was first | ||||
226 | defined. | ||||
227 | |||||
228 | If this method is a clone of a clone (of a clone, etc.), this method | ||||
229 | returns the package name from the I<first> method in the chain of | ||||
230 | clones. | ||||
231 | |||||
232 | =item B<< $metamethod->original_fully_qualified_name >> | ||||
233 | |||||
234 | This returns the method's original fully qualified name, wherever it | ||||
235 | was first defined. | ||||
236 | |||||
237 | If this method is a clone of a clone (of a clone, etc.), this method | ||||
238 | returns the fully qualified name from the I<first> method in the chain | ||||
239 | of clones. | ||||
240 | |||||
241 | =item B<< $metamethod->attach_to_class($metaclass) >> | ||||
242 | |||||
243 | Given a L<Class::MOP::Class> object, this method sets the associated | ||||
244 | metaclass for the method. This will overwrite any existing associated | ||||
245 | metaclass. | ||||
246 | |||||
247 | =item B<< $metamethod->detach_from_class >> | ||||
248 | |||||
249 | Removes any associated metaclass object for the method. | ||||
250 | |||||
251 | =item B<< $metamethod->execute(...) >> | ||||
252 | |||||
253 | This executes the method. Any arguments provided will be passed on to | ||||
254 | the method itself. | ||||
255 | |||||
256 | =item B<< Class::MOP::Method->meta >> | ||||
257 | |||||
258 | This will return a L<Class::MOP::Class> instance for this class. | ||||
259 | |||||
260 | It should also be noted that L<Class::MOP> will actually bootstrap | ||||
261 | this module by installing a number of attribute meta-objects into its | ||||
262 | metaclass. | ||||
263 | |||||
264 | =back | ||||
265 | |||||
266 | =head1 AUTHORS | ||||
267 | |||||
268 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
269 | |||||
270 | =head1 COPYRIGHT AND LICENSE | ||||
271 | |||||
272 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
273 | |||||
274 | L<http://www.iinteractive.com> | ||||
275 | |||||
276 | This library is free software; you can redistribute it and/or modify | ||||
277 | it under the same terms as Perl itself. | ||||
278 | |||||
279 | =cut | ||||
280 | |||||
# spent 313µs within Class::MOP::Method::body which was called 550 times, avg 569ns/call:
# 304 times (184µs+0s) by Class::MOP::Mixin::HasMethods::add_method at line 44 of Class/MOP/Mixin/HasMethods.pm, avg 605ns/call
# 137 times (74µs+0s) by Class::MOP::Mixin::HasMethods::get_method at line 115 of Class/MOP/Mixin/HasMethods.pm, avg 543ns/call
# 36 times (23µs+0s) by Class::MOP::Class::_immutable_metaclass at line 970 of Class/MOP/Class.pm, avg 633ns/call
# 36 times (16µs+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 168 of Class/MOP/Method/Wrapped.pm, avg 444ns/call
# 36 times (15µs+0s) by Class::MOP::Method::Wrapped::wrap at line 77 of Class/MOP/Method/Wrapped.pm, avg 411ns/call
# once (700ns+0s) by Moose::Meta::Method::Constructor::_generate_BUILDARGS at line 137 of Moose/Meta/Method/Constructor.pm | |||||
# spent 48µs within Class::MOP::Method::name which was called 77 times, avg 617ns/call:
# 42 times (27µs+0s) by Class::MOP::Class::_immutable_metaclass at line 968 of Class/MOP/Class.pm, avg 648ns/call
# 33 times (19µs+0s) by Class::MOP::Method::Inlined::can_be_inlined at line 40 of Class/MOP/Method/Inlined.pm, avg 585ns/call
# once (600ns+0s) by Class::MOP::Method::Inlined::can_be_inlined at line 58 of Class/MOP/Method/Inlined.pm
# once (400ns+0s) by Class::MOP::Method::Inlined::can_be_inlined at line 70 of Class/MOP/Method/Inlined.pm | |||||
# spent 140µs within Class::MOP::Method::package_name which was called 304 times, avg 461ns/call:
# 304 times (140µs+0s) by Class::MOP::Mixin::HasMethods::add_method at line 45 of Class/MOP/Mixin/HasMethods.pm, avg 461ns/call |