Profile of Class/MOP/Mixin/HasOverloads.pm

← Index
NYTProf Performance Profile «line view»
For script/ponapi
Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:10 2016

Filename | /usr/local/lib/perl/5.18.2/Class/MOP/Mixin/HasOverloads.pm
Statements | Executed 205 statements in 1.29ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 726µs | 832µs | Class::MOP::Mixin::HasOverloads::::BEGIN@7Class::MOP::Mixin::HasOverloads::BEGIN@7
1 | 1 | 1 | 512µs | 2.11ms | Class::MOP::Mixin::HasOverloads::::BEGIN@9Class::MOP::Mixin::HasOverloads::BEGIN@9
92 | 2 | 2 | 385µs | 3.29ms | Class::MOP::Mixin::HasOverloads::::is_overloadedClass::MOP::Mixin::HasOverloads::is_overloaded
1 | 1 | 1 | 9µs | 19µs | Class::MOP::Mixin::HasOverloads::::BEGIN@4Class::MOP::Mixin::HasOverloads::BEGIN@4
1 | 1 | 1 | 8µs | 41µs | Class::MOP::Mixin::HasOverloads::::BEGIN@50Class::MOP::Mixin::HasOverloads::BEGIN@50
1 | 1 | 1 | 7µs | 10µs | Class::MOP::Mixin::HasOverloads::::BEGIN@5Class::MOP::Mixin::HasOverloads::BEGIN@5
1 | 1 | 1 | 6µs | 24µs | Class::MOP::Mixin::HasOverloads::::BEGIN@10Class::MOP::Mixin::HasOverloads::BEGIN@10
1 | 1 | 1 | 6µs | 22µs | Class::MOP::Mixin::HasOverloads::::BEGIN@15Class::MOP::Mixin::HasOverloads::BEGIN@15
1 | 1 | 1 | 6µs | 25µs | Class::MOP::Mixin::HasOverloads::::BEGIN@11Class::MOP::Mixin::HasOverloads::BEGIN@11
1 | 1 | 1 | 3µs | 3µs | Class::MOP::Mixin::HasOverloads::::BEGIN@13Class::MOP::Mixin::HasOverloads::BEGIN@13
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::_overload_forClass::MOP::Mixin::HasOverloads::_overload_for
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::_overload_infoClass::MOP::Mixin::HasOverloads::_overload_info
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::add_overloaded_operatorClass::MOP::Mixin::HasOverloads::add_overloaded_operator
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::get_all_overloaded_operatorsClass::MOP::Mixin::HasOverloads::get_all_overloaded_operators
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::get_overload_fallback_valueClass::MOP::Mixin::HasOverloads::get_overload_fallback_value
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::get_overload_listClass::MOP::Mixin::HasOverloads::get_overload_list
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::get_overloaded_operatorClass::MOP::Mixin::HasOverloads::get_overloaded_operator
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::has_overloaded_operatorClass::MOP::Mixin::HasOverloads::has_overloaded_operator
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::remove_overloaded_operatorClass::MOP::Mixin::HasOverloads::remove_overloaded_operator
0 | 0 | 0 | 0s | 0s | Class::MOP::Mixin::HasOverloads::::set_overload_fallback_valueClass::MOP::Mixin::HasOverloads::set_overload_fallback_value

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

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Class::MOP::Mixin::HasOverloads;
2 | 1 | 400ns |  |  | our $VERSION = '2.1604';
3 |  |  |  |  |
4 | 2 | 19µs | 2 | 29µs | # spent 19µs (9+10) within Class::MOP::Mixin::HasOverloads::BEGIN@4 which was called: # once (9µs+10µs) by Class::MOP::BEGIN@17 at line 4 use strict; # spent 19µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@4 # spent 10µs making 1 call to strict::import
5 | 2 | 18µs | 2 | 13µs | # spent 10µs (7+3) within Class::MOP::Mixin::HasOverloads::BEGIN@5 which was called: # once (7µs+3µs) by Class::MOP::BEGIN@17 at line 5 use warnings; # spent 10µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@5 # spent 3µs making 1 call to warnings::import
6 |  |  |  |  |
7 | 2 | 90µs | 1 | 832µs | # spent 832µs (726+107) within Class::MOP::Mixin::HasOverloads::BEGIN@7 which was called: # once (726µs+107µs) by Class::MOP::BEGIN@17 at line 7 use Class::MOP::Overload; # spent 832µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@7
8 |  |  |  |  |
9 | 3 | 101µs | 3 | 2.15ms | # spent 2.11ms (512µs+1.60) within Class::MOP::Mixin::HasOverloads::BEGIN@9 which was called: # once (512µs+1.60ms) by Class::MOP::BEGIN@17 at line 9 use Devel::OverloadInfo 0.004 'overload_info'; # spent 2.11ms making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@9 # spent 28µs making 1 call to Exporter::import # spent 8µs making 1 call to UNIVERSAL::VERSION
10 | 2 | 21µs | 2 | 42µs | # spent 24µs (6+18) within Class::MOP::Mixin::HasOverloads::BEGIN@10 which was called: # once (6µs+18µs) by Class::MOP::BEGIN@17 at line 10 use Scalar::Util 'blessed'; # spent 24µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@10 # spent 18µs making 1 call to Exporter::import
11 | 2 | 19µs | 2 | 44µs | # spent 25µs (6+19) within Class::MOP::Mixin::HasOverloads::BEGIN@11 which was called: # once (6µs+19µs) by Class::MOP::BEGIN@17 at line 11 use Sub::Identify 'sub_name', 'stash_name'; # spent 25µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@11 # spent 19µs making 1 call to Exporter::import
12 |  |  |  |  |
13 | 2 | 18µs | 1 | 3µs | # spent 3µs within Class::MOP::Mixin::HasOverloads::BEGIN@13 which was called: # once (3µs+0s) by Class::MOP::BEGIN@17 at line 13 use overload (); # spent 3µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@13
14 |  |  |  |  |
15 | 2 | 171µs | 2 | 39µs | # spent 22µs (6+16) within Class::MOP::Mixin::HasOverloads::BEGIN@15 which was called: # once (6µs+16µs) by Class::MOP::BEGIN@17 at line 15 use parent 'Class::MOP::Mixin'; # spent 22µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@15 # spent 16µs making 1 call to parent::import
16 |  |  |  |  |
17 |  |  |  |  | # spent 3.29ms (385µs+2.91) within Class::MOP::Mixin::HasOverloads::is_overloaded which was called 92 times, avg 36µs/call: # 69 times (265µs+1.88ms) by Moose::Meta::Role::Application::RoleSummation::apply_overloading at line 262 of Moose/Meta/Role/Application/RoleSummation.pm, avg 31µs/call # 23 times (120µs+1.03ms) by Moose::Meta::Role::Application::apply_overloading at line 85 of Moose/Meta/Role/Application.pm, avg 50µs/call sub is_overloaded {
18 | 92 | 20µs |  |  | my $self = shift;
19 | 92 | 398µs | 184 | 2.91ms | Devel::OverloadInfo::is_overloaded($self->name); # spent 2.87ms making 92 calls to Devel::OverloadInfo::is_overloaded, avg 31µs/call # spent 37µs making 92 calls to Class::MOP::Package::name, avg 398ns/call
20 |  |  |  |  | }
21 |  |  |  |  |
22 |  |  |  |  | sub get_overload_list {
23 |  |  |  |  | my $self = shift;
24 |  |  |  |  |
25 |  |  |  |  | my $info = $self->_overload_info;
26 |  |  |  |  | return grep { $_ ne 'fallback' } keys %{$info}
27 |  |  |  |  | }
28 |  |  |  |  |
29 |  |  |  |  | sub get_all_overloaded_operators {
30 |  |  |  |  | my $self = shift;
31 |  |  |  |  | return map { $self->_overload_for($_) } $self->get_overload_list;
32 |  |  |  |  | }
33 |  |  |  |  |
34 |  |  |  |  | sub has_overloaded_operator {
35 |  |  |  |  | my $self = shift;
36 |  |  |  |  | my ($op) = @_;
37 |  |  |  |  | return defined $self->_overload_info->{$op};
38 |  |  |  |  | }
39 |  |  |  |  |
40 |  |  |  |  | sub _overload_map {
41 |  |  |  |  | $_[0]->{_overload_map} ||= {};
42 |  |  |  |  | }
43 |  |  |  |  |
44 |  |  |  |  | sub get_overloaded_operator {
45 |  |  |  |  | my $self = shift;
46 |  |  |  |  | my ($op) = @_;
47 |  |  |  |  | return $self->_overload_map->{$op} ||= $self->_overload_for($op);
48 |  |  |  |  | }
49 |  |  |  |  |
50 | 2 | 408µs | 2 | 74µs | # spent 41µs (8+33) within Class::MOP::Mixin::HasOverloads::BEGIN@50 which was called: # once (8µs+33µs) by Class::MOP::BEGIN@17 at line 50 use constant _SET_FALLBACK_EACH_TIME => $] < 5.120; # spent 41µs making 1 call to Class::MOP::Mixin::HasOverloads::BEGIN@50 # spent 33µs making 1 call to constant::import
51 |  |  |  |  |
52 |  |  |  |  | sub add_overloaded_operator {
53 |  |  |  |  | my $self = shift;
54 |  |  |  |  | my ( $op, $overload ) = @_;
55 |  |  |  |  |
56 |  |  |  |  | my %p = ( associated_metaclass => $self );
57 |  |  |  |  | if ( !ref $overload ) {
58 |  |  |  |  | %p = (
59 |  |  |  |  | %p,
60 |  |  |  |  | operator => $op,
61 |  |  |  |  | method_name => $overload,
62 |  |  |  |  | associated_metaclass => $self,
63 |  |  |  |  | );
64 |  |  |  |  | $p{method} = $self->get_method($overload)
65 |  |  |  |  | if $self->has_method($overload);
66 |  |  |  |  | $overload = Class::MOP::Overload->new(%p);
67 |  |  |  |  | }
68 |  |  |  |  | elsif ( !blessed $overload) {
69 |  |  |  |  | $overload = Class::MOP::Overload->new(
70 |  |  |  |  | operator => $op,
71 |  |  |  |  | coderef => $overload,
72 |  |  |  |  | coderef_name => sub_name($overload),
73 |  |  |  |  | coderef_package => stash_name($overload),
74 |  |  |  |  | %p,
75 |  |  |  |  | );
76 |  |  |  |  | }
77 |  |  |  |  |
78 |  |  |  |  | $overload->attach_to_class($self);
79 |  |  |  |  | $self->_overload_map->{$op} = $overload;
80 |  |  |  |  |
81 |  |  |  |  | my %overload = (
82 |  |  |  |  | $op => $overload->has_coderef
83 |  |  |  |  | ? $overload->coderef
84 |  |  |  |  | : $overload->method_name
85 |  |  |  |  | );
86 |  |  |  |  |
87 |  |  |  |  | # Perl 5.10 and earlier appear to have a bug where setting a new
88 |  |  |  |  | # overloading operator wipes out the fallback value unless we pass it each
89 |  |  |  |  | # time.
90 |  |  |  |  | if (_SET_FALLBACK_EACH_TIME) {
91 |  |  |  |  | $overload{fallback} = $self->get_overload_fallback_value;
92 |  |  |  |  | }
93 |  |  |  |  |
94 |  |  |  |  | $self->name->overload::OVERLOAD(%overload);
95 |  |  |  |  | }
96 |  |  |  |  |
97 |  |  |  |  | sub remove_overloaded_operator {
98 |  |  |  |  | my $self = shift;
99 |  |  |  |  | my ($op) = @_;
100 |  |  |  |  |
101 |  |  |  |  | delete $self->_overload_map->{$op};
102 |  |  |  |  |
103 |  |  |  |  | # overload.pm provides no api for this - but the problem that makes this
104 |  |  |  |  | # necessary has been fixed in 5.18
105 |  |  |  |  | $self->get_or_add_package_symbol('%OVERLOAD')->{dummy}++
106 |  |  |  |  | if $] < 5.017000;
107 |  |  |  |  |
108 |  |  |  |  | $self->remove_package_symbol('&(' . $op);
109 |  |  |  |  | }
110 |  |  |  |  |
111 |  |  |  |  | sub get_overload_fallback_value {
112 |  |  |  |  | my $self = shift;
113 |  |  |  |  | return $self->_overload_info->{fallback}{value};
114 |  |  |  |  | }
115 |  |  |  |  |
116 |  |  |  |  | sub set_overload_fallback_value {
117 |  |  |  |  | my $self = shift;
118 |  |  |  |  | my $value = shift;
119 |  |  |  |  |
120 |  |  |  |  | $self->name->overload::OVERLOAD( fallback => $value );
121 |  |  |  |  | }
122 |  |  |  |  |
123 |  |  |  |  | # We could cache this but we'd need some logic to clear it at all the right
124 |  |  |  |  | # times, which seems more tedious than it's worth.
125 |  |  |  |  | sub _overload_info {
126 |  |  |  |  | my $self = shift;
127 |  |  |  |  | return overload_info( $self->name ) || {};
128 |  |  |  |  | }
129 |  |  |  |  |
130 |  |  |  |  | sub _overload_for {
131 |  |  |  |  | my $self = shift;
132 |  |  |  |  | my $op = shift;
133 |  |  |  |  |
134 |  |  |  |  | my $map = $self->_overload_map;
135 |  |  |  |  | return $map->{$op} if $map->{$op};
136 |  |  |  |  |
137 |  |  |  |  | my $info = $self->_overload_info->{$op};
138 |  |  |  |  | return unless $info;
139 |  |  |  |  |
140 |  |  |  |  | my %p = (
141 |  |  |  |  | operator => $op,
142 |  |  |  |  | associated_metaclass => $self,
143 |  |  |  |  | );
144 |  |  |  |  |
145 |  |  |  |  | if ( $info->{code} && !$info->{method_name} ) {
146 |  |  |  |  | $p{coderef} = $info->{code};
147 |  |  |  |  | @p{ 'coderef_package', 'coderef_name' }
148 |  |  |  |  | = $info->{code_name} =~ /(.+)::([^:]+)/;
149 |  |  |  |  | }
150 |  |  |  |  | else {
151 |  |  |  |  | $p{method_name} = $info->{method_name};
152 |  |  |  |  | if ( $self->has_method( $p{method_name} ) ) {
153 |  |  |  |  | $p{method} = $self->get_method( $p{method_name} );
154 |  |  |  |  | }
155 |  |  |  |  | }
156 |  |  |  |  |
157 |  |  |  |  | return $map->{$op} = Class::MOP::Overload->new(%p);
158 |  |  |  |  | }
159 |  |  |  |  |
160 | 1 | 2µs |  |  | 1;
161 |  |  |  |  |
162 |  |  |  |  | # ABSTRACT: Methods for metaclasses which have overloads
163 |  |  |  |  |
164 |  |  |  |  | __END__