| Filename | /usr/share/perl/5.28/overload.pm |
| Statements | Executed 138 statements in 925µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 6 | 1 | 1 | 146µs | 146µs | overload::OVERLOAD |
| 6 | 6 | 4 | 74µs | 220µs | overload::import |
| 1 | 1 | 1 | 13µs | 22µs | overload::BEGIN@81 |
| 1 | 1 | 1 | 7µs | 11µs | overload::BEGIN@112 |
| 1 | 1 | 1 | 6µs | 40µs | overload::BEGIN@142 |
| 0 | 0 | 0 | 0s | 0s | overload::AddrRef |
| 0 | 0 | 0 | 0s | 0s | overload::Method |
| 0 | 0 | 0 | 0s | 0s | overload::Overloaded |
| 0 | 0 | 0 | 0s | 0s | overload::OverloadedStringify |
| 0 | 0 | 0 | 0s | 0s | overload::constant |
| 0 | 0 | 0 | 0s | 0s | overload::mycan |
| 0 | 0 | 0 | 0s | 0s | overload::nil |
| 0 | 0 | 0 | 0s | 0s | overload::ov_method |
| 0 | 0 | 0 | 0s | 0s | overload::remove_constant |
| 0 | 0 | 0 | 0s | 0s | overload::unimport |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package overload; | ||||
| 2 | |||||
| 3 | 1 | 300ns | our $VERSION = '1.30'; | ||
| 4 | |||||
| 5 | 1 | 8µ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 | 100ns | my %ops_seen; | ||
| 24 | 1 | 114µs | @ops_seen{ map split(/ /), values %ops } = (); | ||
| 25 | |||||
| 26 | sub nil {} | ||||
| 27 | |||||
| 28 | # spent 146µs within overload::OVERLOAD which was called 6 times, avg 24µs/call:
# 6 times (146µs+0s) by overload::import at line 57, avg 24µs/call | ||||
| 29 | 6 | 2µs | $package = shift; | ||
| 30 | 6 | 15µs | my %arg = @_; | ||
| 31 | 6 | 2µs | my $sub; | ||
| 32 | 6 | 26µs | *{$package . "::(("} = \&nil; # Make it findable via fetchmethod. | ||
| 33 | 6 | 53µs | for (keys %arg) { | ||
| 34 | 15 | 10µs | if ($_ eq 'fallback') { | ||
| 35 | 6 | 14µs | for my $sym (*{$package . "::()"}) { | ||
| 36 | 6 | 4µs | *$sym = \&nil; # Make it findable via fetchmethod. | ||
| 37 | 6 | 6µs | $$sym = $arg{$_}; | ||
| 38 | } | ||||
| 39 | } else { | ||||
| 40 | warnings::warnif("overload arg '$_' is invalid") | ||||
| 41 | 9 | 8µs | unless exists $ops_seen{$_}; | ||
| 42 | 9 | 4µs | $sub = $arg{$_}; | ||
| 43 | 9 | 2µs | if (not ref $sub) { | ||
| 44 | 4 | 9µs | $ {$package . "::(" . $_} = $sub; | ||
| 45 | 4 | 2µs | $sub = \&nil; | ||
| 46 | } | ||||
| 47 | #print STDERR "Setting '$ {'package'}::\cO$_' to \\&'$sub'.\n"; | ||||
| 48 | 9 | 16µs | *{$package . "::(" . $_} = \&{ $sub }; | ||
| 49 | } | ||||
| 50 | } | ||||
| 51 | } | ||||
| 52 | |||||
| 53 | # spent 220µs (74+146) within overload::import which was called 6 times, avg 37µs/call:
# once (13µs+32µs) by File::Temp::Dir::BEGIN@1543 at line 1543 of File/Temp.pm
# once (19µs+25µs) by Getopt::Long::CallBack::BEGIN@1568 at line 1568 of Getopt/Long.pm
# once (12µs+26µs) by File::Temp::BEGIN@32 at line 32 of File/Temp.pm
# once (10µs+26µs) by Template::Exception::BEGIN@27 at line 27 of Template/Exception.pm
# once (12µs+21µs) by Path::Tiny::Error::BEGIN@2133 at line 2133 of Path/Tiny.pm
# once (7µs+16µs) by Path::Tiny::BEGIN@29 at line 32 of Path/Tiny.pm | ||||
| 54 | 6 | 14µs | $package = (caller())[0]; | ||
| 55 | # *{$package . "::OVERLOAD"} = \&OVERLOAD; | ||||
| 56 | 6 | 1µs | shift; | ||
| 57 | 6 | 36µs | 6 | 146µs | $package->overload::OVERLOAD(@_); # spent 146µs making 6 calls to overload::OVERLOAD, avg 24µs/call |
| 58 | } | ||||
| 59 | |||||
| 60 | sub unimport { | ||||
| 61 | $package = (caller())[0]; | ||||
| 62 | shift; | ||||
| 63 | *{$package . "::(("} = \&nil; | ||||
| 64 | for (@_) { | ||||
| 65 | warnings::warnif("overload arg '$_' is invalid") | ||||
| 66 | unless exists $ops_seen{$_}; | ||||
| 67 | delete $ {$package . "::"}{$_ eq 'fallback' ? '()' : "(" .$_}; | ||||
| 68 | } | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | sub Overloaded { | ||||
| 72 | my $package = shift; | ||||
| 73 | $package = ref $package if ref $package; | ||||
| 74 | mycan ($package, '()') || mycan ($package, '(('); | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | sub ov_method { | ||||
| 78 | my $globref = shift; | ||||
| 79 | return undef unless $globref; | ||||
| 80 | my $sub = \&{*$globref}; | ||||
| 81 | 2 | 187µs | 2 | 31µs | # spent 22µs (13+9) within overload::BEGIN@81 which was called:
# once (13µs+9µs) by Path::Tiny::BEGIN@29 at line 81 # spent 22µs making 1 call to overload::BEGIN@81
# spent 9µs making 1 call to overloading::unimport |
| 82 | return $sub if $sub != \&nil; | ||||
| 83 | return shift->can($ {*$globref}); | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | sub OverloadedStringify { | ||||
| 87 | my $package = shift; | ||||
| 88 | $package = ref $package if ref $package; | ||||
| 89 | #$package->can('(""') | ||||
| 90 | ov_method mycan($package, '(""'), $package | ||||
| 91 | or ov_method mycan($package, '(0+'), $package | ||||
| 92 | or ov_method mycan($package, '(bool'), $package | ||||
| 93 | or ov_method mycan($package, '(nomethod'), $package; | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | sub Method { | ||||
| 97 | my $package = shift; | ||||
| 98 | if(ref $package) { | ||||
| 99 | local $@; | ||||
| 100 | local $!; | ||||
| 101 | require Scalar::Util; | ||||
| 102 | $package = Scalar::Util::blessed($package); | ||||
| 103 | return undef if !defined $package; | ||||
| 104 | } | ||||
| 105 | #my $meth = $package->can('(' . shift); | ||||
| 106 | ov_method mycan($package, '(' . shift), $package; | ||||
| 107 | #return $meth if $meth ne \&nil; | ||||
| 108 | #return $ {*{$meth}}; | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | sub AddrRef { | ||||
| 112 | 2 | 131µs | 2 | 16µs | # spent 11µs (7+5) within overload::BEGIN@112 which was called:
# once (7µs+5µs) by Path::Tiny::BEGIN@29 at line 112 # spent 11µs making 1 call to overload::BEGIN@112
# spent 5µs making 1 call to overloading::unimport |
| 113 | "$_[0]"; | ||||
| 114 | } | ||||
| 115 | |||||
| 116 | 1 | 1µs | *StrVal = *AddrRef; | ||
| 117 | |||||
| 118 | sub mycan { # Real can would leave stubs. | ||||
| 119 | my ($package, $meth) = @_; | ||||
| 120 | |||||
| 121 | local $@; | ||||
| 122 | local $!; | ||||
| 123 | require mro; | ||||
| 124 | |||||
| 125 | my $mro = mro::get_linear_isa($package); | ||||
| 126 | foreach my $p (@$mro) { | ||||
| 127 | my $fqmeth = $p . q{::} . $meth; | ||||
| 128 | return \*{$fqmeth} if defined &{$fqmeth}; | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | return undef; | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 1 | 2µs | %constants = ( | ||
| 135 | 'integer' => 0x1000, # HINT_NEW_INTEGER | ||||
| 136 | 'float' => 0x2000, # HINT_NEW_FLOAT | ||||
| 137 | 'binary' => 0x4000, # HINT_NEW_BINARY | ||||
| 138 | 'q' => 0x8000, # HINT_NEW_STRING | ||||
| 139 | 'qr' => 0x10000, # HINT_NEW_RE | ||||
| 140 | ); | ||||
| 141 | |||||
| 142 | 2 | 246µs | 2 | 74µs | # spent 40µs (6+34) within overload::BEGIN@142 which was called:
# once (6µs+34µs) by Path::Tiny::BEGIN@29 at line 142 # spent 40µs making 1 call to overload::BEGIN@142
# spent 34µs making 1 call to warnings::register::import |
| 143 | sub constant { | ||||
| 144 | # Arguments: what, sub | ||||
| 145 | while (@_) { | ||||
| 146 | if (@_ == 1) { | ||||
| 147 | warnings::warnif ("Odd number of arguments for overload::constant"); | ||||
| 148 | last; | ||||
| 149 | } | ||||
| 150 | elsif (!exists $constants {$_ [0]}) { | ||||
| 151 | warnings::warnif ("'$_[0]' is not an overloadable type"); | ||||
| 152 | } | ||||
| 153 | elsif (!ref $_ [1] || "$_[1]" !~ /(^|=)CODE\(0x[0-9a-f]+\)$/) { | ||||
| 154 | # Can't use C<ref $_[1] eq "CODE"> above as code references can be | ||||
| 155 | # blessed, and C<ref> would return the package the ref is blessed into. | ||||
| 156 | if (warnings::enabled) { | ||||
| 157 | $_ [1] = "undef" unless defined $_ [1]; | ||||
| 158 | warnings::warn ("'$_[1]' is not a code reference"); | ||||
| 159 | } | ||||
| 160 | } | ||||
| 161 | else { | ||||
| 162 | $^H{$_[0]} = $_[1]; | ||||
| 163 | $^H |= $constants{$_[0]}; | ||||
| 164 | } | ||||
| 165 | shift, shift; | ||||
| 166 | } | ||||
| 167 | } | ||||
| 168 | |||||
| 169 | sub remove_constant { | ||||
| 170 | # Arguments: what, sub | ||||
| 171 | while (@_) { | ||||
| 172 | delete $^H{$_[0]}; | ||||
| 173 | $^H &= ~ $constants{$_[0]}; | ||||
| 174 | shift, shift; | ||||
| 175 | } | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | 1 | 11µs | 1; | ||
| 179 | |||||
| 180 | __END__ |