Filename | /usr/share/perl/5.20/overload.pm |
Statements | Executed 863 statements in 3.07ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.76ms | 1.80ms | BEGIN@83 | overload::
26 | 1 | 1 | 632µs | 735µs | OVERLOAD | overload::
26 | 26 | 24 | 235µs | 969µs | import | overload::
1 | 1 | 1 | 11µs | 107µs | BEGIN@144 | overload::
1 | 1 | 1 | 10µs | 17µs | BEGIN@114 | overload::
0 | 0 | 0 | 0s | 0s | AddrRef | overload::
0 | 0 | 0 | 0s | 0s | Method | overload::
0 | 0 | 0 | 0s | 0s | Overloaded | overload::
0 | 0 | 0 | 0s | 0s | OverloadedStringify | overload::
0 | 0 | 0 | 0s | 0s | constant | overload::
0 | 0 | 0 | 0s | 0s | mycan | overload::
0 | 0 | 0 | 0s | 0s | nil | overload::
0 | 0 | 0 | 0s | 0s | ov_method | overload::
0 | 0 | 0 | 0s | 0s | remove_constant | overload::
0 | 0 | 0 | 0s | 0s | unimport | overload::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package overload; | ||||
2 | |||||
3 | 1 | 500ns | our $VERSION = '1.22'; | ||
4 | |||||
5 | 1 | 7µs | %ops = ( | ||
6 | with_assign => "+ - * / % ** << >> x .", | ||||
7 | assign => "+= -= *= /= %= **= <<= >>= x= .=", | ||||
8 | num_comparison => "< <= > >= == !=", | ||||
9 | '3way_comparison' => "<=> cmp", | ||||
10 | str_comparison => "lt le gt ge eq ne", | ||||
11 | binary => '& &= | |= ^ ^=', | ||||
12 | unary => "neg ! ~", | ||||
13 | mutators => '++ --', | ||||
14 | func => "atan2 cos sin exp abs log sqrt int", | ||||
15 | conversion => 'bool "" 0+ qr', | ||||
16 | iterators => '<>', | ||||
17 | filetest => "-X", | ||||
18 | dereferencing => '${} @{} %{} &{} *{}', | ||||
19 | matching => '~~', | ||||
20 | special => 'nomethod fallback =', | ||||
21 | ); | ||||
22 | |||||
23 | 1 | 300ns | my %ops_seen; | ||
24 | 1 | 3µs | for $category (keys %ops) { | ||
25 | 15 | 53µs | $ops_seen{$_}++ for (split /\s+/, $ops{$category}); | ||
26 | } | ||||
27 | |||||
28 | sub nil {} | ||||
29 | |||||
30 | # spent 735µs (632+102) within overload::OVERLOAD which was called 26 times, avg 28µs/call:
# 26 times (632µs+102µs) by overload::import at line 59, avg 28µs/call | ||||
31 | 26 | 7µs | $package = shift; | ||
32 | 26 | 73µs | my %arg = @_; | ||
33 | 26 | 4µs | my ($sub, $fb); | ||
34 | 26 | 90µs | *{$package . "::(("} = \&nil; # Make it findable via fetchmethod. | ||
35 | 26 | 146µs | for (keys %arg) { | ||
36 | 118 | 62µs | if ($_ eq 'fallback') { | ||
37 | 13 | 25µs | for my $sym (*{$package . "::()"}) { | ||
38 | 13 | 9µs | *$sym = \&nil; # Make it findable via fetchmethod. | ||
39 | 13 | 14µs | $$sym = $arg{$_}; | ||
40 | } | ||||
41 | } else { | ||||
42 | 105 | 43µs | 1 | 102µs | warnings::warnif("overload arg '$_' is invalid") # spent 102µs making 1 call to warnings::warnif |
43 | unless $ops_seen{$_}; | ||||
44 | 105 | 19µs | $sub = $arg{$_}; | ||
45 | 105 | 22µs | if (not ref $sub) { | ||
46 | 25 | 37µs | $ {$package . "::(" . $_} = $sub; | ||
47 | 25 | 8µs | $sub = \&nil; | ||
48 | } | ||||
49 | #print STDERR "Setting '$ {'package'}::\cO$_' to \\&'$sub'.\n"; | ||||
50 | 105 | 130µs | *{$package . "::(" . $_} = \&{ $sub }; | ||
51 | } | ||||
52 | } | ||||
53 | } | ||||
54 | |||||
55 | # spent 969µs (235+735) within overload::import which was called 26 times, avg 37µs/call:
# once (9µs+215µs) by Math::BigInt::BEGIN@46 at line 155 of Math/BigInt.pm
# once (12µs+38µs) by CGI::Cookie::BEGIN@11 at line 11 of CGI/Cookie.pm
# once (10µs+40µs) by DateTime::BEGIN@57 at line 58 of DateTime.pm
# once (10µs+32µs) by DateTime::Duration::BEGIN@11 at line 12 of DateTime/Duration.pm
# once (9µs+27µs) by XML::LibXML::Error::BEGIN@22 at line 29 of XML/LibXML/Error.pm
# once (11µs+25µs) by URI::BEGIN@24 at line 27 of URI.pm
# once (6µs+27µs) by XML::LibXML::Element::BEGIN@1542 at line 1542 of XML/LibXML.pm
# once (11µs+22µs) by CGI::File::Temp::BEGIN@12 at line 12 of CGI/File/Temp.pm
# once (9µs+24µs) by File::Temp::BEGIN@32 at line 32 of File/Temp.pm
# once (10µs+22µs) by File::Temp::Dir::BEGIN@1543 at line 1543 of File/Temp.pm
# once (9µs+21µs) by MIME::Type::BEGIN@19 at line 19 of MIME/Type.pm
# once (9µs+21µs) by Template::Exception::BEGIN@27 at line 27 of Template/Exception.pm
# once (10µs+20µs) by Set::Infinite::Basic::BEGIN@27 at line 27 of Set/Infinite/Basic.pm
# once (9µs+20µs) by XML::SAX::Exception::BEGIN@8 at line 8 of XML/SAX/Exception.pm
# once (10µs+19µs) by JSON::XS::Boolean::BEGIN@3 at line 14 of (eval 65)[JSON.pm:353]
# once (8µs+21µs) by JSON::XS::Boolean::BEGIN@1497 at line 1500 of JSON/XS.pm
# once (12µs+15µs) by XML::LibXML::Literal::BEGIN@22 at line 22 of XML/LibXML/Literal.pm
# once (10µs+16µs) by XML::Parser::ContentModel::BEGIN@501 at line 501 of XML/Parser/Expat.pm
# once (10µs+14µs) by YAML::Tag::BEGIN@4 at line 4 of YAML/Tag.pm
# once (7µs+17µs) by XML::LibXML::Node::BEGIN@1271 at line 1274 of XML/LibXML.pm
# once (12µs+12µs) by ZOOM::Exception::BEGIN@194 at line 194 of ZOOM.pm
# once (9µs+15µs) by Set::Infinite::BEGIN@21 at line 21 of Set/Infinite.pm
# once (6µs+15µs) by XML::LibXML::Number::BEGIN@20 at line 20 of XML/LibXML/Number.pm
# once (7µs+13µs) by XML::LibXML::NodeList::BEGIN@23 at line 29 of XML/LibXML/NodeList.pm
# once (7µs+11µs) by JSON::PP::Boolean::BEGIN@3 at line 14 of (eval 66)[JSON.pm:353]
# once (5µs+11µs) by XML::LibXML::Boolean::BEGIN@22 at line 22 of XML/LibXML/Boolean.pm | ||||
56 | 26 | 47µs | $package = (caller())[0]; | ||
57 | # *{$package . "::OVERLOAD"} = \&OVERLOAD; | ||||
58 | 26 | 6µs | shift; | ||
59 | 26 | 168µs | 26 | 735µs | $package->overload::OVERLOAD(@_); # spent 735µs making 26 calls to overload::OVERLOAD, avg 28µs/call |
60 | } | ||||
61 | |||||
62 | sub unimport { | ||||
63 | $package = (caller())[0]; | ||||
64 | shift; | ||||
65 | *{$package . "::(("} = \&nil; | ||||
66 | for (@_) { | ||||
67 | warnings::warnif("overload arg '$_' is invalid") | ||||
68 | unless $ops_seen{$_}; | ||||
69 | delete $ {$package . "::"}{$_ eq 'fallback' ? '()' : "(" .$_}; | ||||
70 | } | ||||
71 | } | ||||
72 | |||||
73 | sub Overloaded { | ||||
74 | my $package = shift; | ||||
75 | $package = ref $package if ref $package; | ||||
76 | mycan ($package, '()') || mycan ($package, '(('); | ||||
77 | } | ||||
78 | |||||
79 | sub ov_method { | ||||
80 | my $globref = shift; | ||||
81 | return undef unless $globref; | ||||
82 | my $sub = \&{*$globref}; | ||||
83 | 2 | 1.65ms | 2 | 1.81ms | # spent 1.80ms (1.76+39µs) within overload::BEGIN@83 which was called:
# once (1.76ms+39µs) by ZOOM::Exception::BEGIN@194 at line 83 # spent 1.80ms making 1 call to overload::BEGIN@83
# spent 10µs making 1 call to overloading::unimport |
84 | return $sub if !ref $sub or $sub != \&nil; | ||||
85 | return shift->can($ {*$globref}); | ||||
86 | } | ||||
87 | |||||
88 | sub OverloadedStringify { | ||||
89 | my $package = shift; | ||||
90 | $package = ref $package if ref $package; | ||||
91 | #$package->can('(""') | ||||
92 | ov_method mycan($package, '(""'), $package | ||||
93 | or ov_method mycan($package, '(0+'), $package | ||||
94 | or ov_method mycan($package, '(bool'), $package | ||||
95 | or ov_method mycan($package, '(nomethod'), $package; | ||||
96 | } | ||||
97 | |||||
98 | sub Method { | ||||
99 | my $package = shift; | ||||
100 | if(ref $package) { | ||||
101 | local $@; | ||||
102 | local $!; | ||||
103 | require Scalar::Util; | ||||
104 | $package = Scalar::Util::blessed($package); | ||||
105 | return undef if !defined $package; | ||||
106 | } | ||||
107 | #my $meth = $package->can('(' . shift); | ||||
108 | ov_method mycan($package, '(' . shift), $package; | ||||
109 | #return $meth if $meth ne \&nil; | ||||
110 | #return $ {*{$meth}}; | ||||
111 | } | ||||
112 | |||||
113 | sub AddrRef { | ||||
114 | 2 | 169µs | 2 | 24µs | # spent 17µs (10+7) within overload::BEGIN@114 which was called:
# once (10µs+7µs) by ZOOM::Exception::BEGIN@194 at line 114 # spent 17µs making 1 call to overload::BEGIN@114
# spent 7µs making 1 call to overloading::unimport |
115 | "$_[0]"; | ||||
116 | } | ||||
117 | |||||
118 | 1 | 2µs | *StrVal = *AddrRef; | ||
119 | |||||
120 | sub mycan { # Real can would leave stubs. | ||||
121 | my ($package, $meth) = @_; | ||||
122 | |||||
123 | local $@; | ||||
124 | local $!; | ||||
125 | require mro; | ||||
126 | |||||
127 | my $mro = mro::get_linear_isa($package); | ||||
128 | foreach my $p (@$mro) { | ||||
129 | my $fqmeth = $p . q{::} . $meth; | ||||
130 | return \*{$fqmeth} if defined &{$fqmeth}; | ||||
131 | } | ||||
132 | |||||
133 | return undef; | ||||
134 | } | ||||
135 | |||||
136 | 1 | 2µs | %constants = ( | ||
137 | 'integer' => 0x1000, # HINT_NEW_INTEGER | ||||
138 | 'float' => 0x2000, # HINT_NEW_FLOAT | ||||
139 | 'binary' => 0x4000, # HINT_NEW_BINARY | ||||
140 | 'q' => 0x8000, # HINT_NEW_STRING | ||||
141 | 'qr' => 0x10000, # HINT_NEW_RE | ||||
142 | ); | ||||
143 | |||||
144 | 2 | 261µs | 2 | 203µs | # spent 107µs (11+96) within overload::BEGIN@144 which was called:
# once (11µs+96µs) by ZOOM::Exception::BEGIN@194 at line 144 # spent 107µs making 1 call to overload::BEGIN@144
# spent 96µs making 1 call to warnings::register::import |
145 | sub constant { | ||||
146 | # Arguments: what, sub | ||||
147 | while (@_) { | ||||
148 | if (@_ == 1) { | ||||
149 | warnings::warnif ("Odd number of arguments for overload::constant"); | ||||
150 | last; | ||||
151 | } | ||||
152 | elsif (!exists $constants {$_ [0]}) { | ||||
153 | warnings::warnif ("'$_[0]' is not an overloadable type"); | ||||
154 | } | ||||
155 | elsif (!ref $_ [1] || "$_[1]" !~ /(^|=)CODE\(0x[0-9a-f]+\)$/) { | ||||
156 | # Can't use C<ref $_[1] eq "CODE"> above as code references can be | ||||
157 | # blessed, and C<ref> would return the package the ref is blessed into. | ||||
158 | if (warnings::enabled) { | ||||
159 | $_ [1] = "undef" unless defined $_ [1]; | ||||
160 | warnings::warn ("'$_[1]' is not a code reference"); | ||||
161 | } | ||||
162 | } | ||||
163 | else { | ||||
164 | $^H{$_[0]} = $_[1]; | ||||
165 | $^H |= $constants{$_[0]}; | ||||
166 | } | ||||
167 | shift, shift; | ||||
168 | } | ||||
169 | } | ||||
170 | |||||
171 | sub remove_constant { | ||||
172 | # Arguments: what, sub | ||||
173 | while (@_) { | ||||
174 | delete $^H{$_[0]}; | ||||
175 | $^H &= ~ $constants{$_[0]}; | ||||
176 | shift, shift; | ||||
177 | } | ||||
178 | } | ||||
179 | |||||
180 | 1 | 9µs | 1; | ||
181 | |||||
182 | __END__ |