Filename | /Users/ether/perl5/perlbrew/perls/36.0/lib/5.36.0/overload.pm |
Statements | Executed 349 statements in 1.12ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
14 | 1 | 1 | 207µs | 207µs | OVERLOAD | overload::
14 | 14 | 12 | 94µs | 301µs | import | overload::
1 | 1 | 1 | 22µs | 26µs | BEGIN@3 | overload::
1 | 1 | 1 | 18µs | 18µs | unimport | overload::
1 | 1 | 1 | 7µs | 71µs | BEGIN@145 | overload::
1 | 1 | 1 | 7µs | 15µs | BEGIN@85 | overload::
1 | 1 | 1 | 5µs | 25µs | BEGIN@5 | overload::
1 | 1 | 1 | 4µs | 10µs | BEGIN@4 | overload::
1 | 1 | 1 | 3µs | 8µs | BEGIN@115 | 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::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package overload; | ||||
2 | |||||
3 | 2 | 26µs | 2 | 30µs | # spent 26µs (22+4) within overload::BEGIN@3 which was called:
# once (22µs+4µs) by Cpanel::JSON::XS::BEGIN@2334 at line 3 # spent 26µs making 1 call to overload::BEGIN@3
# spent 4µs making 1 call to strict::import |
4 | 2 | 21µs | 2 | 16µs | # spent 10µs (4+6) within overload::BEGIN@4 which was called:
# once (4µs+6µs) by Cpanel::JSON::XS::BEGIN@2334 at line 4 # spent 10µs making 1 call to overload::BEGIN@4
# spent 6µs making 1 call to strict::unimport |
5 | 2 | 286µs | 2 | 45µs | # spent 25µs (5+20) within overload::BEGIN@5 which was called:
# once (5µs+20µs) by Cpanel::JSON::XS::BEGIN@2334 at line 5 # spent 25µs making 1 call to overload::BEGIN@5
# spent 20µs making 1 call to warnings::unimport |
6 | |||||
7 | 1 | 1µs | our $VERSION = '1.35'; | ||
8 | |||||
9 | 1 | 5µs | our %ops = ( | ||
10 | with_assign => "+ - * / % ** << >> x .", | ||||
11 | assign => "+= -= *= /= %= **= <<= >>= x= .=", | ||||
12 | num_comparison => "< <= > >= == !=", | ||||
13 | '3way_comparison' => "<=> cmp", | ||||
14 | str_comparison => "lt le gt ge eq ne", | ||||
15 | binary => '& &= | |= ^ ^= &. &.= |. |.= ^. ^.=', | ||||
16 | unary => "neg ! ~ ~.", | ||||
17 | mutators => '++ --', | ||||
18 | func => "atan2 cos sin exp abs log sqrt int", | ||||
19 | conversion => 'bool "" 0+ qr', | ||||
20 | iterators => '<>', | ||||
21 | filetest => "-X", | ||||
22 | dereferencing => '${} @{} %{} &{} *{}', | ||||
23 | matching => '~~', | ||||
24 | special => 'nomethod fallback =', | ||||
25 | ); | ||||
26 | |||||
27 | 1 | 0s | my %ops_seen; | ||
28 | 1 | 41µs | @ops_seen{ map split(/ /), values %ops } = (); | ||
29 | |||||
30 | sub nil {} | ||||
31 | |||||
32 | # spent 207µs within overload::OVERLOAD which was called 14 times, avg 15µs/call:
# 14 times (207µs+0s) by overload::import at line 61, avg 15µs/call | ||||
33 | 14 | 0s | my $package = shift; | ||
34 | 14 | 17µs | my %arg = @_; | ||
35 | 14 | 6µs | my $sub; | ||
36 | 14 | 35µs | *{$package . "::(("} = \&nil; # Make it findable via fetchmethod. | ||
37 | 14 | 65µs | for (keys %arg) { | ||
38 | 43 | 17µs | if ($_ eq 'fallback') { | ||
39 | 11 | 19µs | for my $sym (*{$package . "::()"}) { | ||
40 | 11 | 4µs | *$sym = \&nil; # Make it findable via fetchmethod. | ||
41 | 11 | 9µs | $$sym = $arg{$_}; | ||
42 | } | ||||
43 | } else { | ||||
44 | warnings::warnif("overload arg '$_' is invalid") | ||||
45 | 32 | 10µs | unless exists $ops_seen{$_}; | ||
46 | 32 | 9µs | $sub = $arg{$_}; | ||
47 | 32 | 6µs | if (not ref $sub) { | ||
48 | 1 | 2µs | $ {$package . "::(" . $_} = $sub; | ||
49 | 1 | 0s | $sub = \&nil; | ||
50 | } | ||||
51 | #print STDERR "Setting '$ {'package'}::\cO$_' to \\&'$sub'.\n"; | ||||
52 | 32 | 35µs | *{$package . "::(" . $_} = \&{ $sub }; | ||
53 | } | ||||
54 | } | ||||
55 | } | ||||
56 | |||||
57 | # spent 301µs (94+207) within overload::import which was called 14 times, avg 22µs/call:
# once (11µs+21µs) by Path::Tiny::Error::BEGIN@2415 at line 2415 of Path/Tiny.pm
# once (10µs+20µs) by YAML::PP::Preserve::Scalar::BEGIN@377 at line 381 of YAML/PP.pm
# once (10µs+19µs) by Getopt::Long::CallBack::BEGIN@1573 at line 1574 of Getopt/Long.pm
# once (5µs+22µs) by Path::Tiny::BEGIN@29 at line 33 of Path/Tiny.pm
# once (7µs+19µs) by JSON::Schema::Modern::Result::BEGIN@29 at line 33 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Result.pm
# once (7µs+15µs) by JSON::PP::BEGIN@12 at line 11 of JSON/PP/Boolean.pm
# once (6µs+13µs) by Mojo::URL::BEGIN@3 at line 3 of Mojo/URL.pm
# once (6µs+13µs) by JSON::Schema::Modern::Error::BEGIN@24 at line 24 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Error.pm
# once (6µs+12µs) by Pod::Simple::LinkSection::BEGIN@11 at line 17 of Pod/Simple/LinkSection.pm
# once (5µs+13µs) by Mojo::Parameters::BEGIN@3 at line 3 of Mojo/Parameters.pm
# once (5µs+12µs) by Mojo::Path::BEGIN@3 at line 3 of Mojo/Path.pm
# once (6µs+10µs) by YAML::PP::Exception::BEGIN@7 at line 7 of YAML/PP/Exception.pm
# once (7µs+9µs) by Cpanel::JSON::XS::BEGIN@2334 at line 2342 of Cpanel/JSON/XS.pm
# once (3µs+9µs) by Cpanel::JSON::XS::BEGIN@2334 at line 2371 of Cpanel/JSON/XS.pm | ||||
58 | 14 | 16µs | my $package = (caller())[0]; | ||
59 | # *{$package . "::OVERLOAD"} = \&OVERLOAD; | ||||
60 | 14 | 4µs | shift; | ||
61 | 14 | 63µs | 14 | 207µs | $package->overload::OVERLOAD(@_); # spent 207µs making 14 calls to overload::OVERLOAD, avg 15µs/call |
62 | } | ||||
63 | |||||
64 | # spent 18µs within overload::unimport which was called:
# once (18µs+0s) by JSON::PP::BEGIN@12 at line 6 of JSON/PP/Boolean.pm | ||||
65 | 1 | 1µs | my $package = (caller())[0]; | ||
66 | 1 | 0s | shift; | ||
67 | 1 | 3µs | *{$package . "::(("} = \&nil; | ||
68 | 1 | 5µs | for (@_) { | ||
69 | warnings::warnif("overload arg '$_' is invalid") | ||||
70 | 4 | 2µs | unless exists $ops_seen{$_}; | ||
71 | 4 | 9µs | delete $ {$package . "::"}{$_ eq 'fallback' ? '()' : "(" .$_}; | ||
72 | } | ||||
73 | } | ||||
74 | |||||
75 | sub Overloaded { | ||||
76 | my $package = shift; | ||||
77 | $package = ref $package if ref $package; | ||||
78 | mycan ($package, '()') || mycan ($package, '(('); | ||||
79 | } | ||||
80 | |||||
81 | sub ov_method { | ||||
82 | my $globref = shift; | ||||
83 | return undef unless $globref; | ||||
84 | my $sub = \&{*$globref}; | ||||
85 | 2 | 108µs | 2 | 23µs | # spent 15µs (7+8) within overload::BEGIN@85 which was called:
# once (7µs+8µs) by Cpanel::JSON::XS::BEGIN@2334 at line 85 # spent 15µs making 1 call to overload::BEGIN@85
# spent 8µs making 1 call to overloading::unimport |
86 | return $sub if $sub != \&nil; | ||||
87 | return shift->can($ {*$globref}); | ||||
88 | } | ||||
89 | |||||
90 | sub OverloadedStringify { | ||||
91 | my $package = shift; | ||||
92 | $package = ref $package if ref $package; | ||||
93 | #$package->can('(""') | ||||
94 | ov_method mycan($package, '(""'), $package | ||||
95 | or ov_method mycan($package, '(0+'), $package | ||||
96 | or ov_method mycan($package, '(bool'), $package | ||||
97 | or ov_method mycan($package, '(nomethod'), $package; | ||||
98 | } | ||||
99 | |||||
100 | sub Method { | ||||
101 | my $package = shift; | ||||
102 | if(ref $package) { | ||||
103 | local $@; | ||||
104 | local $!; | ||||
105 | $package = builtin::blessed($package); | ||||
106 | return undef if !defined $package; | ||||
107 | } | ||||
108 | #my $meth = $package->can('(' . shift); | ||||
109 | ov_method mycan($package, '(' . shift), $package; | ||||
110 | #return $meth if $meth ne \&nil; | ||||
111 | #return $ {*{$meth}}; | ||||
112 | } | ||||
113 | |||||
114 | sub AddrRef { | ||||
115 | 2 | 91µs | 2 | 13µs | # spent 8µs (3+5) within overload::BEGIN@115 which was called:
# once (3µs+5µs) by Cpanel::JSON::XS::BEGIN@2334 at line 115 # spent 8µs making 1 call to overload::BEGIN@115
# spent 5µs making 1 call to overloading::unimport |
116 | "$_[0]"; | ||||
117 | } | ||||
118 | |||||
119 | 1 | 1µs | *StrVal = *AddrRef; | ||
120 | |||||
121 | sub mycan { # Real can would leave stubs. | ||||
122 | my ($package, $meth) = @_; | ||||
123 | |||||
124 | local $@; | ||||
125 | local $!; | ||||
126 | require mro; | ||||
127 | |||||
128 | my $mro = mro::get_linear_isa($package); | ||||
129 | foreach my $p (@$mro) { | ||||
130 | my $fqmeth = $p . q{::} . $meth; | ||||
131 | return \*{$fqmeth} if defined &{$fqmeth}; | ||||
132 | } | ||||
133 | |||||
134 | return undef; | ||||
135 | } | ||||
136 | |||||
137 | 1 | 1µs | my %constants = ( | ||
138 | 'integer' => 0x1000, # HINT_NEW_INTEGER | ||||
139 | 'float' => 0x2000, # HINT_NEW_FLOAT | ||||
140 | 'binary' => 0x4000, # HINT_NEW_BINARY | ||||
141 | 'q' => 0x8000, # HINT_NEW_STRING | ||||
142 | 'qr' => 0x10000, # HINT_NEW_RE | ||||
143 | ); | ||||
144 | |||||
145 | 2 | 192µs | 2 | 135µs | # spent 71µs (7+64) within overload::BEGIN@145 which was called:
# once (7µs+64µs) by Cpanel::JSON::XS::BEGIN@2334 at line 145 # spent 71µs making 1 call to overload::BEGIN@145
# spent 64µs making 1 call to warnings::register::import |
146 | sub constant { | ||||
147 | # Arguments: what, sub | ||||
148 | while (@_) { | ||||
149 | if (@_ == 1) { | ||||
150 | warnings::warnif ("Odd number of arguments for overload::constant"); | ||||
151 | last; | ||||
152 | } | ||||
153 | elsif (!exists $constants {$_ [0]}) { | ||||
154 | warnings::warnif ("'$_[0]' is not an overloadable type"); | ||||
155 | } | ||||
156 | elsif (!ref $_ [1] || "$_[1]" !~ /(^|=)CODE\(0x[0-9a-f]+\)$/) { | ||||
157 | # Can't use C<ref $_[1] eq "CODE"> above as code references can be | ||||
158 | # blessed, and C<ref> would return the package the ref is blessed into. | ||||
159 | if (warnings::enabled) { | ||||
160 | $_ [1] = "undef" unless defined $_ [1]; | ||||
161 | warnings::warn ("'$_[1]' is not a code reference"); | ||||
162 | } | ||||
163 | } | ||||
164 | else { | ||||
165 | $^H{$_[0]} = $_[1]; | ||||
166 | $^H |= $constants{$_[0]}; | ||||
167 | } | ||||
168 | shift, shift; | ||||
169 | } | ||||
170 | } | ||||
171 | |||||
172 | sub remove_constant { | ||||
173 | # Arguments: what, sub | ||||
174 | while (@_) { | ||||
175 | delete $^H{$_[0]}; | ||||
176 | $^H &= ~ $constants{$_[0]}; | ||||
177 | shift, shift; | ||||
178 | } | ||||
179 | } | ||||
180 | |||||
181 | 1 | 8µs | 1; | ||
182 | |||||
183 | __END__ |