Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/5.13.5/overload.pm |
Statements | Executed 74 statements in 463µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 1 | 1 | 176µs | 178µs | OVERLOAD | overload::
4 | 4 | 3 | 59µs | 237µs | import | overload::
1 | 1 | 1 | 29µs | 211µs | BEGIN@145 | overload::
1 | 1 | 1 | 2µs | 2µs | CORE:match (opcode) | 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 | 2µs | our $VERSION = '1.10'; | ||
4 | |||||
5 | sub nil {} | ||||
6 | |||||
7 | # spent 178µs (176+2) within overload::OVERLOAD which was called 4 times, avg 44µs/call:
# 4 times (176µs+2µs) by overload::import at line 34, avg 44µs/call | ||||
8 | 32 | 114µs | $package = shift; | ||
9 | my %arg = @_; | ||||
10 | my ($sub, $fb); | ||||
11 | $ {$package . "::OVERLOAD"}{dummy}++; # Register with magic by touching. | ||||
12 | $fb = ${$package . "::()"}; # preserve old fallback value RT#68196 | ||||
13 | *{$package . "::()"} = \&nil; # Make it findable via fetchmethod. | ||||
14 | for (keys %arg) { | ||||
15 | 21 | 66µs | if ($_ eq 'fallback') { | ||
16 | $fb = $arg{$_}; | ||||
17 | } else { | ||||
18 | $sub = $arg{$_}; | ||||
19 | 2 | 6µs | 1 | 2µs | if (not ref $sub and $sub !~ /::/) { # spent 2µs making 1 call to overload::CORE:match |
20 | $ {$package . "::(" . $_} = $sub; | ||||
21 | $sub = \&nil; | ||||
22 | } | ||||
23 | #print STDERR "Setting `$ {'package'}::\cO$_' to \\&`$sub'.\n"; | ||||
24 | *{$package . "::(" . $_} = \&{ $sub }; | ||||
25 | } | ||||
26 | } | ||||
27 | ${$package . "::()"} = $fb; # Make it findable too (fallback only). | ||||
28 | } | ||||
29 | |||||
30 | # spent 237µs (59+178) within overload::import which was called 4 times, avg 59µs/call:
# once (14µs+66µs) by Getopt::Long::Descriptive::Usage::BEGIN@142 at line 152 of Getopt/Long/Descriptive/Usage.pm
# once (16µs+41µs) by Regexp::Common::BEGIN@163 at line 163 of Regexp/Common.pm
# once (15µs+35µs) by Regexp::Common::Entry::BEGIN@257 at line 268 of Regexp/Common.pm
# once (13µs+36µs) by Getopt::Long::CallBack::BEGIN@1489 at line 1489 of Getopt/Long.pm | ||||
31 | 12 | 59µs | $package = (caller())[0]; | ||
32 | # *{$package . "::OVERLOAD"} = \&OVERLOAD; | ||||
33 | shift; | ||||
34 | 4 | 178µs | $package->overload::OVERLOAD(@_); # spent 178µs making 4 calls to overload::OVERLOAD, avg 44µs/call | ||
35 | } | ||||
36 | |||||
37 | sub unimport { | ||||
38 | $package = (caller())[0]; | ||||
39 | ${$package . "::OVERLOAD"}{dummy}++; # Upgrade the table | ||||
40 | shift; | ||||
41 | for (@_) { | ||||
42 | if ($_ eq 'fallback') { | ||||
43 | undef $ {$package . "::()"}; | ||||
44 | } else { | ||||
45 | delete $ {$package . "::"}{"(" . $_}; | ||||
46 | } | ||||
47 | } | ||||
48 | } | ||||
49 | |||||
50 | sub Overloaded { | ||||
51 | my $package = shift; | ||||
52 | $package = ref $package if ref $package; | ||||
53 | $package->can('()'); | ||||
54 | } | ||||
55 | |||||
56 | sub ov_method { | ||||
57 | my $globref = shift; | ||||
58 | return undef unless $globref; | ||||
59 | my $sub = \&{*$globref}; | ||||
60 | return $sub if $sub ne \&nil; | ||||
61 | return shift->can($ {*$globref}); | ||||
62 | } | ||||
63 | |||||
64 | sub OverloadedStringify { | ||||
65 | my $package = shift; | ||||
66 | $package = ref $package if ref $package; | ||||
67 | #$package->can('(""') | ||||
68 | ov_method mycan($package, '(""'), $package | ||||
69 | or ov_method mycan($package, '(0+'), $package | ||||
70 | or ov_method mycan($package, '(bool'), $package | ||||
71 | or ov_method mycan($package, '(nomethod'), $package; | ||||
72 | } | ||||
73 | |||||
74 | sub Method { | ||||
75 | my $package = shift; | ||||
76 | if(ref $package) { | ||||
77 | local $@; | ||||
78 | local $!; | ||||
79 | require Scalar::Util; | ||||
80 | $package = Scalar::Util::blessed($package); | ||||
81 | return undef if !defined $package; | ||||
82 | } | ||||
83 | #my $meth = $package->can('(' . shift); | ||||
84 | ov_method mycan($package, '(' . shift), $package; | ||||
85 | #return $meth if $meth ne \&nil; | ||||
86 | #return $ {*{$meth}}; | ||||
87 | } | ||||
88 | |||||
89 | sub AddrRef { | ||||
90 | my $package = ref $_[0]; | ||||
91 | return "$_[0]" unless $package; | ||||
92 | |||||
93 | local $@; | ||||
94 | local $!; | ||||
95 | require Scalar::Util; | ||||
96 | my $class = Scalar::Util::blessed($_[0]); | ||||
97 | my $class_prefix = defined($class) ? "$class=" : ""; | ||||
98 | my $type = Scalar::Util::reftype($_[0]); | ||||
99 | my $addr = Scalar::Util::refaddr($_[0]); | ||||
100 | return sprintf("$class_prefix$type(0x%x)", $addr); | ||||
101 | } | ||||
102 | |||||
103 | 1 | 2µs | *StrVal = *AddrRef; | ||
104 | |||||
105 | sub mycan { # Real can would leave stubs. | ||||
106 | my ($package, $meth) = @_; | ||||
107 | |||||
108 | local $@; | ||||
109 | local $!; | ||||
110 | require mro; | ||||
111 | |||||
112 | my $mro = mro::get_linear_isa($package); | ||||
113 | foreach my $p (@$mro) { | ||||
114 | my $fqmeth = $p . q{::} . $meth; | ||||
115 | return \*{$fqmeth} if defined &{$fqmeth}; | ||||
116 | } | ||||
117 | |||||
118 | return undef; | ||||
119 | } | ||||
120 | |||||
121 | 1 | 3µs | %constants = ( | ||
122 | 'integer' => 0x1000, # HINT_NEW_INTEGER | ||||
123 | 'float' => 0x2000, # HINT_NEW_FLOAT | ||||
124 | 'binary' => 0x4000, # HINT_NEW_BINARY | ||||
125 | 'q' => 0x8000, # HINT_NEW_STRING | ||||
126 | 'qr' => 0x10000, # HINT_NEW_RE | ||||
127 | ); | ||||
128 | |||||
129 | 1 | 7µs | %ops = ( with_assign => "+ - * / % ** << >> x .", | ||
130 | assign => "+= -= *= /= %= **= <<= >>= x= .=", | ||||
131 | num_comparison => "< <= > >= == !=", | ||||
132 | '3way_comparison'=> "<=> cmp", | ||||
133 | str_comparison => "lt le gt ge eq ne", | ||||
134 | binary => '& &= | |= ^ ^=', | ||||
135 | unary => "neg ! ~", | ||||
136 | mutators => '++ --', | ||||
137 | func => "atan2 cos sin exp abs log sqrt int", | ||||
138 | conversion => 'bool "" 0+ qr', | ||||
139 | iterators => '<>', | ||||
140 | filetest => "-X", | ||||
141 | dereferencing => '${} @{} %{} &{} *{}', | ||||
142 | matching => '~~', | ||||
143 | special => 'nomethod fallback ='); | ||||
144 | |||||
145 | 2 | 196µs | 2 | 392µs | # spent 211µs (29+182) within overload::BEGIN@145 which was called:
# once (29µs+182µs) by Getopt::Long::CallBack::BEGIN@1489 at line 145 # spent 211µs making 1 call to overload::BEGIN@145
# spent 182µ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 | 7µs | 1; | ||
182 | |||||
183 | __END__ | ||||
# spent 2µs within overload::CORE:match which was called:
# once (2µs+0s) by overload::OVERLOAD at line 19 |