File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Mixin/HasMethods.pm |
Statements Executed | 9762 |
Statement Execution Time | 37.5ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 18.4ms | 22.5ms | BEGIN@12 | Class::MOP::Mixin::HasMethods::
351 | 22 | 7 | 8.49ms | 15.9ms | add_method | Class::MOP::Mixin::HasMethods::
477 | 6 | 3 | 5.71ms | 13.8ms | get_method | Class::MOP::Mixin::HasMethods::
828 | 2 | 1 | 924µs | 924µs | _method_map | Class::MOP::Mixin::HasMethods::
351 | 1 | 2 | 508µs | 508µs | CORE:match (opcode) | Class::MOP::Mixin::HasMethods::
52 | 1 | 1 | 500µs | 2.02ms | wrap_method_body | Class::MOP::Mixin::HasMethods::
100 | 5 | 3 | 372µs | 3.82ms | has_method | Class::MOP::Mixin::HasMethods::
58 | 1 | 1 | 332µs | 414µs | _code_is_mine | Class::MOP::Mixin::HasMethods::
3 | 1 | 1 | 164µs | 2.71ms | get_method_list | Class::MOP::Mixin::HasMethods::
52 | 1 | 1 | 70µs | 70µs | method_metaclass | Class::MOP::Mixin::HasMethods::
36 | 1 | 1 | 47µs | 47µs | wrapped_method_metaclass | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 15µs | 18µs | BEGIN@3 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 13µs | 23µs | BEGIN@4 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 7µs | 48µs | BEGIN@14 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 7µs | 34µs | BEGIN@10 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 7µs | 37µs | BEGIN@11 | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | remove_method | Class::MOP::Mixin::HasMethods::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::MOP::Mixin::HasMethods; | ||||
2 | |||||
3 | 3 | 21µs | 2 | 22µs | # spent 18µs (15+4) within Class::MOP::Mixin::HasMethods::BEGIN@3 which was called
# once (15µs+4µs) by Class::MOP::BEGIN@17 at line 3 # spent 18µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@3
# spent 4µs making 1 call to strict::import |
4 | 3 | 46µs | 2 | 33µs | # spent 23µs (13+10) within Class::MOP::Mixin::HasMethods::BEGIN@4 which was called
# once (13µs+10µs) by Class::MOP::BEGIN@17 at line 4 # spent 23µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@4
# spent 10µs making 1 call to warnings::import |
5 | |||||
6 | 1 | 900ns | our $VERSION = '0.98'; | ||
7 | 1 | 15µs | $VERSION = eval $VERSION; | ||
8 | 1 | 400ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
9 | |||||
10 | 3 | 24µs | 2 | 61µs | # spent 34µs (7+27) within Class::MOP::Mixin::HasMethods::BEGIN@10 which was called
# once (7µs+27µs) by Class::MOP::BEGIN@17 at line 10 # spent 34µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@10
# spent 27µs making 1 call to Exporter::import |
11 | 3 | 25µs | 2 | 67µs | # spent 37µs (7+30) within Class::MOP::Mixin::HasMethods::BEGIN@11 which was called
# once (7µs+30µs) by Class::MOP::BEGIN@17 at line 11 # spent 37µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@11
# spent 30µs making 1 call to Exporter::import |
12 | 3 | 18.3ms | 2 | 22.6ms | # spent 22.5ms (18.4+4.06) within Class::MOP::Mixin::HasMethods::BEGIN@12 which was called
# once (18.4ms+4.06ms) by Class::MOP::BEGIN@17 at line 12 # spent 22.5ms making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@12
# spent 49µs making 1 call to Exporter::import |
13 | |||||
14 | 3 | 509µs | 2 | 89µs | # spent 48µs (7+41) within Class::MOP::Mixin::HasMethods::BEGIN@14 which was called
# once (7µs+41µs) by Class::MOP::BEGIN@17 at line 14 # spent 48µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@14
# spent 41µs making 1 call to base::import |
15 | |||||
16 | 52 | 124µs | # spent 70µs within Class::MOP::Mixin::HasMethods::method_metaclass which was called 52 times, avg 1µs/call:
# 52 times (70µs+0s) by Class::MOP::Mixin::HasMethods::wrap_method_body at line 31, avg 1µs/call | ||
17 | 36 | 85µs | # spent 47µs within Class::MOP::Mixin::HasMethods::wrapped_method_metaclass which was called 36 times, avg 1µs/call:
# 36 times (47µs+0s) by Class::MOP::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Class.pm:678] at line 651 of Class/MOP/Class.pm, avg 1µs/call | ||
18 | |||||
19 | # This doesn't always get initialized in a constructor because there is a | ||||
20 | # weird object construction path for subclasses of Class::MOP::Class. At one | ||||
21 | # point, this always got initialized by calling into the XS code first, but | ||||
22 | # that is no longer guaranteed to happen. | ||||
23 | 828 | 1.54ms | sub _method_map { $_[0]->{'methods'} ||= {} } | ||
24 | |||||
25 | # spent 2.02ms (500µs+1.52) within Class::MOP::Mixin::HasMethods::wrap_method_body which was called 52 times, avg 39µs/call:
# 52 times (500µs+1.52ms) by Class::MOP::Mixin::HasMethods::get_method at line 123, avg 39µs/call | ||||
26 | 156 | 439µs | my ( $self, %args ) = @_; | ||
27 | |||||
28 | ( 'CODE' eq ref $args{body} ) | ||||
29 | || confess "Your code block must be a CODE reference"; | ||||
30 | |||||
31 | $self->method_metaclass->wrap( # spent 1.42ms making 52 calls to Class::MOP::Method::wrap, avg 27µs/call
# spent 70µs making 52 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 1µs/call
# spent 25µs making 52 calls to Class::MOP::Package::name, avg 487ns/call | ||||
32 | package_name => $self->name, | ||||
33 | %args, | ||||
34 | ); | ||||
35 | } | ||||
36 | |||||
37 | # spent 15.9ms (8.49+7.39) within Class::MOP::Mixin::HasMethods::add_method which was called 351 times, avg 45µs/call:
# 154 times (3.83ms+3.03ms) by Class::MOP::Attribute::install_accessors at line 358 of Class/MOP/Attribute.pm, avg 45µs/call
# 36 times (884µs+660µs) by Class::MOP::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Class.pm:678] at line 676 of Class/MOP/Class.pm, avg 43µs/call
# 36 times (840µs+663µs) by Class::MOP::Attribute::install_accessors at line 366 of Class/MOP/Attribute.pm, avg 42µs/call
# 32 times (813µs+616µs) by Class::MOP::Class::_inline_constructor at line 1064 of Class/MOP/Class.pm, avg 45µs/call
# 31 times (771µs+645µs) by Class::MOP::Attribute::install_accessors at line 354 of Class/MOP/Attribute.pm, avg 46µs/call
# 20 times (413µs+306µs) by metaclass::import at line 51 of metaclass.pm, avg 36µs/call
# 8 times (181µs+145µs) by Class::MOP::Attribute::install_accessors at line 362 of Class/MOP/Attribute.pm, avg 41µs/call
# 7 times (146µs+91µs) by Moose::BEGIN@37 at line 26 of Moose/Meta/Attribute/Native.pm, avg 34µs/call
# 6 times (155µs+916µs) by Class::MOP::Class::_immutable_metaclass at line 974 of Class/MOP/Class.pm, avg 179µs/call
# 3 times (52µs+32µs) by Moose::BEGIN@26 at line 265 of Moose/Meta/Role.pm, avg 28µs/call
# 3 times (49µs+33µs) by Moose::BEGIN@26 at line 292 of Moose/Meta/Role.pm, avg 27µs/call
# 3 times (48µs+29µs) by Moose::BEGIN@26 at line 273 of Moose/Meta/Role.pm, avg 26µs/call
# 2 times (56µs+36µs) by Moose::BEGIN@26 at line 110 of Moose/Meta/Role.pm, avg 46µs/call
# 2 times (49µs+28µs) by Class::MOP::Class::create at line 305 of Class/MOP/Class.pm, avg 39µs/call
# once (24µs+30µs) by Moose::Exporter::BEGIN@11 at line 501 of Class/MOP.pm
# once (29µs+22µs) by Class::MOP::Class::_inline_destructor at line 1097 of Class/MOP/Class.pm
# once (31µs+20µs) by Moose::BEGIN@26 at line 115 of Moose/Meta/Role.pm
# once (30µs+20µs) by Moose::BEGIN@26 at line 90 of Moose/Meta/Role.pm
# once (29µs+20µs) by Moose::BEGIN@26 at line 100 of Moose/Meta/Role.pm
# once (27µs+21µs) by Moose::BEGIN@26 at line 95 of Moose/Meta/Role.pm
# once (17µs+16µs) by Moose::Exporter::BEGIN@11 at line 541 of Class/MOP.pm
# once (18µs+12µs) by Moose::init_meta at line 214 of Moose.pm | ||||
38 | 2808 | 5.76ms | my ( $self, $method_name, $method ) = @_; | ||
39 | ( defined $method_name && length $method_name ) | ||||
40 | || confess "You must define a method name"; | ||||
41 | |||||
42 | my $body; | ||||
43 | 959 | 2.29ms | 351 | 246µs | if ( blessed($method) ) { # spent 246µs making 351 calls to Scalar::Util::blessed, avg 701ns/call |
44 | $body = $method->body; # spent 184µs making 304 calls to Class::MOP::Method::body, avg 605ns/call | ||||
45 | if ( $method->package_name ne $self->name ) { # spent 817µs making 6 calls to Class::MOP::Method::clone, avg 136µs/call
# spent 142µs making 310 calls to Class::MOP::Package::name, avg 459ns/call
# spent 140µs making 304 calls to Class::MOP::Method::package_name, avg 461ns/call
# spent 5µs making 6 calls to UNIVERSAL::can, avg 800ns/call | ||||
46 | $method = $method->clone( | ||||
47 | package_name => $self->name, | ||||
48 | name => $method_name, | ||||
49 | ) if $method->can('clone'); | ||||
50 | } | ||||
51 | |||||
52 | $method->attach_to_class($self); # spent 1.27ms making 304 calls to Class::MOP::Method::attach_to_class, avg 4µs/call | ||||
53 | } | ||||
54 | else { | ||||
55 | # If a raw code reference is supplied, its method object is not created. | ||||
56 | # The method object won't be created until required. | ||||
57 | $body = $method; | ||||
58 | } | ||||
59 | |||||
60 | $self->_method_map->{$method_name} = $method; # spent 463µs making 351 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 1µs/call | ||||
61 | |||||
62 | my ( $current_package, $current_name ) = Class::MOP::get_code_info($body); # spent 413µs making 351 calls to Class::MOP::get_code_info, avg 1µs/call | ||||
63 | |||||
64 | 576 | 2.15ms | 351 | 508µs | if ( !defined $current_name || $current_name =~ /^__ANON__/ ) { # spent 508µs making 351 calls to Class::MOP::Mixin::HasMethods::CORE:match, avg 1µs/call |
65 | my $full_method_name = ( $self->name . '::' . $method_name ); # spent 188µs making 288 calls to Class::MOP::Package::name, avg 653ns/call | ||||
66 | subname( $full_method_name => $body ); # spent 819µs making 288 calls to Sub::Name::subname, avg 3µs/call | ||||
67 | } | ||||
68 | |||||
69 | $self->add_package_symbol( | ||||
70 | { sigil => '&', type => 'CODE', name => $method_name }, # spent 2.20ms making 351 calls to Class::MOP::Package::add_package_symbol, avg 6µs/call | ||||
71 | $body, | ||||
72 | ); | ||||
73 | } | ||||
74 | |||||
75 | # spent 414µs (332+82) within Class::MOP::Mixin::HasMethods::_code_is_mine which was called 58 times, avg 7µs/call:
# 58 times (332µs+82µs) by Class::MOP::Mixin::HasMethods::get_method at line 117, avg 7µs/call | ||||
76 | 174 | 431µs | my ( $self, $code ) = @_; | ||
77 | |||||
78 | my ( $code_package, $code_name ) = Class::MOP::get_code_info($code); # spent 52µs making 58 calls to Class::MOP::get_code_info, avg 893ns/call | ||||
79 | |||||
80 | return $code_package && $code_package eq $self->name # spent 30µs making 58 calls to Class::MOP::Package::name, avg 519ns/call | ||||
81 | || ( $code_package eq 'constant' && $code_name eq '__ANON__' ); | ||||
82 | } | ||||
83 | |||||
84 | # spent 3.82ms (372µs+3.45) within Class::MOP::Mixin::HasMethods::has_method which was called 100 times, avg 38µs/call:
# 62 times (214µs+2.33ms) by Class::MOP::Mixin::HasMethods::get_method_list at line 151, avg 41µs/call
# 32 times (131µs+968µs) by Class::MOP::Class::_inline_constructor at line 1041 of Class/MOP/Class.pm, avg 34µs/call
# 4 times (13µs+104µs) by Class::MOP::Class::find_all_methods_by_name at line 763 of Class/MOP/Class.pm, avg 29µs/call
# once (10µs+24µs) by Moose::init_meta at line 214 of Moose.pm
# once (4µs+28µs) by Class::MOP::Class::_inline_destructor at line 1076 of Class/MOP/Class.pm | ||||
85 | 300 | 331µs | my ( $self, $method_name ) = @_; | ||
86 | |||||
87 | ( defined $method_name && length $method_name ) | ||||
88 | || confess "You must define a method name"; | ||||
89 | |||||
90 | return defined( $self->get_method($method_name) ); # spent 3.45ms making 100 calls to Class::MOP::Mixin::HasMethods::get_method, avg 35µs/call | ||||
91 | } | ||||
92 | |||||
93 | # spent 13.8ms (5.71+8.06) within Class::MOP::Mixin::HasMethods::get_method which was called 477 times, avg 29µs/call:
# 179 times (2.07ms+3.38ms) by Class::MOP::Class::find_method_by_name at line 729 of Class/MOP/Class.pm, avg 30µs/call
# 114 times (1.45ms+1.63ms) by Class::MOP::Class::find_next_method_by_name at line 779 of Class/MOP/Class.pm, avg 27µs/call
# 100 times (1.23ms+2.22ms) by Class::MOP::Mixin::HasMethods::has_method at line 90, avg 35µs/call
# 42 times (473µs+369µs) by Class::MOP::Class::get_all_methods at line 743 of Class/MOP/Class.pm, avg 20µs/call
# 36 times (377µs+328µs) by Class::MOP::Class::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Class.pm:678] at line 653 of Class/MOP/Class.pm, avg 20µs/call
# 6 times (105µs+131µs) by Moose::Meta::Attribute::_process_accessors at line 569 of Moose/Meta/Attribute.pm, avg 39µs/call | ||||
94 | 3783 | 5.31ms | my ( $self, $method_name ) = @_; | ||
95 | |||||
96 | ( defined $method_name && length $method_name ) | ||||
97 | || confess "You must define a method name"; | ||||
98 | |||||
99 | my $method_map = $self->_method_map; # spent 461µs making 477 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 966ns/call | ||||
100 | my $map_entry = $method_map->{$method_name}; | ||||
101 | my $code = $self->get_package_symbol( # spent 4.61ms making 477 calls to Class::MOP::Package::get_package_symbol, avg 10µs/call | ||||
102 | { | ||||
103 | name => $method_name, | ||||
104 | sigil => '&', | ||||
105 | type => 'CODE', | ||||
106 | } | ||||
107 | ); | ||||
108 | |||||
109 | # This seems to happen in some weird cases where methods modifiers are | ||||
110 | # added via roles or some other such bizareness. Honestly, I don't totally | ||||
111 | # understand this, but returning the entry works, and keeps various MX | ||||
112 | # modules from blowing up. - DR | ||||
113 | return $map_entry if blessed $map_entry && !$code; # spent 313µs making 477 calls to Scalar::Util::blessed, avg 656ns/call | ||||
114 | |||||
115 | return $map_entry if blessed $map_entry && $map_entry->body == $code; # spent 163µs making 477 calls to Scalar::Util::blessed, avg 342ns/call
# spent 74µs making 137 calls to Class::MOP::Method::body, avg 543ns/call | ||||
116 | |||||
117 | unless ($map_entry) { # spent 414µs making 58 calls to Class::MOP::Mixin::HasMethods::_code_is_mine, avg 7µs/call | ||||
118 | return unless $code && $self->_code_is_mine($code); | ||||
119 | } | ||||
120 | |||||
121 | $code ||= $map_entry; | ||||
122 | |||||
123 | return $method_map->{$method_name} = $self->wrap_method_body( # spent 2.02ms making 52 calls to Class::MOP::Mixin::HasMethods::wrap_method_body, avg 39µs/call | ||||
124 | body => $code, | ||||
125 | name => $method_name, | ||||
126 | associated_metaclass => $self, | ||||
127 | ); | ||||
128 | } | ||||
129 | |||||
130 | sub remove_method { | ||||
131 | my ( $self, $method_name ) = @_; | ||||
132 | ( defined $method_name && length $method_name ) | ||||
133 | || confess "You must define a method name"; | ||||
134 | |||||
135 | my $removed_method = delete $self->_full_method_map->{$method_name}; | ||||
136 | |||||
137 | $self->remove_package_symbol( | ||||
138 | { sigil => '&', type => 'CODE', name => $method_name } ); | ||||
139 | |||||
140 | $removed_method->detach_from_class | ||||
141 | if $removed_method && blessed $removed_method; | ||||
142 | |||||
143 | # still valid, since we just removed the method from the map | ||||
144 | $self->update_package_cache_flag; | ||||
145 | |||||
146 | return $removed_method; | ||||
147 | } | ||||
148 | |||||
149 | # spent 2.71ms (164µs+2.55) within Class::MOP::Mixin::HasMethods::get_method_list which was called 3 times, avg 904µs/call:
# 3 times (164µs+2.55ms) by Class::MOP::Class::get_all_methods at line 743 of Class/MOP/Class.pm, avg 904µs/call | ||||
150 | 6 | 38µs | my $self = shift; | ||
151 | 62 | 64µs | 65 | 2.55ms | return grep { $self->has_method($_) } keys %{ $self->namespace }; # spent 2.54ms making 62 calls to Class::MOP::Mixin::HasMethods::has_method, avg 41µs/call
# spent 7µs making 3 calls to Class::MOP::Package::namespace, avg 2µs/call |
152 | } | ||||
153 | |||||
154 | 1 | 4µs | 1; | ||
155 | |||||
156 | __END__ | ||||
157 | |||||
158 | =pod | ||||
159 | |||||
160 | =head1 NAME | ||||
161 | |||||
162 | Class::MOP::Mixin::HasMethods - Methods for metaclasses which have methods | ||||
163 | |||||
164 | =head1 DESCRIPTION | ||||
165 | |||||
166 | This class implements methods for metaclasses which have methods | ||||
167 | (L<Class::MOP::Package> and L<Moose::Meta::Role>). See L<Class::MOP::Package> | ||||
168 | for API details. | ||||
169 | |||||
170 | =head1 AUTHORS | ||||
171 | |||||
172 | Dave Rolsky E<lt>autarch@urth.orgE<gt> | ||||
173 | |||||
174 | =head1 COPYRIGHT AND LICENSE | ||||
175 | |||||
176 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
177 | |||||
178 | L<http://www.iinteractive.com> | ||||
179 | |||||
180 | This library is free software; you can redistribute it and/or modify | ||||
181 | it under the same terms as Perl itself. | ||||
182 | |||||
183 | =cut | ||||
# spent 508µs within Class::MOP::Mixin::HasMethods::CORE:match which was called 351 times, avg 1µs/call:
# 351 times (508µs+0s) by Class::MOP::Mixin::HasMethods::add_method at line 64 of Class/MOP/Mixin/HasMethods.pm, avg 1µs/call |