Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Class/MOP/Mixin/HasMethods.pm |
Statements | Executed 11568 statements in 42.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
386 | 19 | 7 | 23.3ms | 46.8ms | add_method | Class::MOP::Mixin::HasMethods::
65 | 1 | 1 | 5.35ms | 7.28ms | wrap_method_body | Class::MOP::Mixin::HasMethods::
616 | 2 | 1 | 4.15ms | 19.5ms | _get_maybe_raw_method | Class::MOP::Mixin::HasMethods::
570 | 6 | 4 | 3.15ms | 29.4ms | get_method | Class::MOP::Mixin::HasMethods::
386 | 1 | 1 | 2.17ms | 3.00ms | update_package_cache_flag | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 699µs | 3.18ms | BEGIN@12 | Class::MOP::Mixin::HasMethods::
386 | 1 | 1 | 683µs | 683µs | CORE:match (opcode) | Class::MOP::Mixin::HasMethods::
105 | 1 | 1 | 677µs | 850µs | _code_is_mine | Class::MOP::Mixin::HasMethods::
25 | 5 | 4 | 488µs | 12.3ms | _add_meta_method | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 482µs | 659µs | BEGIN@13 | Class::MOP::Mixin::HasMethods::
17 | 1 | 1 | 263µs | 7.54ms | _full_method_map | Class::MOP::Mixin::HasMethods::
46 | 5 | 3 | 214µs | 1.18ms | has_method | Class::MOP::Mixin::HasMethods::
17 | 1 | 1 | 80µs | 7.62ms | _get_local_methods | Class::MOP::Mixin::HasMethods::
25 | 2 | 1 | 33µs | 33µs | _meta_method_class | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 12µs | 12µs | BEGIN@2 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 12µs | 49µs | BEGIN@15 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 10µs | 14µs | BEGIN@10 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 9µs | 36µs | BEGIN@16 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 9µs | 44µs | BEGIN@17 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 9µs | 89µs | BEGIN@21 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 8µs | 25µs | BEGIN@9 | Class::MOP::Mixin::HasMethods::
1 | 1 | 1 | 4µs | 4µs | BEGIN@19 | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | _get_overloaded_operator_body | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | _overload_map | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | _restore_metamethods_from | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | _wrap_overload | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | add_overloaded_operator | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | get_all_overloaded_operators | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | get_method_list | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | get_overload_list | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | get_overloaded_operator | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | has_overloaded_operator | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | is_overloaded | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | overload_operators | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | remove_method | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | remove_overloaded_operator | Class::MOP::Mixin::HasMethods::
0 | 0 | 0 | 0s | 0s | reset_package_cache_flag | Class::MOP::Mixin::HasMethods::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::MOP::Mixin::HasMethods; | ||||
2 | # spent 12µs within Class::MOP::Mixin::HasMethods::BEGIN@2 which was called:
# once (12µs+0s) by Class::MOP::BEGIN@25 at line 4 | ||||
3 | 1 | 7µs | $Class::MOP::Mixin::HasMethods::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 46µs | 1 | 12µs | } # spent 12µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Class::MOP::Mixin::HasMethods::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 32µs | 2 | 41µs | # spent 25µs (8+16) within Class::MOP::Mixin::HasMethods::BEGIN@9 which was called:
# once (8µs+16µs) by Class::MOP::BEGIN@25 at line 9 # spent 25µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@9
# spent 16µs making 1 call to strict::import |
10 | 2 | 30µs | 2 | 19µs | # spent 14µs (10+5) within Class::MOP::Mixin::HasMethods::BEGIN@10 which was called:
# once (10µs+5µs) by Class::MOP::BEGIN@25 at line 10 # spent 14µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@10
# spent 5µs making 1 call to warnings::import |
11 | |||||
12 | 2 | 145µs | 1 | 3.18ms | # spent 3.18ms (699µs+2.48) within Class::MOP::Mixin::HasMethods::BEGIN@12 which was called:
# once (699µs+2.48ms) by Class::MOP::BEGIN@25 at line 12 # spent 3.18ms making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@12 |
13 | 2 | 130µs | 1 | 659µs | # spent 659µs (482+177) within Class::MOP::Mixin::HasMethods::BEGIN@13 which was called:
# once (482µs+177µs) by Class::MOP::BEGIN@25 at line 13 # spent 659µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@13 |
14 | |||||
15 | 2 | 36µs | 2 | 87µs | # spent 49µs (12+38) within Class::MOP::Mixin::HasMethods::BEGIN@15 which was called:
# once (12µs+38µs) by Class::MOP::BEGIN@25 at line 15 # spent 49µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@15
# spent 38µs making 1 call to Exporter::import |
16 | 2 | 33µs | 2 | 64µs | # spent 36µs (9+27) within Class::MOP::Mixin::HasMethods::BEGIN@16 which was called:
# once (9µs+27µs) by Class::MOP::BEGIN@25 at line 16 # spent 36µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@16
# spent 27µs making 1 call to Exporter::import |
17 | 2 | 31µs | 2 | 79µs | # spent 44µs (9+35) within Class::MOP::Mixin::HasMethods::BEGIN@17 which was called:
# once (9µs+35µs) by Class::MOP::BEGIN@25 at line 17 # spent 44µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@17
# spent 35µs making 1 call to Exporter::import |
18 | |||||
19 | 2 | 30µs | 1 | 4µs | # spent 4µs within Class::MOP::Mixin::HasMethods::BEGIN@19 which was called:
# once (4µs+0s) by Class::MOP::BEGIN@25 at line 19 # spent 4µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@19 |
20 | |||||
21 | 2 | 1.76ms | 2 | 170µs | # spent 89µs (9+81) within Class::MOP::Mixin::HasMethods::BEGIN@21 which was called:
# once (9µs+81µs) by Class::MOP::BEGIN@25 at line 21 # spent 89µs making 1 call to Class::MOP::Mixin::HasMethods::BEGIN@21
# spent 81µs making 1 call to base::import |
22 | |||||
23 | 25 | 56µs | # spent 33µs within Class::MOP::Mixin::HasMethods::_meta_method_class which was called 25 times, avg 1µs/call:
# 23 times (30µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 33, avg 1µs/call
# 2 times (3µs+0s) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 31, avg 2µs/call | ||
24 | |||||
25 | # spent 12.3ms (488µs+11.8) within Class::MOP::Mixin::HasMethods::_add_meta_method which was called 25 times, avg 492µs/call:
# 20 times (332µs+8.40ms) by metaclass::import at line 49 of metaclass.pm, avg 436µs/call
# 2 times (53µs+897µs) by Class::MOP::Class::create at line 448 of Class/MOP/Class.pm, avg 475µs/call
# once (46µs+1.25ms) by Moose::Exporter::BEGIN@13 at line 660 of Class/MOP.pm
# once (21µs+649µs) by Moose::init_meta at line 217 of Moose.pm
# once (37µs+613µs) by Moose::Exporter::BEGIN@13 at line 666 of Class/MOP.pm | ||||
26 | 25 | 6µs | my $self = shift; | ||
27 | 25 | 10µs | my ($name) = @_; | ||
28 | 25 | 125µs | 50 | 2.57ms | my $existing_method = $self->can('find_method_by_name') # spent 2.54ms making 25 calls to Class::MOP::Class::find_method_by_name, avg 102µs/call
# spent 28µs making 25 calls to UNIVERSAL::can, avg 1µs/call |
29 | ? $self->find_method_by_name($name) | ||||
30 | : $self->get_method($name); | ||||
31 | 25 | 26µs | 4 | 7µs | return if $existing_method # spent 3µs making 2 calls to Class::MOP::Mixin::HasMethods::_meta_method_class, avg 2µs/call
# spent 3µs making 2 calls to UNIVERSAL::isa, avg 2µs/call |
32 | && $existing_method->isa($self->_meta_method_class); | ||||
33 | 25 | 259µs | 100 | 9.23ms | $self->add_method( # spent 5.72ms making 23 calls to Class::MOP::Method::Meta::wrap, avg 249µs/call
# spent 1.96ms making 25 calls to Class::MOP::Mixin::HasMethods::add_method, avg 78µs/call
# spent 1.50ms making 2 calls to Moose::Meta::Method::Meta::wrap, avg 750µs/call
# spent 30µs making 23 calls to Class::MOP::Mixin::HasMethods::_meta_method_class, avg 1µs/call
# spent 15µs making 25 calls to Class::MOP::Package::name, avg 616ns/call
# spent 3µs making 2 calls to Moose::Meta::Class::_meta_method_class, avg 2µs/call |
34 | $name => $self->_meta_method_class->wrap( | ||||
35 | name => $name, | ||||
36 | package_name => $self->name, | ||||
37 | associated_metaclass => $self, | ||||
38 | ) | ||||
39 | ); | ||||
40 | } | ||||
41 | |||||
42 | # spent 7.28ms (5.35+1.94) within Class::MOP::Mixin::HasMethods::wrap_method_body which was called 65 times, avg 112µs/call:
# 65 times (5.35ms+1.94ms) by Class::MOP::Mixin::HasMethods::get_method at line 124, avg 112µs/call | ||||
43 | 65 | 96µs | my ( $self, %args ) = @_; | ||
44 | |||||
45 | 65 | 188µs | 65 | 39µs | ( 'CODE' eq reftype $args{body} ) # spent 39µs making 65 calls to Scalar::Util::reftype, avg 606ns/call |
46 | || confess "Your code block must be a CODE reference"; | ||||
47 | |||||
48 | 65 | 601µs | 195 | 1.90ms | $self->method_metaclass->wrap( # spent 1.82ms making 65 calls to Class::MOP::Method::wrap, avg 28µs/call
# spent 45µs making 65 calls to Class::MOP::Mixin::HasMethods::method_metaclass, avg 688ns/call
# spent 33µs making 65 calls to Class::MOP::Package::name, avg 506ns/call |
49 | package_name => $self->name, | ||||
50 | %args, | ||||
51 | ); | ||||
52 | } | ||||
53 | |||||
54 | # spent 46.8ms (23.3+23.5) within Class::MOP::Mixin::HasMethods::add_method which was called 386 times, avg 121µs/call:
# 152 times (4.91ms+12.4ms) by Class::MOP::Attribute::install_accessors at line 428 of Class/MOP/Attribute.pm, avg 114µs/call
# 46 times (1.41ms+2.35ms) by Class::MOP::Attribute::install_accessors at line 424 of Class/MOP/Attribute.pm, avg 82µs/call
# 44 times (7.49ms+2.06ms) by Class::MOP::Class::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Class/MOP/Class.pm:1072] at line 1070 of Class/MOP/Class.pm, avg 217µs/call
# 42 times (6.63ms+1.96ms) by Class::MOP::Attribute::install_accessors at line 436 of Class/MOP/Attribute.pm, avg 204µs/call
# 31 times (915µs+1.47ms) by Class::MOP::Class::_inline_constructor at line 1452 of Class/MOP/Class.pm, avg 77µs/call
# 25 times (778µs+1.18ms) by Class::MOP::Mixin::HasMethods::_add_meta_method at line 33, avg 78µs/call
# 14 times (406µs+796µs) by Class::MOP::MiniTrait::apply at line 29 of Class/MOP/MiniTrait.pm, avg 86µs/call
# 8 times (240µs+370µs) by Class::MOP::Attribute::install_accessors at line 432 of Class/MOP/Attribute.pm, avg 76µs/call
# 7 times (152µs+270µs) by Moose::BEGIN@46 at line 30 of Moose/Meta/Attribute/Native.pm, avg 60µs/call
# 3 times (63µs+105µs) by Moose::BEGIN@35 at line 318 of Moose/Meta/Role.pm, avg 56µs/call
# 3 times (59µs+95µs) by Moose::BEGIN@35 at line 326 of Moose/Meta/Role.pm, avg 51µs/call
# 3 times (59µs+94µs) by Moose::BEGIN@35 at line 345 of Moose/Meta/Role.pm, avg 51µs/call
# 2 times (40µs+64µs) by Moose::BEGIN@35 at line 119 of Moose/Meta/Role.pm, avg 52µs/call
# once (37µs+46µs) by Class::MOP::Class::_inline_destructor at line 1490 of Class/MOP/Class.pm
# once (23µs+45µs) by Moose::Exporter::BEGIN@13 at line 486 of Class/MOP.pm
# once (22µs+37µs) by Moose::BEGIN@35 at line 99 of Moose/Meta/Role.pm
# once (21µs+36µs) by Moose::BEGIN@35 at line 109 of Moose/Meta/Role.pm
# once (20µs+34µs) by Moose::BEGIN@35 at line 124 of Moose/Meta/Role.pm
# once (21µs+33µs) by Moose::BEGIN@35 at line 104 of Moose/Meta/Role.pm | ||||
55 | 386 | 161µs | my ( $self, $method_name, $method ) = @_; | ||
56 | 386 | 175µs | ( defined $method_name && length $method_name ) | ||
57 | || confess "You must define a method name"; | ||||
58 | |||||
59 | 386 | 6.56ms | 386 | 284µs | my $package_name = $self->name; # spent 284µs making 386 calls to Class::MOP::Package::name, avg 736ns/call |
60 | |||||
61 | 386 | 25µs | my $body; | ||
62 | 386 | 2.12ms | 749 | 665µs | if ( blessed($method) && $method->isa('Class::MOP::Method') ) { # spent 361µs making 386 calls to Scalar::Util::blessed, avg 936ns/call
# spent 304µs making 363 calls to UNIVERSAL::isa, avg 838ns/call |
63 | 363 | 895µs | 363 | 214µs | $body = $method->body; # spent 214µs making 363 calls to Class::MOP::Method::body, avg 591ns/call |
64 | 363 | 1.17ms | 377 | 431µs | if ( $method->package_name ne $package_name ) { # spent 226µs making 14 calls to Class::MOP::Method::clone, avg 16µs/call
# spent 205µs making 363 calls to Class::MOP::Method::package_name, avg 565ns/call |
65 | $method = $method->clone( | ||||
66 | package_name => $package_name, | ||||
67 | name => $method_name, | ||||
68 | ); | ||||
69 | } | ||||
70 | |||||
71 | 363 | 450µs | 363 | 1.79ms | $method->attach_to_class($self); # spent 1.79ms making 363 calls to Class::MOP::Method::attach_to_class, avg 5µs/call |
72 | } | ||||
73 | else { | ||||
74 | # If a raw code reference is supplied, its method object is not created. | ||||
75 | # The method object won't be created until required. | ||||
76 | 23 | 6µs | $body = $method; | ||
77 | } | ||||
78 | |||||
79 | 386 | 2.47ms | 409 | 1.42ms | $self->_method_map->{$method_name} = $method; # spent 1.40ms making 386 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 4µs/call
# spent 15µs making 23 calls to Class::MOP::Method::body, avg 643ns/call |
80 | |||||
81 | 386 | 1.43ms | 386 | 505µs | my ($current_package, $current_name) = Class::MOP::get_code_info($body); # spent 505µs making 386 calls to Class::MOP::get_code_info, avg 1µs/call |
82 | |||||
83 | 386 | 9.36ms | 702 | 1.68ms | subname($package_name . '::' . $method_name, $body) # spent 994µs making 316 calls to Sub::Name::subname, avg 3µs/call
# spent 683µs making 386 calls to Class::MOP::Mixin::HasMethods::CORE:match, avg 2µs/call |
84 | unless defined $current_name && $current_name !~ /^__ANON__/; | ||||
85 | |||||
86 | 386 | 804µs | 386 | 13.5ms | $self->add_package_symbol("&$method_name", $body); # spent 13.5ms making 386 calls to Class::MOP::Package::add_package_symbol, avg 35µs/call |
87 | |||||
88 | # we added the method to the method map too, so it's still valid | ||||
89 | 386 | 1.44ms | 386 | 3.00ms | $self->update_package_cache_flag; # spent 3.00ms making 386 calls to Class::MOP::Mixin::HasMethods::update_package_cache_flag, avg 8µs/call |
90 | } | ||||
91 | |||||
92 | # spent 850µs (677+173) within Class::MOP::Mixin::HasMethods::_code_is_mine which was called 105 times, avg 8µs/call:
# 105 times (677µs+173µs) by Class::MOP::Mixin::HasMethods::_get_maybe_raw_method at line 139, avg 8µs/call | ||||
93 | 105 | 26µs | my ( $self, $code ) = @_; | ||
94 | |||||
95 | 105 | 358µs | 105 | 107µs | my ( $code_package, $code_name ) = Class::MOP::get_code_info($code); # spent 107µs making 105 calls to Class::MOP::get_code_info, avg 1µs/call |
96 | |||||
97 | 105 | 535µs | 105 | 66µs | return ( $code_package && $code_package eq $self->name ) # spent 66µs making 105 calls to Class::MOP::Package::name, avg 629ns/call |
98 | || ( $code_package eq 'constant' && $code_name eq '__ANON__' ); | ||||
99 | } | ||||
100 | |||||
101 | # spent 1.18ms (214µs+964µs) within Class::MOP::Mixin::HasMethods::has_method which was called 46 times, avg 26µs/call:
# 31 times (131µs+726µs) by Class::MOP::Class::_inline_constructor at line 1424 of Class/MOP/Class.pm, avg 28µs/call
# 6 times (22µs+110µs) by Class::MOP::Class::find_all_methods_by_name at line 1155 of Class/MOP/Class.pm, avg 22µs/call
# 5 times (38µs+66µs) by Moose::Meta::Class::_inline_create_error at line 850 of Moose/Meta/Class.pm, avg 21µs/call
# 3 times (19µs+42µs) by Moose::Meta::Attribute::_process_accessors at line 1070 of Moose/Meta/Attribute.pm, avg 20µs/call
# once (5µs+20µs) by Class::MOP::Class::_inline_destructor at line 1464 of Class/MOP/Class.pm | ||||
102 | 46 | 13µs | my ( $self, $method_name ) = @_; | ||
103 | |||||
104 | 46 | 17µs | ( defined $method_name && length $method_name ) | ||
105 | || confess "You must define a method name"; | ||||
106 | |||||
107 | 46 | 124µs | 46 | 956µs | my $method = $self->_get_maybe_raw_method($method_name) # spent 956µs making 46 calls to Class::MOP::Mixin::HasMethods::_get_maybe_raw_method, avg 21µs/call |
108 | or return; | ||||
109 | |||||
110 | 6 | 38µs | 6 | 8µs | return defined($self->_method_map->{$method_name} = $method); # spent 8µs making 6 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 1µs/call |
111 | } | ||||
112 | |||||
113 | # spent 29.4ms (3.15+26.2) within Class::MOP::Mixin::HasMethods::get_method which was called 570 times, avg 52µs/call:
# 336 times (1.69ms+15.1ms) by Class::MOP::Class::find_method_by_name at line 1123 of Class/MOP/Class.pm, avg 50µs/call
# 150 times (919µs+3.35ms) by Class::MOP::Class::find_next_method_by_name at line 1171 of Class/MOP/Class.pm, avg 28µs/call
# 44 times (149µs+859µs) by Class::MOP::Class::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Class/MOP/Class.pm:1072] at line 1047 of Class/MOP/Class.pm, avg 23µs/call
# 36 times (357µs+6.80ms) by Class::MOP::Mixin::HasMethods::_full_method_map at line 205, avg 199µs/call
# 3 times (21µs+74µs) by Moose::Meta::Attribute::_process_accessors at line 1043 of Moose/Meta/Attribute.pm, avg 32µs/call
# once (6µs+24µs) by Moose::init_meta at line 207 of Moose.pm | ||||
114 | 570 | 172µs | my ( $self, $method_name ) = @_; | ||
115 | |||||
116 | 570 | 148µs | ( defined $method_name && length $method_name ) | ||
117 | || confess "You must define a method name"; | ||||
118 | |||||
119 | 570 | 1.35ms | 570 | 18.5ms | my $method = $self->_get_maybe_raw_method($method_name) # spent 18.5ms making 570 calls to Class::MOP::Mixin::HasMethods::_get_maybe_raw_method, avg 32µs/call |
120 | or return; | ||||
121 | |||||
122 | 154 | 884µs | 243 | 225µs | return $method if blessed($method) && $method->isa('Class::MOP::Method'); # spent 142µs making 154 calls to Scalar::Util::blessed, avg 923ns/call
# spent 83µs making 89 calls to UNIVERSAL::isa, avg 931ns/call |
123 | |||||
124 | 65 | 482µs | 130 | 7.49ms | return $self->_method_map->{$method_name} = $self->wrap_method_body( # spent 7.28ms making 65 calls to Class::MOP::Mixin::HasMethods::wrap_method_body, avg 112µs/call
# spent 108µs making 13 calls to Class::MOP::Class::Immutable::Class::MOP::Class::_method_map, avg 8µs/call
# spent 95µs making 52 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 2µs/call |
125 | body => $method, | ||||
126 | name => $method_name, | ||||
127 | associated_metaclass => $self, | ||||
128 | ); | ||||
129 | } | ||||
130 | |||||
131 | # spent 19.5ms (4.15+15.3) within Class::MOP::Mixin::HasMethods::_get_maybe_raw_method which was called 616 times, avg 32µs/call:
# 570 times (3.81ms+14.7ms) by Class::MOP::Mixin::HasMethods::get_method at line 119, avg 32µs/call
# 46 times (331µs+624µs) by Class::MOP::Mixin::HasMethods::has_method at line 107, avg 21µs/call | ||||
132 | 616 | 113µs | my ( $self, $method_name ) = @_; | ||
133 | |||||
134 | 616 | 2.10ms | 623 | 2.83ms | my $map_entry = $self->_method_map->{$method_name}; # spent 1.94ms making 228 calls to Class::MOP::Class::Immutable::Class::MOP::Class::_method_map, avg 8µs/call
# spent 886µs making 388 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 2µs/call
# spent 5µs making 7 calls to Class::MOP::Method::body, avg 686ns/call |
135 | 616 | 249µs | return $map_entry if defined $map_entry; | ||
136 | |||||
137 | 522 | 844µs | 522 | 11.6ms | my $code = $self->get_package_symbol("&$method_name"); # spent 11.6ms making 522 calls to Class::MOP::Package::get_package_symbol, avg 22µs/call |
138 | |||||
139 | 522 | 1.07ms | 105 | 850µs | return unless $code && $self->_code_is_mine($code); # spent 850µs making 105 calls to Class::MOP::Mixin::HasMethods::_code_is_mine, avg 8µs/call |
140 | |||||
141 | 66 | 133µs | return $code; | ||
142 | } | ||||
143 | |||||
144 | sub remove_method { | ||||
145 | my ( $self, $method_name ) = @_; | ||||
146 | |||||
147 | ( defined $method_name && length $method_name ) | ||||
148 | || confess "You must define a method name"; | ||||
149 | |||||
150 | my $removed_method = delete $self->_method_map->{$method_name}; | ||||
151 | |||||
152 | $self->remove_package_symbol("&$method_name"); | ||||
153 | |||||
154 | $removed_method->detach_from_class | ||||
155 | if blessed($removed_method) && $removed_method->isa('Class::MOP::Method'); | ||||
156 | |||||
157 | # still valid, since we just removed the method from the map | ||||
158 | $self->update_package_cache_flag; | ||||
159 | |||||
160 | return $removed_method; | ||||
161 | } | ||||
162 | |||||
163 | sub get_method_list { | ||||
164 | my $self = shift; | ||||
165 | |||||
166 | return keys %{ $self->_full_method_map }; | ||||
167 | } | ||||
168 | |||||
169 | # spent 7.62ms (80µs+7.54) within Class::MOP::Mixin::HasMethods::_get_local_methods which was called 17 times, avg 448µs/call:
# 17 times (80µs+7.54ms) by Class::MOP::Class::get_all_methods at line 1136 of Class/MOP/Class.pm, avg 448µs/call | ||||
170 | 17 | 3µs | my $self = shift; | ||
171 | |||||
172 | 17 | 69µs | 17 | 7.54ms | return values %{ $self->_full_method_map }; # spent 7.54ms making 17 calls to Class::MOP::Mixin::HasMethods::_full_method_map, avg 444µs/call |
173 | } | ||||
174 | |||||
175 | sub _restore_metamethods_from { | ||||
176 | my $self = shift; | ||||
177 | my ($old_meta) = @_; | ||||
178 | |||||
179 | for my $method ($old_meta->_get_local_methods) { | ||||
180 | $method->_make_compatible_with($self->method_metaclass); | ||||
181 | $self->add_method($method->name => $method); | ||||
182 | } | ||||
183 | } | ||||
184 | |||||
185 | sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef } | ||||
186 | # spent 3.00ms (2.17+831µs) within Class::MOP::Mixin::HasMethods::update_package_cache_flag which was called 386 times, avg 8µs/call:
# 386 times (2.17ms+831µs) by Class::MOP::Mixin::HasMethods::add_method at line 89, avg 8µs/call | ||||
187 | 386 | 88µs | my $self = shift; | ||
188 | # NOTE: | ||||
189 | # we can manually update the cache number | ||||
190 | # since we are actually adding the method | ||||
191 | # to our cache as well. This avoids us | ||||
192 | # having to regenerate the method_map. | ||||
193 | # - SL | ||||
194 | 386 | 3.12ms | 772 | 831µs | $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name); # spent 598µs making 386 calls to mro::get_pkg_gen, avg 2µs/call
# spent 234µs making 386 calls to Class::MOP::Package::name, avg 605ns/call |
195 | } | ||||
196 | |||||
197 | # spent 7.54ms (263µs+7.28) within Class::MOP::Mixin::HasMethods::_full_method_map which was called 17 times, avg 444µs/call:
# 17 times (263µs+7.28ms) by Class::MOP::Mixin::HasMethods::_get_local_methods at line 172, avg 444µs/call | ||||
198 | 17 | 3µs | my $self = shift; | ||
199 | |||||
200 | 17 | 100µs | 34 | 30µs | my $pkg_gen = Class::MOP::check_package_cache_flag($self->name); # spent 22µs making 17 calls to mro::get_pkg_gen, avg 1µs/call
# spent 9µs making 17 calls to Class::MOP::Package::name, avg 524ns/call |
201 | |||||
202 | 17 | 11µs | if (($self->{_package_cache_flag_full} || -1) != $pkg_gen) { | ||
203 | # forcibly reify all method map entries | ||||
204 | $self->get_method($_) | ||||
205 | 4 | 69µs | 40 | 7.22ms | for $self->list_all_package_symbols('CODE'); # spent 7.16ms making 36 calls to Class::MOP::Mixin::HasMethods::get_method, avg 199µs/call
# spent 65µs making 4 calls to Class::MOP::Package::list_all_package_symbols, avg 16µs/call |
206 | 4 | 3µs | $self->{_package_cache_flag_full} = $pkg_gen; | ||
207 | } | ||||
208 | |||||
209 | 17 | 99µs | 17 | 26µs | return $self->_method_map; # spent 26µs making 17 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 2µs/call |
210 | } | ||||
211 | |||||
212 | # overloading | ||||
213 | |||||
214 | 1 | 100ns | my $overload_operators; | ||
215 | sub overload_operators { | ||||
216 | $overload_operators ||= [map { split /\s+/ } values %overload::ops]; | ||||
217 | return @$overload_operators; | ||||
218 | } | ||||
219 | |||||
220 | sub is_overloaded { | ||||
221 | my $self = shift; | ||||
222 | return overload::Overloaded($self->name); | ||||
223 | } | ||||
224 | |||||
225 | # XXX this could probably stand to be cached, but i figure it should be | ||||
226 | # uncommon enough to not particularly matter | ||||
227 | sub _overload_map { | ||||
228 | my $self = shift; | ||||
229 | |||||
230 | return {} unless $self->is_overloaded; | ||||
231 | |||||
232 | my %map; | ||||
233 | for my $op ($self->overload_operators) { | ||||
234 | my $body = $self->_get_overloaded_operator_body($op); | ||||
235 | next unless defined $body; | ||||
236 | $map{$op} = $body; | ||||
237 | } | ||||
238 | |||||
239 | return \%map; | ||||
240 | } | ||||
241 | |||||
242 | sub get_overload_list { | ||||
243 | my $self = shift; | ||||
244 | return keys %{ $self->_overload_map }; | ||||
245 | } | ||||
246 | |||||
247 | sub get_all_overloaded_operators { | ||||
248 | my $self = shift; | ||||
249 | my $map = $self->_overload_map; | ||||
250 | return map { $self->_wrap_overload($_, $map->{$_}) } keys %$map; | ||||
251 | } | ||||
252 | |||||
253 | sub has_overloaded_operator { | ||||
254 | my $self = shift; | ||||
255 | my ($op) = @_; | ||||
256 | return defined $self->_get_overloaded_operator_body($op); | ||||
257 | } | ||||
258 | |||||
259 | sub get_overloaded_operator { | ||||
260 | my $self = shift; | ||||
261 | my ($op) = @_; | ||||
262 | my $body = $self->_get_overloaded_operator_body($op); | ||||
263 | return unless defined $body; | ||||
264 | return $self->_wrap_overload($op, $body); | ||||
265 | } | ||||
266 | |||||
267 | sub add_overloaded_operator { | ||||
268 | my $self = shift; | ||||
269 | my ($op, $body) = @_; | ||||
270 | $self->name->overload::OVERLOAD($op => $body); | ||||
271 | } | ||||
272 | |||||
273 | sub remove_overloaded_operator { | ||||
274 | my $self = shift; | ||||
275 | my ($op) = @_; | ||||
276 | |||||
277 | if ( $] < 5.018 ) { | ||||
278 | # ugh, overload.pm provides no api for this - but the problem that | ||||
279 | # makes this necessary has been fixed in 5.18 | ||||
280 | $self->get_or_add_package_symbol('%OVERLOAD')->{dummy}++; | ||||
281 | } | ||||
282 | |||||
283 | $self->remove_package_symbol('&(' . $op); | ||||
284 | } | ||||
285 | |||||
286 | sub _get_overloaded_operator_body { | ||||
287 | my $self = shift; | ||||
288 | my ($op) = @_; | ||||
289 | return overload::Method($self->name, $op); | ||||
290 | } | ||||
291 | |||||
292 | sub _wrap_overload { | ||||
293 | my $self = shift; | ||||
294 | my ($op, $body) = @_; | ||||
295 | return Class::MOP::Method::Overload->wrap( | ||||
296 | operator => $op, | ||||
297 | package_name => $self->name, | ||||
298 | associated_metaclass => $self, | ||||
299 | body => $body, | ||||
300 | ); | ||||
301 | } | ||||
302 | |||||
303 | 1 | 4µs | 1; | ||
304 | |||||
305 | # ABSTRACT: Methods for metaclasses which have methods | ||||
306 | |||||
307 | __END__ | ||||
# spent 683µs within Class::MOP::Mixin::HasMethods::CORE:match which was called 386 times, avg 2µs/call:
# 386 times (683µs+0s) by Class::MOP::Mixin::HasMethods::add_method at line 83, avg 2µs/call |