Profile of Class/MOP/Method.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:27 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Class/MOP/Method.pm
Statements | Executed 3215 statements in 7.31ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
181 | 4 | 4 | 3.11ms | 16.9ms | Class::MOP::Method::::wrapClass::MOP::Method::wrap
367 | 1 | 1 | 1.39ms | 1.66ms | Class::MOP::Method::::attach_to_classClass::MOP::Method::attach_to_class
35 | 2 | 2 | 531µs | 645µs | Class::MOP::Method::::cloneClass::MOP::Method::clone
74 | 1 | 1 | 508µs | 6.03ms | Class::MOP::Method::::_newClass::MOP::Method::_new
1 | 1 | 1 | 9µs | 46µs | Class::MOP::Method::::BEGIN@21Class::MOP::Method::BEGIN@21
1 | 1 | 1 | 8µs | 8µs | Class::MOP::Method::::BEGIN@3Class::MOP::Method::BEGIN@3
1 | 1 | 1 | 7µs | 619µs | Class::MOP::Method::::BEGIN@16Class::MOP::Method::BEGIN@16
1 | 1 | 1 | 7µs | 22µs | Class::MOP::Method::::BEGIN@11Class::MOP::Method::BEGIN@11
1 | 1 | 1 | 7µs | 36µs | Class::MOP::Method::::BEGIN@14Class::MOP::Method::BEGIN@14
1 | 1 | 1 | 6µs | 9µs | Class::MOP::Method::::BEGIN@10Class::MOP::Method::BEGIN@10
1 | 1 | 1 | 6µs | 39µs | Class::MOP::Method::::BEGIN@13Class::MOP::Method::BEGIN@13
1 | 1 | 1 | 1µs | 1µs | Class::MOP::Method::::is_stubClass::MOP::Method::is_stub (xsub)
0 | 0 | 0 | 0s | 0s | Class::MOP::Method::::__ANON__[:21]Class::MOP::Method::__ANON__[:21]
0 | 0 | 0 | 0s | 0s | Class::MOP::Method::::detach_from_classClass::MOP::Method::detach_from_class
0 | 0 | 0 | 0s | 0s | Class::MOP::Method::::executeClass::MOP::Method::execute
0 | 0 | 0 | 0s | 0s | Class::MOP::Method::::fully_qualified_nameClass::MOP::Method::fully_qualified_name
0 | 0 | 0 | 0s | 0s | Class::MOP::Method::::original_fully_qualified_nameClass::MOP::Method::original_fully_qualified_name
0 | 0 | 0 | 0s | 0s | Class::MOP::Method::::original_nameClass::MOP::Method::original_name
0 | 0 | 0 | 0s | 0s | Class::MOP::Method::::original_package_nameClass::MOP::Method::original_package_name

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  |
2 |  |  |  |  | package Class::MOP::Method;
3 |  |  |  |  | # spent 8µs within Class::MOP::Method::BEGIN@3 which was called: # once (8µs+0s) by base::import at line 5 BEGIN {
4 | 1 | 4µs |  |  | $Class::MOP::Method::AUTHORITY = 'cpan:STEVAN';
5 | 1 | 22µs | 1 | 8µs | } # spent 8µs making 1 call to Class::MOP::Method::BEGIN@3
6 |  |  |  |  | {
7 | 2 | 1µs |  |  | $Class::MOP::Method::VERSION = '2.0602';
8 |  |  |  |  | }
9 |  |  |  |  |
10 | 3 | 16µs | 2 | 12µs | # spent 9µs (6+3) within Class::MOP::Method::BEGIN@10 which was called: # once (6µs+3µs) by base::import at line 10 use strict; # spent 9µs making 1 call to Class::MOP::Method::BEGIN@10 # spent 3µs making 1 call to strict::import
11 | 3 | 18µs | 2 | 38µs | # spent 22µs (7+15) within Class::MOP::Method::BEGIN@11 which was called: # once (7µs+15µs) by base::import at line 11 use warnings; # spent 22µs making 1 call to Class::MOP::Method::BEGIN@11 # spent 15µs making 1 call to warnings::import
12 |  |  |  |  |
13 | 3 | 20µs | 2 | 72µs | # spent 39µs (6+33) within Class::MOP::Method::BEGIN@13 which was called: # once (6µs+33µs) by base::import at line 13 use Carp 'confess'; # spent 39µs making 1 call to Class::MOP::Method::BEGIN@13 # spent 33µs making 1 call to Exporter::import
14 | 3 | 18µs | 2 | 66µs | # spent 36µs (7+30) within Class::MOP::Method::BEGIN@14 which was called: # once (7µs+30µs) by base::import at line 14 use Scalar::Util 'weaken', 'reftype', 'blessed'; # spent 36µs making 1 call to Class::MOP::Method::BEGIN@14 # spent 30µs making 1 call to Exporter::import
15 |  |  |  |  |
16 | 3 | 38µs | 2 | 619µs | # spent 619µs (7+612) within Class::MOP::Method::BEGIN@16 which was called: # once (7µs+612µs) by base::import at line 16 use base 'Class::MOP::Object'; # spent 619µs making 1 call to Class::MOP::Method::BEGIN@16 # spent 612µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 612µs
17 |  |  |  |  |
18 |  |  |  |  | # NOTE:
19 |  |  |  |  | # if poked in the right way,
20 |  |  |  |  | # they should act like CODE refs.
21 | 3 | 505µs | 2 | 83µs | # spent 46µs (9+37) within Class::MOP::Method::BEGIN@21 which was called: # once (9µs+37µs) by base::import at line 21 use overload '&{}' => sub { $_[0]->body }, fallback => 1; # spent 46µs making 1 call to Class::MOP::Method::BEGIN@21 # spent 37µs making 1 call to overload::import
22 |  |  |  |  |
23 |  |  |  |  | # construction
24 |  |  |  |  |
25 |  |  |  |  | # spent 16.9ms (3.11+13.8) within Class::MOP::Method::wrap which was called 181 times, avg 94µs/call: # 66 times (1.07ms+1.39ms) by Class::MOP::Mixin::HasMethods::wrap_method_body at line 48 of Class/MOP/Mixin/HasMethods.pm, avg 37µs/call # 57 times (914µs+1.73ms) by Class::MOP::Attribute::_process_accessors at line 372 of Class/MOP/Attribute.pm, avg 46µs/call # 35 times (776µs+10.3ms) by Class::MOP::Method::Meta::wrap at line 62 of Class/MOP/Method/Meta.pm, avg 316µs/call # 23 times (348µs+424µs) by Class::MOP::Method::Wrapped::wrap at line 94 of Class/MOP/Method/Wrapped.pm, avg 34µs/call sub wrap {
26 | 181 | 374µs |  |  | my ( $class, @args ) = @_;
27 |  |  |  |  |
28 | 181 | 146µs |  |  | unshift @args, 'body' if @args % 2 == 1;
29 |  |  |  |  |
30 | 181 | 393µs |  |  | my %params = @args;
31 | 181 | 66µs |  |  | my $code = $params{body};
32 |  |  |  |  |
33 | 181 | 969µs | 362 | 258µs | if (blessed($code) && $code->isa(__PACKAGE__)) { # spent 133µs making 181 calls to Scalar::Util::blessed, avg 735ns/call # spent 125µs making 181 calls to Scalar::Util::reftype, avg 691ns/call
34 |  |  |  |  | my $method = $code->clone;
35 |  |  |  |  | delete $params{body};
36 |  |  |  |  | Class::MOP::class_of($class)->rebless_instance($method, %params);
37 |  |  |  |  | return $method;
38 |  |  |  |  | }
39 |  |  |  |  | elsif (!ref $code || 'CODE' ne reftype($code)) {
40 |  |  |  |  | confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")";
41 |  |  |  |  | }
42 |  |  |  |  |
43 | 181 | 83µs |  |  | ($params{package_name} && $params{name})
44 |  |  |  |  | || confess "You must supply the package_name and name parameters";
45 |  |  |  |  |
46 | 181 | 408µs | 181 | 13.4ms | my $self = $class->_new(\%params); # spent 6.03ms making 74 calls to Class::MOP::Method::_new, avg 81µs/call # spent 4.47ms making 12 calls to Moose::Meta::Method::_new, avg 373µs/call # spent 1.57ms making 57 calls to Class::MOP::Method::Accessor::_new, avg 27µs/call # spent 899µs making 15 calls to Moose::Meta::Role::Method::_new, avg 60µs/call # spent 395µs making 23 calls to Class::MOP::Method::Wrapped::_new, avg 17µs/call
47 |  |  |  |  |
48 | 181 | 556µs | 158 | 206µs | weaken($self->{associated_metaclass}) if $self->{associated_metaclass}; # spent 206µs making 158 calls to Scalar::Util::weaken, avg 1µs/call
49 |  |  |  |  |
50 | 181 | 576µs |  |  | return $self;
51 |  |  |  |  | }
52 |  |  |  |  |
53 |  |  |  |  | # spent 6.03ms (508µs+5.52) within Class::MOP::Method::_new which was called 74 times, avg 81µs/call: # 74 times (508µs+5.52ms) by Class::MOP::Method::wrap at line 46, avg 81µs/call sub _new {
54 | 74 | 34µs |  |  | my $class = shift;
55 |  |  |  |  |
56 | 74 | 147µs | 46 | 5.52ms | return Class::MOP::Class->initialize($class)->new_object(@_) # spent 4.63ms making 23 calls to Class::MOP::Class::new_object, avg 201µs/call # spent 893µs making 23 calls to Class::MOP::Class::initialize, avg 39µs/call
57 |  |  |  |  | if $class ne __PACKAGE__;
58 |  |  |  |  |
59 | 51 | 20µs |  |  | my $params = @_ == 1 ? $_[0] : {@_};
60 |  |  |  |  |
61 | 51 | 332µs |  |  | return bless {
62 |  |  |  |  | 'body' => $params->{body},
63 |  |  |  |  | 'associated_metaclass' => $params->{associated_metaclass},
64 |  |  |  |  | 'package_name' => $params->{package_name},
65 |  |  |  |  | 'name' => $params->{name},
66 |  |  |  |  | 'original_method' => $params->{original_method},
67 |  |  |  |  | } => $class;
68 |  |  |  |  | }
69 |  |  |  |  |
70 |  |  |  |  | ## accessors
71 |  |  |  |  |
72 | 3 | 8µs |  |  | sub associated_metaclass { shift->{'associated_metaclass'} }
73 |  |  |  |  |
74 |  |  |  |  | # spent 1.66ms (1.39+270µs) within Class::MOP::Method::attach_to_class which was called 367 times, avg 5µs/call: # 367 times (1.39ms+270µs) by Class::MOP::Mixin::HasMethods::add_method at line 71 of Class/MOP/Mixin/HasMethods.pm, avg 5µs/call sub attach_to_class {
75 | 367 | 168µs |  |  | my ( $self, $class ) = @_;
76 | 367 | 214µs |  |  | $self->{associated_metaclass} = $class;
77 | 367 | 1.50ms | 367 | 270µs | weaken($self->{associated_metaclass}); # spent 270µs making 367 calls to Scalar::Util::weaken, avg 736ns/call
78 |  |  |  |  | }
79 |  |  |  |  |
80 |  |  |  |  | sub detach_from_class {
81 |  |  |  |  | my $self = shift;
82 |  |  |  |  | delete $self->{associated_metaclass};
83 |  |  |  |  | }
84 |  |  |  |  |
85 |  |  |  |  | sub fully_qualified_name {
86 |  |  |  |  | my $self = shift;
87 |  |  |  |  | $self->package_name . '::' . $self->name;
88 |  |  |  |  | }
89 |  |  |  |  |
90 |  |  |  |  | sub original_method { (shift)->{'original_method'} }
91 |  |  |  |  |
92 | 35 | 91µs |  |  | sub _set_original_method { $_[0]->{'original_method'} = $_[1] }
93 |  |  |  |  |
94 |  |  |  |  | # It's possible that this could cause a loop if there is a circular
95 |  |  |  |  | # reference in here. That shouldn't ever happen in normal
96 |  |  |  |  | # circumstances, since original method only gets set when clone is
97 |  |  |  |  | # called. We _could_ check for such a loop, but it'd involve some sort
98 |  |  |  |  | # of package-lexical variable, and wouldn't be terribly subclassable.
99 |  |  |  |  | sub original_package_name {
100 |  |  |  |  | my $self = shift;
101 |  |  |  |  |
102 |  |  |  |  | $self->original_method
103 |  |  |  |  | ? $self->original_method->original_package_name
104 |  |  |  |  | : $self->package_name;
105 |  |  |  |  | }
106 |  |  |  |  |
107 |  |  |  |  | sub original_name {
108 |  |  |  |  | my $self = shift;
109 |  |  |  |  |
110 |  |  |  |  | $self->original_method
111 |  |  |  |  | ? $self->original_method->original_name
112 |  |  |  |  | : $self->name;
113 |  |  |  |  | }
114 |  |  |  |  |
115 |  |  |  |  | sub original_fully_qualified_name {
116 |  |  |  |  | my $self = shift;
117 |  |  |  |  |
118 |  |  |  |  | $self->original_method
119 |  |  |  |  | ? $self->original_method->original_fully_qualified_name
120 |  |  |  |  | : $self->fully_qualified_name;
121 |  |  |  |  | }
122 |  |  |  |  |
123 |  |  |  |  | sub execute {
124 |  |  |  |  | my $self = shift;
125 |  |  |  |  | $self->body->(@_);
126 |  |  |  |  | }
127 |  |  |  |  |
128 |  |  |  |  | # We used to go through use Class::MOP::Class->clone_instance to do this, but
129 |  |  |  |  | # this was awfully slow. This method may be called a number of times when
130 |  |  |  |  | # classes are loaded (especially during Moose role application), so it is
131 |  |  |  |  | # worth optimizing. - DR
132 |  |  |  |  | # spent 645µs (531+115) within Class::MOP::Method::clone which was called 35 times, avg 18µs/call: # 25 times (348µs+83µs) by Class::MOP::Mixin::HasMethods::add_method at line 64 of Class/MOP/Mixin/HasMethods.pm, avg 17µs/call # 10 times (183µs+32µs) by Class::MOP::MiniTrait::apply at line 29 of Class/MOP/MiniTrait.pm, avg 21µs/call sub clone {
133 | 35 | 13µs |  |  | my $self = shift;
134 |  |  |  |  |
135 | 35 | 316µs | 35 | 29µs | my $clone = bless { %{$self}, @_ }, blessed($self); # spent 29µs making 35 calls to Scalar::Util::blessed, avg 823ns/call
136 | 35 | 110µs | 35 | 28µs | weaken($clone->{associated_metaclass}) if $clone->{associated_metaclass}; # spent 28µs making 35 calls to Scalar::Util::weaken, avg 789ns/call
137 |  |  |  |  |
138 | 35 | 61µs | 35 | 58µs | $clone->_set_original_method($self); # spent 58µs making 35 calls to Class::MOP::Method::_set_original_method, avg 2µs/call
139 |  |  |  |  |
140 | 35 | 83µs |  |  | return $clone;
141 |  |  |  |  | }
142 |  |  |  |  |
143 | 1 | 2µs |  |  | 1;
144 |  |  |  |  |
145 |  |  |  |  | # ABSTRACT: Method Meta Object
146 |  |  |  |  |
- - |  |  |  |  |
149 |  |  |  |  | =pod
150 |  |  |  |  |
151 |  |  |  |  | =head1 NAME
152 |  |  |  |  |
153 |  |  |  |  | Class::MOP::Method - Method Meta Object
154 |  |  |  |  |
155 |  |  |  |  | =head1 VERSION
156 |  |  |  |  |
157 |  |  |  |  | version 2.0602
158 |  |  |  |  |
159 |  |  |  |  | =head1 DESCRIPTION
160 |  |  |  |  |
161 |  |  |  |  | The Method Protocol is very small, since methods in Perl 5 are just
162 |  |  |  |  | subroutines in a specific package. We provide a very basic
163 |  |  |  |  | introspection interface.
164 |  |  |  |  |
165 |  |  |  |  | =head1 METHODS
166 |  |  |  |  |
167 |  |  |  |  | =over 4
168 |  |  |  |  |
169 |  |  |  |  | =item B<< Class::MOP::Method->wrap($code, %options) >>
170 |  |  |  |  |
171 |  |  |  |  | This is the constructor. It accepts a method body in the form of
172 |  |  |  |  | either a code reference or a L<Class::MOP::Method> instance, followed
173 |  |  |  |  | by a hash of options.
174 |  |  |  |  |
175 |  |  |  |  | The options are:
176 |  |  |  |  |
177 |  |  |  |  | =over 8
178 |  |  |  |  |
179 |  |  |  |  | =item * name
180 |  |  |  |  |
181 |  |  |  |  | The method name (without a package name). This is required if C<$code>
182 |  |  |  |  | is a coderef.
183 |  |  |  |  |
184 |  |  |  |  | =item * package_name
185 |  |  |  |  |
186 |  |  |  |  | The package name for the method. This is required if C<$code> is a
187 |  |  |  |  | coderef.
188 |  |  |  |  |
189 |  |  |  |  | =item * associated_metaclass
190 |  |  |  |  |
191 |  |  |  |  | An optional L<Class::MOP::Class> object. This is the metaclass for the
192 |  |  |  |  | method's class.
193 |  |  |  |  |
194 |  |  |  |  | =back
195 |  |  |  |  |
196 |  |  |  |  | =item B<< $metamethod->clone(%params) >>
197 |  |  |  |  |
198 |  |  |  |  | This makes a shallow clone of the method object. In particular,
199 |  |  |  |  | subroutine reference itself is shared between all clones of a given
200 |  |  |  |  | method.
201 |  |  |  |  |
202 |  |  |  |  | When a method is cloned, the original method object will be available
203 |  |  |  |  | by calling C<original_method> on the clone.
204 |  |  |  |  |
205 |  |  |  |  | =item B<< $metamethod->body >>
206 |  |  |  |  |
207 |  |  |  |  | This returns a reference to the method's subroutine.
208 |  |  |  |  |
209 |  |  |  |  | =item B<< $metamethod->name >>
210 |  |  |  |  |
211 |  |  |  |  | This returns the method's name
212 |  |  |  |  |
213 |  |  |  |  | =item B<< $metamethod->package_name >>
214 |  |  |  |  |
215 |  |  |  |  | This returns the method's package name.
216 |  |  |  |  |
217 |  |  |  |  | =item B<< $metamethod->fully_qualified_name >>
218 |  |  |  |  |
219 |  |  |  |  | This returns the method's fully qualified name (package name and
220 |  |  |  |  | method name).
221 |  |  |  |  |
222 |  |  |  |  | =item B<< $metamethod->associated_metaclass >>
223 |  |  |  |  |
224 |  |  |  |  | This returns the L<Class::MOP::Class> object for the method, if one
225 |  |  |  |  | exists.
226 |  |  |  |  |
227 |  |  |  |  | =item B<< $metamethod->original_method >>
228 |  |  |  |  |
229 |  |  |  |  | If this method object was created as a clone of some other method
230 |  |  |  |  | object, this returns the object that was cloned.
231 |  |  |  |  |
232 |  |  |  |  | =item B<< $metamethod->original_name >>
233 |  |  |  |  |
234 |  |  |  |  | This returns the method's original name, wherever it was first
235 |  |  |  |  | defined.
236 |  |  |  |  |
237 |  |  |  |  | If this method is a clone of a clone (of a clone, etc.), this method
238 |  |  |  |  | returns the name from the I<first> method in the chain of clones.
239 |  |  |  |  |
240 |  |  |  |  | =item B<< $metamethod->original_package_name >>
241 |  |  |  |  |
242 |  |  |  |  | This returns the method's original package name, wherever it was first
243 |  |  |  |  | defined.
244 |  |  |  |  |
245 |  |  |  |  | If this method is a clone of a clone (of a clone, etc.), this method
246 |  |  |  |  | returns the package name from the I<first> method in the chain of
247 |  |  |  |  | clones.
248 |  |  |  |  |
249 |  |  |  |  | =item B<< $metamethod->original_fully_qualified_name >>
250 |  |  |  |  |
251 |  |  |  |  | This returns the method's original fully qualified name, wherever it
252 |  |  |  |  | was first defined.
253 |  |  |  |  |
254 |  |  |  |  | If this method is a clone of a clone (of a clone, etc.), this method
255 |  |  |  |  | returns the fully qualified name from the I<first> method in the chain
256 |  |  |  |  | of clones.
257 |  |  |  |  |
258 |  |  |  |  | =item B<< $metamethod->is_stub >>
259 |  |  |  |  |
260 |  |  |  |  | Returns true if the method is just a stub:
261 |  |  |  |  |
262 |  |  |  |  | sub foo;
263 |  |  |  |  |
264 |  |  |  |  | =item B<< $metamethod->attach_to_class($metaclass) >>
265 |  |  |  |  |
266 |  |  |  |  | Given a L<Class::MOP::Class> object, this method sets the associated
267 |  |  |  |  | metaclass for the method. This will overwrite any existing associated
268 |  |  |  |  | metaclass.
269 |  |  |  |  |
270 |  |  |  |  | =item B<< $metamethod->detach_from_class >>
271 |  |  |  |  |
272 |  |  |  |  | Removes any associated metaclass object for the method.
273 |  |  |  |  |
274 |  |  |  |  | =item B<< $metamethod->execute(...) >>
275 |  |  |  |  |
276 |  |  |  |  | This executes the method. Any arguments provided will be passed on to
277 |  |  |  |  | the method itself.
278 |  |  |  |  |
279 |  |  |  |  | =item B<< Class::MOP::Method->meta >>
280 |  |  |  |  |
281 |  |  |  |  | This will return a L<Class::MOP::Class> instance for this class.
282 |  |  |  |  |
283 |  |  |  |  | It should also be noted that L<Class::MOP> will actually bootstrap
284 |  |  |  |  | this module by installing a number of attribute meta-objects into its
285 |  |  |  |  | metaclass.
286 |  |  |  |  |
287 |  |  |  |  | =back
288 |  |  |  |  |
289 |  |  |  |  | =head1 AUTHOR
290 |  |  |  |  |
291 |  |  |  |  | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
292 |  |  |  |  |
293 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
294 |  |  |  |  |
295 |  |  |  |  | This software is copyright (c) 2012 by Infinity Interactive, Inc..
296 |  |  |  |  |
297 |  |  |  |  | This is free software; you can redistribute it and/or modify it under
298 |  |  |  |  | the same terms as the Perl 5 programming language system itself.
299 |  |  |  |  |
300 |  |  |  |  | =cut
301 |  |  |  |  |
302 |  |  |  |  |
303 |  |  |  |  | __END__
|  |  |  |  | # spent 1µs within Class::MOP::Method::is_stub which was called: # once (1µs+0s) by Moose::Meta::Attribute::_process_accessors at line 1053 of Moose/Meta/Attribute.pm sub Class::MOP::Method::is_stub; # xsub