| Filename | /usr/share/perl/5.18/Carp.pm |
| Statements | Executed 456 statements in 2.56ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 6 | 1 | 1 | 89µs | 123µs | Carp::format_arg |
| 3 | 1 | 1 | 86µs | 220µs | Carp::caller_info |
| 3 | 1 | 1 | 53µs | 133µs | Carp::short_error_loc |
| 3 | 1 | 1 | 29µs | 249µs | Carp::ret_summary |
| 6 | 1 | 1 | 27µs | 43µs | Carp::get_status |
| 18 | 3 | 1 | 26µs | 26µs | Carp::_cgc |
| 3 | 1 | 1 | 24µs | 465µs | Carp::croak |
| 6 | 2 | 1 | 23µs | 66µs | Carp::trusts |
| 3 | 1 | 1 | 22µs | 428µs | Carp::shortmess |
| 6 | 1 | 1 | 16µs | 16µs | Carp::trusts_directly |
| 3 | 1 | 1 | 16µs | 398µs | Carp::shortmess_heavy |
| 1 | 1 | 1 | 15µs | 15µs | Carp::BEGIN@3 |
| 12 | 2 | 1 | 10µs | 10µs | Carp::CORE:subst (opcode) |
| 6 | 1 | 1 | 9µs | 9µs | Carp::str_len_trim |
| 6 | 1 | 1 | 8µs | 8µs | Carp::CORE:match (opcode) |
| 1 | 1 | 1 | 7µs | 22µs | Carp::BEGIN@434 |
| 3 | 1 | 1 | 7µs | 7µs | Carp::get_subname |
| 1 | 1 | 1 | 7µs | 12µs | Carp::BEGIN@5 |
| 1 | 1 | 1 | 6µs | 15µs | Carp::BEGIN@433 |
| 1 | 1 | 1 | 6µs | 14µs | Carp::BEGIN@441 |
| 1 | 1 | 1 | 6µs | 6µs | Carp::BEGIN@105 |
| 1 | 1 | 1 | 5µs | 12µs | Carp::BEGIN@67 |
| 1 | 1 | 1 | 5µs | 5µs | Carp::BEGIN@17 |
| 1 | 1 | 1 | 5µs | 5µs | Carp::BEGIN@7 |
| 1 | 1 | 1 | 5µs | 14µs | Carp::BEGIN@4 |
| 1 | 1 | 1 | 5µs | 12µs | Carp::BEGIN@448 |
| 1 | 1 | 1 | 5µs | 11µs | Carp::BEGIN@18 |
| 1 | 1 | 1 | 4µs | 10µs | Carp::BEGIN@8 |
| 0 | 0 | 0 | 0s | 0s | Carp::__ANON__[:13] |
| 0 | 0 | 0 | 0s | 0s | Carp::__ANON__[:23] |
| 0 | 0 | 0 | 0s | 0s | Carp::carp |
| 0 | 0 | 0 | 0s | 0s | Carp::cluck |
| 0 | 0 | 0 | 0s | 0s | Carp::confess |
| 0 | 0 | 0 | 0s | 0s | Carp::export_fail |
| 0 | 0 | 0 | 0s | 0s | Carp::long_error_loc |
| 0 | 0 | 0 | 0s | 0s | Carp::longmess |
| 0 | 0 | 0 | 0s | 0s | Carp::longmess_heavy |
| 0 | 0 | 0 | 0s | 0s | Carp::ret_backtrace |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Carp; | ||||
| 2 | |||||
| 3 | 3 | 40µs | 1 | 15µs | # spent 15µs within Carp::BEGIN@3 which was called:
# once (15µs+0s) by Module::Pluggable::Object::BEGIN@7 at line 3 # spent 15µs making 1 call to Carp::BEGIN@3 |
| 4 | 2 | 21µs | 2 | 23µs | # spent 14µs (5+9) within Carp::BEGIN@4 which was called:
# once (5µs+9µs) by Module::Pluggable::Object::BEGIN@7 at line 4 # spent 14µs making 1 call to Carp::BEGIN@4
# spent 9µs making 1 call to strict::import |
| 5 | 2 | 22µs | 2 | 17µs | # spent 12µs (7+5) within Carp::BEGIN@5 which was called:
# once (7µs+5µs) by Module::Pluggable::Object::BEGIN@7 at line 5 # spent 12µs making 1 call to Carp::BEGIN@5
# spent 5µs making 1 call to warnings::import |
| 6 | |||||
| 7 | # spent 5µs within Carp::BEGIN@7 which was called:
# once (5µs+0s) by Module::Pluggable::Object::BEGIN@7 at line 15 | ||||
| 8 | 2 | 68µs | 2 | 17µs | # spent 10µs (4+6) within Carp::BEGIN@8 which was called:
# once (4µs+6µs) by Module::Pluggable::Object::BEGIN@7 at line 8 # spent 10µs making 1 call to Carp::BEGIN@8
# spent 6µs making 1 call to strict::unimport |
| 9 | 1 | 6µs | if(exists($::{"utf8::"}) && exists(*{$::{"utf8::"}}{HASH}->{"is_utf8"}) && | ||
| 10 | defined(*{*{$::{"utf8::"}}{HASH}->{"is_utf8"}}{CODE})) { | ||||
| 11 | *is_utf8 = \&{"utf8::is_utf8"}; | ||||
| 12 | } else { | ||||
| 13 | *is_utf8 = sub { 0 }; | ||||
| 14 | } | ||||
| 15 | 1 | 21µs | 1 | 5µs | } # spent 5µs making 1 call to Carp::BEGIN@7 |
| 16 | |||||
| 17 | # spent 5µs within Carp::BEGIN@17 which was called:
# once (5µs+0s) by Module::Pluggable::Object::BEGIN@7 at line 25 | ||||
| 18 | 2 | 58µs | 2 | 18µs | # spent 11µs (5+7) within Carp::BEGIN@18 which was called:
# once (5µs+7µs) by Module::Pluggable::Object::BEGIN@7 at line 18 # spent 11µs making 1 call to Carp::BEGIN@18
# spent 7µs making 1 call to strict::unimport |
| 19 | 1 | 9µs | if(exists($::{"utf8::"}) && exists(*{$::{"utf8::"}}{HASH}->{"downgrade"}) && | ||
| 20 | defined(*{*{$::{"utf8::"}}{HASH}->{"downgrade"}}{CODE})) { | ||||
| 21 | *downgrade = \&{"utf8::downgrade"}; | ||||
| 22 | } else { | ||||
| 23 | *downgrade = sub {}; | ||||
| 24 | } | ||||
| 25 | 1 | 143µs | 1 | 5µs | } # spent 5µs making 1 call to Carp::BEGIN@17 |
| 26 | |||||
| 27 | 1 | 500ns | our $VERSION = '1.29'; | ||
| 28 | |||||
| 29 | 1 | 100ns | our $MaxEvalLen = 0; | ||
| 30 | 1 | 100ns | our $Verbose = 0; | ||
| 31 | 1 | 100ns | our $CarpLevel = 0; | ||
| 32 | 1 | 100ns | our $MaxArgLen = 64; # How much of each argument to print. 0 = all. | ||
| 33 | 1 | 100ns | our $MaxArgNums = 8; # How many arguments to print. 0 = all. | ||
| 34 | |||||
| 35 | 1 | 1µs | require Exporter; | ||
| 36 | 1 | 6µs | our @ISA = ('Exporter'); | ||
| 37 | 1 | 700ns | our @EXPORT = qw(confess croak carp); | ||
| 38 | 1 | 500ns | our @EXPORT_OK = qw(cluck verbose longmess shortmess); | ||
| 39 | 1 | 200ns | our @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode | ||
| 40 | |||||
| 41 | # The members of %Internal are packages that are internal to perl. | ||||
| 42 | # Carp will not report errors from within these packages if it | ||||
| 43 | # can. The members of %CarpInternal are internal to Perl's warning | ||||
| 44 | # system. Carp will not report errors from within these packages | ||||
| 45 | # either, and will not report calls *to* these packages for carp and | ||||
| 46 | # croak. They replace $CarpLevel, which is deprecated. The | ||||
| 47 | # $Max(EvalLen|(Arg(Len|Nums)) variables are used to specify how the eval | ||||
| 48 | # text and function arguments should be formatted when printed. | ||||
| 49 | |||||
| 50 | 1 | 100ns | our %CarpInternal; | ||
| 51 | 1 | 100ns | our %Internal; | ||
| 52 | |||||
| 53 | # disable these by default, so they can live w/o require Carp | ||||
| 54 | 1 | 500ns | $CarpInternal{Carp}++; | ||
| 55 | 1 | 100ns | $CarpInternal{warnings}++; | ||
| 56 | 1 | 100ns | $Internal{Exporter}++; | ||
| 57 | 1 | 200ns | $Internal{'Exporter::Heavy'}++; | ||
| 58 | |||||
| 59 | # if the caller specifies verbose usage ("perl -MCarp=verbose script.pl") | ||||
| 60 | # then the following method will be called by the Exporter which knows | ||||
| 61 | # to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word | ||||
| 62 | # 'verbose'. | ||||
| 63 | |||||
| 64 | sub export_fail { shift; $Verbose = shift if $_[0] eq 'verbose'; @_ } | ||||
| 65 | |||||
| 66 | sub _cgc { | ||||
| 67 | 2 | 258µs | 2 | 20µs | # spent 12µs (5+7) within Carp::BEGIN@67 which was called:
# once (5µs+7µs) by Module::Pluggable::Object::BEGIN@7 at line 67 # spent 12µs making 1 call to Carp::BEGIN@67
# spent 7µs making 1 call to strict::unimport |
| 68 | 18 | 18µs | return \&{"CORE::GLOBAL::caller"} if defined &{"CORE::GLOBAL::caller"}; | ||
| 69 | 18 | 26µs | return; | ||
| 70 | } | ||||
| 71 | |||||
| 72 | sub longmess { | ||||
| 73 | # Icky backwards compatibility wrapper. :-( | ||||
| 74 | # | ||||
| 75 | # The story is that the original implementation hard-coded the | ||||
| 76 | # number of call levels to go back, so calls to longmess were off | ||||
| 77 | # by one. Other code began calling longmess and expecting this | ||||
| 78 | # behaviour, so the replacement has to emulate that behaviour. | ||||
| 79 | my $cgc = _cgc(); | ||||
| 80 | my $call_pack = $cgc ? $cgc->() : caller(); | ||||
| 81 | if ( $Internal{$call_pack} or $CarpInternal{$call_pack} ) { | ||||
| 82 | return longmess_heavy(@_); | ||||
| 83 | } | ||||
| 84 | else { | ||||
| 85 | local $CarpLevel = $CarpLevel + 1; | ||||
| 86 | return longmess_heavy(@_); | ||||
| 87 | } | ||||
| 88 | } | ||||
| 89 | |||||
| 90 | 1 | 100ns | our @CARP_NOT; | ||
| 91 | |||||
| 92 | # spent 428µs (22+406) within Carp::shortmess which was called 3 times, avg 143µs/call:
# 3 times (22µs+406µs) by Carp::croak at line 100, avg 143µs/call | ||||
| 93 | 3 | 4µs | 3 | 8µs | my $cgc = _cgc(); # spent 8µs making 3 calls to Carp::_cgc, avg 3µs/call |
| 94 | |||||
| 95 | # Icky backwards compatibility wrapper. :-( | ||||
| 96 | 3 | 5µs | local @CARP_NOT = $cgc ? $cgc->() : caller(); | ||
| 97 | 3 | 8µs | 3 | 398µs | shortmess_heavy(@_); # spent 398µs making 3 calls to Carp::shortmess_heavy, avg 133µs/call |
| 98 | } | ||||
| 99 | |||||
| 100 | 3 | 48µs | 6 | 441µs | # spent 465µs (24+441) within Carp::croak which was called 3 times, avg 155µs/call:
# 3 times (24µs+441µs) by Exporter::Heavy::heavy_export at line 140 of Exporter/Heavy.pm, avg 155µs/call # spent 428µs making 3 calls to Carp::shortmess, avg 143µs/call
# spent 13µs making 3 calls to Exporter::Heavy::__ANON__[Exporter/Heavy.pm:44], avg 4µs/call |
| 101 | sub confess { die longmess @_ } | ||||
| 102 | sub carp { warn shortmess @_ } | ||||
| 103 | sub cluck { warn longmess @_ } | ||||
| 104 | |||||
| 105 | # spent 6µs within Carp::BEGIN@105 which was called:
# once (6µs+0s) by Module::Pluggable::Object::BEGIN@7 at line 112 | ||||
| 106 | 1 | 6µs | if("$]" >= 5.015002 || ("$]" >= 5.014002 && "$]" < 5.015) || | ||
| 107 | ("$]" >= 5.012005 && "$]" < 5.013)) { | ||||
| 108 | *CALLER_OVERRIDE_CHECK_OK = sub () { 1 }; | ||||
| 109 | } else { | ||||
| 110 | *CALLER_OVERRIDE_CHECK_OK = sub () { 0 }; | ||||
| 111 | } | ||||
| 112 | 1 | 1.26ms | 1 | 6µs | } # spent 6µs making 1 call to Carp::BEGIN@105 |
| 113 | |||||
| 114 | # spent 220µs (86+134) within Carp::caller_info which was called 3 times, avg 73µs/call:
# 3 times (86µs+134µs) by Carp::ret_summary at line 342, avg 73µs/call | ||||
| 115 | 3 | 2µs | my $i = shift(@_) + 1; | ||
| 116 | 3 | 500ns | my %call_info; | ||
| 117 | 3 | 2µs | 3 | 4µs | my $cgc = _cgc(); # spent 4µs making 3 calls to Carp::_cgc, avg 1µs/call |
| 118 | { | ||||
| 119 | # Some things override caller() but forget to implement the | ||||
| 120 | # @DB::args part of it, which we need. We check for this by | ||||
| 121 | # pre-populating @DB::args with a sentinel which no-one else | ||||
| 122 | # has the address of, so that we can detect whether @DB::args | ||||
| 123 | # has been properly populated. However, on earlier versions | ||||
| 124 | # of perl this check tickles a bug in CORE::caller() which | ||||
| 125 | # leaks memory. So we only check on fixed perls. | ||||
| 126 | 6 | 4µs | @DB::args = \$i if CALLER_OVERRIDE_CHECK_OK; | ||
| 127 | package DB; | ||||
| 128 | |||||
| 129 | 3 | 15µs | |||
| - - | |||||
| 133 | 3 | 1µs | unless ( defined $call_info{file} ) { | ||
| 134 | return (); | ||||
| 135 | } | ||||
| 136 | |||||
| 137 | 3 | 4µs | 3 | 7µs | my $sub_name = Carp::get_subname( \%call_info ); # spent 7µs making 3 calls to Carp::get_subname, avg 2µs/call |
| 138 | 3 | 1µs | if ( $call_info{has_args} ) { | ||
| 139 | 3 | 300ns | my @args; | ||
| 140 | 3 | 1µs | if (CALLER_OVERRIDE_CHECK_OK && @DB::args == 1 | ||
| 141 | && ref $DB::args[0] eq ref \$i | ||||
| 142 | && $DB::args[0] == \$i ) { | ||||
| 143 | @DB::args = (); # Don't let anyone see the address of $i | ||||
| 144 | local $@; | ||||
| 145 | my $where = eval { | ||||
| 146 | my $func = $cgc or return ''; | ||||
| 147 | my $gv = | ||||
| 148 | *{ | ||||
| 149 | ( $::{"B::"} || return '') # B stash | ||||
| 150 | ->{svref_2object} || return '' # entry in stash | ||||
| 151 | }{CODE} # coderef in entry | ||||
| 152 | ->($func)->GV; | ||||
| 153 | my $package = $gv->STASH->NAME; | ||||
| 154 | my $subname = $gv->NAME; | ||||
| 155 | return unless defined $package && defined $subname; | ||||
| 156 | |||||
| 157 | # returning CORE::GLOBAL::caller isn't useful for tracing the cause: | ||||
| 158 | return if $package eq 'CORE::GLOBAL' && $subname eq 'caller'; | ||||
| 159 | " in &${package}::$subname"; | ||||
| 160 | } || ''; | ||||
| 161 | @args | ||||
| 162 | = "** Incomplete caller override detected$where; \@DB::args were not set **"; | ||||
| 163 | } | ||||
| 164 | else { | ||||
| 165 | 3 | 2µs | @args = @DB::args; | ||
| 166 | 3 | 300ns | my $overflow; | ||
| 167 | 3 | 1µs | if ( $MaxArgNums and @args > $MaxArgNums ) | ||
| 168 | { # More than we want to show? | ||||
| 169 | $#args = $MaxArgNums; | ||||
| 170 | $overflow = 1; | ||||
| 171 | } | ||||
| 172 | |||||
| 173 | 9 | 11µs | 6 | 123µs | @args = map { Carp::format_arg($_) } @args; # spent 123µs making 6 calls to Carp::format_arg, avg 20µs/call |
| 174 | |||||
| 175 | 3 | 800ns | if ($overflow) { | ||
| 176 | push @args, '...'; | ||||
| 177 | } | ||||
| 178 | } | ||||
| 179 | |||||
| 180 | # Push the args onto the subroutine | ||||
| 181 | 3 | 17µs | $sub_name .= '(' . join( ', ', @args ) . ')'; | ||
| 182 | } | ||||
| 183 | 3 | 2µs | $call_info{sub_name} = $sub_name; | ||
| 184 | 3 | 14µs | return wantarray() ? %call_info : \%call_info; | ||
| 185 | } | ||||
| 186 | |||||
| 187 | # Transform an argument to a function into a string. | ||||
| 188 | # spent 123µs (89+34) within Carp::format_arg which was called 6 times, avg 20µs/call:
# 6 times (89µs+34µs) by Carp::caller_info at line 173, avg 20µs/call | ||||
| 189 | 6 | 3µs | my $arg = shift; | ||
| 190 | 6 | 1µs | if ( ref($arg) ) { | ||
| 191 | $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg"; | ||||
| 192 | } | ||||
| 193 | 6 | 2µs | if ( defined($arg) ) { | ||
| 194 | 6 | 13µs | 6 | 2µs | $arg =~ s/'/\\'/g; # spent 2µs making 6 calls to Carp::CORE:subst, avg 333ns/call |
| 195 | 6 | 5µs | 6 | 9µs | $arg = str_len_trim( $arg, $MaxArgLen ); # spent 9µs making 6 calls to Carp::str_len_trim, avg 1µs/call |
| 196 | |||||
| 197 | # Quote it? | ||||
| 198 | # Downgrade, and use [0-9] rather than \d, to avoid loading | ||||
| 199 | # Unicode tables, which would be liable to fail if we're | ||||
| 200 | # processing a syntax error. | ||||
| 201 | 6 | 12µs | 6 | 3µs | downgrade($arg, 1); # spent 3µs making 6 calls to utf8::downgrade, avg 550ns/call |
| 202 | 6 | 39µs | 6 | 8µs | $arg = "'$arg'" unless $arg =~ /^-?[0-9.]+\z/; # spent 8µs making 6 calls to Carp::CORE:match, avg 1µs/call |
| 203 | } | ||||
| 204 | else { | ||||
| 205 | $arg = 'undef'; | ||||
| 206 | } | ||||
| 207 | |||||
| 208 | # The following handling of "control chars" is direct from | ||||
| 209 | # the original code - it is broken on Unicode though. | ||||
| 210 | # Suggestions? | ||||
| 211 | is_utf8($arg) | ||||
| 212 | 6 | 28µs | 12 | 12µs | or $arg =~ s/([[:cntrl:]]|[[:^ascii:]])/sprintf("\\x{%x}",ord($1))/eg; # spent 8µs making 6 calls to Carp::CORE:subst, avg 1µs/call
# spent 3µs making 6 calls to utf8::is_utf8, avg 550ns/call |
| 213 | 6 | 9µs | return $arg; | ||
| 214 | } | ||||
| 215 | |||||
| 216 | # Takes an inheritance cache and a package and returns | ||||
| 217 | # an anon hash of known inheritances and anon array of | ||||
| 218 | # inheritances which consequences have not been figured | ||||
| 219 | # for. | ||||
| 220 | # spent 43µs (27+16) within Carp::get_status which was called 6 times, avg 7µs/call:
# 6 times (27µs+16µs) by Carp::trusts at line 415, avg 7µs/call | ||||
| 221 | 6 | 700ns | my $cache = shift; | ||
| 222 | 6 | 700ns | my $pkg = shift; | ||
| 223 | 6 | 14µs | 6 | 16µs | $cache->{$pkg} ||= [ { $pkg => $pkg }, [ trusts_directly($pkg) ] ]; # spent 16µs making 6 calls to Carp::trusts_directly, avg 3µs/call |
| 224 | 6 | 12µs | return @{ $cache->{$pkg} }; | ||
| 225 | } | ||||
| 226 | |||||
| 227 | # Takes the info from caller() and figures out the name of | ||||
| 228 | # the sub/require/eval | ||||
| 229 | # spent 7µs within Carp::get_subname which was called 3 times, avg 2µs/call:
# 3 times (7µs+0s) by Carp::caller_info at line 137, avg 2µs/call | ||||
| 230 | 3 | 800ns | my $info = shift; | ||
| 231 | 3 | 2µs | if ( defined( $info->{evaltext} ) ) { | ||
| 232 | my $eval = $info->{evaltext}; | ||||
| 233 | if ( $info->{is_require} ) { | ||||
| 234 | return "require $eval"; | ||||
| 235 | } | ||||
| 236 | else { | ||||
| 237 | $eval =~ s/([\\\'])/\\$1/g; | ||||
| 238 | return "eval '" . str_len_trim( $eval, $MaxEvalLen ) . "'"; | ||||
| 239 | } | ||||
| 240 | } | ||||
| 241 | |||||
| 242 | # this can happen on older perls when the sub (or the stash containing it) | ||||
| 243 | # has been deleted | ||||
| 244 | 3 | 700ns | if ( !defined( $info->{sub} ) ) { | ||
| 245 | return '__ANON__::__ANON__'; | ||||
| 246 | } | ||||
| 247 | |||||
| 248 | 3 | 7µs | return ( $info->{sub} eq '(eval)' ) ? 'eval {...}' : $info->{sub}; | ||
| 249 | } | ||||
| 250 | |||||
| 251 | # Figures out what call (from the point of view of the caller) | ||||
| 252 | # the long error backtrace should start at. | ||||
| 253 | sub long_error_loc { | ||||
| 254 | my $i; | ||||
| 255 | my $lvl = $CarpLevel; | ||||
| 256 | { | ||||
| 257 | ++$i; | ||||
| 258 | my $cgc = _cgc(); | ||||
| 259 | my @caller = $cgc ? $cgc->($i) : caller($i); | ||||
| 260 | my $pkg = $caller[0]; | ||||
| 261 | unless ( defined($pkg) ) { | ||||
| 262 | |||||
| 263 | # This *shouldn't* happen. | ||||
| 264 | if (%Internal) { | ||||
| 265 | local %Internal; | ||||
| 266 | $i = long_error_loc(); | ||||
| 267 | last; | ||||
| 268 | } | ||||
| 269 | elsif (defined $caller[2]) { | ||||
| 270 | # this can happen when the stash has been deleted | ||||
| 271 | # in that case, just assume that it's a reasonable place to | ||||
| 272 | # stop (the file and line data will still be intact in any | ||||
| 273 | # case) - the only issue is that we can't detect if the | ||||
| 274 | # deleted package was internal (so don't do that then) | ||||
| 275 | # -doy | ||||
| 276 | redo unless 0 > --$lvl; | ||||
| 277 | last; | ||||
| 278 | } | ||||
| 279 | else { | ||||
| 280 | return 2; | ||||
| 281 | } | ||||
| 282 | } | ||||
| 283 | redo if $CarpInternal{$pkg}; | ||||
| 284 | redo unless 0 > --$lvl; | ||||
| 285 | redo if $Internal{$pkg}; | ||||
| 286 | } | ||||
| 287 | return $i - 1; | ||||
| 288 | } | ||||
| 289 | |||||
| 290 | sub longmess_heavy { | ||||
| 291 | return @_ if ref( $_[0] ); # don't break references as exceptions | ||||
| 292 | my $i = long_error_loc(); | ||||
| 293 | return ret_backtrace( $i, @_ ); | ||||
| 294 | } | ||||
| 295 | |||||
| 296 | # Returns a full stack backtrace starting from where it is | ||||
| 297 | # told. | ||||
| 298 | sub ret_backtrace { | ||||
| 299 | my ( $i, @error ) = @_; | ||||
| 300 | my $mess; | ||||
| 301 | my $err = join '', @error; | ||||
| 302 | $i++; | ||||
| 303 | |||||
| 304 | my $tid_msg = ''; | ||||
| 305 | if ( defined &threads::tid ) { | ||||
| 306 | my $tid = threads->tid; | ||||
| 307 | $tid_msg = " thread $tid" if $tid; | ||||
| 308 | } | ||||
| 309 | |||||
| 310 | my %i = caller_info($i); | ||||
| 311 | $mess = "$err at $i{file} line $i{line}$tid_msg"; | ||||
| 312 | if( defined $. ) { | ||||
| 313 | local $@ = ''; | ||||
| 314 | local $SIG{__DIE__}; | ||||
| 315 | eval { | ||||
| 316 | CORE::die; | ||||
| 317 | }; | ||||
| 318 | if($@ =~ /^Died at .*(, <.*?> line \d+).$/ ) { | ||||
| 319 | $mess .= $1; | ||||
| 320 | } | ||||
| 321 | } | ||||
| 322 | $mess .= "\.\n"; | ||||
| 323 | |||||
| 324 | while ( my %i = caller_info( ++$i ) ) { | ||||
| 325 | $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; | ||||
| 326 | } | ||||
| 327 | |||||
| 328 | return $mess; | ||||
| 329 | } | ||||
| 330 | |||||
| 331 | # spent 249µs (29+220) within Carp::ret_summary which was called 3 times, avg 83µs/call:
# 3 times (29µs+220µs) by Carp::shortmess_heavy at line 387, avg 83µs/call | ||||
| 332 | 3 | 3µs | my ( $i, @error ) = @_; | ||
| 333 | 3 | 2µs | my $err = join '', @error; | ||
| 334 | 3 | 400ns | $i++; | ||
| 335 | |||||
| 336 | 3 | 500ns | my $tid_msg = ''; | ||
| 337 | 3 | 900ns | if ( defined &threads::tid ) { | ||
| 338 | my $tid = threads->tid; | ||||
| 339 | $tid_msg = " thread $tid" if $tid; | ||||
| 340 | } | ||||
| 341 | |||||
| 342 | 3 | 9µs | 3 | 220µs | my %i = caller_info($i); # spent 220µs making 3 calls to Carp::caller_info, avg 73µs/call |
| 343 | 3 | 13µs | return "$err at $i{file} line $i{line}$tid_msg\.\n"; | ||
| 344 | } | ||||
| 345 | |||||
| 346 | # spent 133µs (53+80) within Carp::short_error_loc which was called 3 times, avg 44µs/call:
# 3 times (53µs+80µs) by Carp::shortmess_heavy at line 386, avg 44µs/call | ||||
| 347 | # You have to create your (hash)ref out here, rather than defaulting it | ||||
| 348 | # inside trusts *on a lexical*, as you want it to persist across calls. | ||||
| 349 | # (You can default it on $_[2], but that gets messy) | ||||
| 350 | 3 | 1µs | my $cache = {}; | ||
| 351 | 3 | 300ns | my $i = 1; | ||
| 352 | 3 | 500ns | my $lvl = $CarpLevel; | ||
| 353 | { | ||||
| 354 | 15 | 7µs | 12 | 14µs | my $cgc = _cgc(); # spent 14µs making 12 calls to Carp::_cgc, avg 1µs/call |
| 355 | 12 | 4µs | my $called = $cgc ? $cgc->($i) : caller($i); | ||
| 356 | 12 | 900ns | $i++; | ||
| 357 | 12 | 3µs | my $caller = $cgc ? $cgc->($i) : caller($i); | ||
| 358 | |||||
| 359 | 12 | 2µs | if (!defined($caller)) { | ||
| 360 | my @caller = $cgc ? $cgc->($i) : caller($i); | ||||
| 361 | if (@caller) { | ||||
| 362 | # if there's no package but there is other caller info, then | ||||
| 363 | # the package has been deleted - treat this as a valid package | ||||
| 364 | # in this case | ||||
| 365 | redo if defined($called) && $CarpInternal{$called}; | ||||
| 366 | redo unless 0 > --$lvl; | ||||
| 367 | last; | ||||
| 368 | } | ||||
| 369 | else { | ||||
| 370 | return 0; | ||||
| 371 | } | ||||
| 372 | } | ||||
| 373 | 12 | 4µs | redo if $Internal{$caller}; | ||
| 374 | 6 | 2µs | redo if $CarpInternal{$caller}; | ||
| 375 | 3 | 600ns | redo if $CarpInternal{$called}; | ||
| 376 | 3 | 3µs | 3 | 42µs | redo if trusts( $called, $caller, $cache ); # spent 42µs making 3 calls to Carp::trusts, avg 14µs/call |
| 377 | 3 | 3µs | 3 | 24µs | redo if trusts( $caller, $called, $cache ); # spent 24µs making 3 calls to Carp::trusts, avg 8µs/call |
| 378 | 3 | 2µs | redo unless 0 > --$lvl; | ||
| 379 | } | ||||
| 380 | 3 | 9µs | return $i - 1; | ||
| 381 | } | ||||
| 382 | |||||
| 383 | # spent 398µs (16+382) within Carp::shortmess_heavy which was called 3 times, avg 133µs/call:
# 3 times (16µs+382µs) by Carp::shortmess at line 97, avg 133µs/call | ||||
| 384 | 3 | 500ns | return longmess_heavy(@_) if $Verbose; | ||
| 385 | 3 | 1µs | return @_ if ref( $_[0] ); # don't break references as exceptions | ||
| 386 | 3 | 3µs | 3 | 133µs | my $i = short_error_loc(); # spent 133µs making 3 calls to Carp::short_error_loc, avg 44µs/call |
| 387 | 3 | 8µs | 3 | 249µs | if ($i) { # spent 249µs making 3 calls to Carp::ret_summary, avg 83µs/call |
| 388 | ret_summary( $i, @_ ); | ||||
| 389 | } | ||||
| 390 | else { | ||||
| 391 | longmess_heavy(@_); | ||||
| 392 | } | ||||
| 393 | } | ||||
| 394 | |||||
| 395 | # If a string is too long, trims it with ... | ||||
| 396 | # spent 9µs within Carp::str_len_trim which was called 6 times, avg 1µs/call:
# 6 times (9µs+0s) by Carp::format_arg at line 195, avg 1µs/call | ||||
| 397 | 6 | 1µs | my $str = shift; | ||
| 398 | 6 | 1µs | my $max = shift || 0; | ||
| 399 | 6 | 2µs | if ( 2 < $max and $max < length($str) ) { | ||
| 400 | substr( $str, $max - 3 ) = '...'; | ||||
| 401 | } | ||||
| 402 | 6 | 10µs | return $str; | ||
| 403 | } | ||||
| 404 | |||||
| 405 | # Takes two packages and an optional cache. Says whether the | ||||
| 406 | # first inherits from the second. | ||||
| 407 | # | ||||
| 408 | # Recursive versions of this have to work to avoid certain | ||||
| 409 | # possible endless loops, and when following long chains of | ||||
| 410 | # inheritance are less efficient. | ||||
| 411 | sub trusts { | ||||
| 412 | 6 | 1µs | my $child = shift; | ||
| 413 | 6 | 400ns | my $parent = shift; | ||
| 414 | 6 | 700ns | my $cache = shift; | ||
| 415 | 6 | 4µs | 6 | 43µs | my ( $known, $partial ) = get_status( $cache, $child ); # spent 43µs making 6 calls to Carp::get_status, avg 7µs/call |
| 416 | |||||
| 417 | # Figure out consequences until we have an answer | ||||
| 418 | 6 | 2µs | while ( @$partial and not exists $known->{$parent} ) { | ||
| 419 | my $anc = shift @$partial; | ||||
| 420 | next if exists $known->{$anc}; | ||||
| 421 | $known->{$anc}++; | ||||
| 422 | my ( $anc_knows, $anc_partial ) = get_status( $cache, $anc ); | ||||
| 423 | my @found = keys %$anc_knows; | ||||
| 424 | @$known{@found} = (); | ||||
| 425 | push @$partial, @$anc_partial; | ||||
| 426 | } | ||||
| 427 | 6 | 11µs | return exists $known->{$parent}; | ||
| 428 | } | ||||
| 429 | |||||
| 430 | # Takes a package and gives a list of those trusted directly | ||||
| 431 | # spent 16µs within Carp::trusts_directly which was called 6 times, avg 3µs/call:
# 6 times (16µs+0s) by Carp::get_status at line 223, avg 3µs/call | ||||
| 432 | 6 | 800ns | my $class = shift; | ||
| 433 | 2 | 22µs | 2 | 24µs | # spent 15µs (6+9) within Carp::BEGIN@433 which was called:
# once (6µs+9µs) by Module::Pluggable::Object::BEGIN@7 at line 433 # spent 15µs making 1 call to Carp::BEGIN@433
# spent 9µs making 1 call to strict::unimport |
| 434 | 2 | 55µs | 2 | 38µs | # spent 22µs (7+15) within Carp::BEGIN@434 which was called:
# once (7µs+15µs) by Module::Pluggable::Object::BEGIN@7 at line 434 # spent 22µs making 1 call to Carp::BEGIN@434
# spent 15µs making 1 call to warnings::unimport |
| 435 | return @{"$class\::CARP_NOT"} | ||||
| 436 | ? @{"$class\::CARP_NOT"} | ||||
| 437 | 6 | 21µs | : @{"$class\::ISA"}; | ||
| 438 | } | ||||
| 439 | |||||
| 440 | 1 | 600ns | if(!defined($warnings::VERSION) || | ||
| 441 | 3 | 32µs | 2 | 22µs | # spent 14µs (6+8) within Carp::BEGIN@441 which was called:
# once (6µs+8µs) by Module::Pluggable::Object::BEGIN@7 at line 441 # spent 14µs making 1 call to Carp::BEGIN@441
# spent 8µs making 1 call to warnings::unimport |
| 442 | # Very old versions of warnings.pm import from Carp. This can go | ||||
| 443 | # wrong due to the circular dependency. If Carp is invoked before | ||||
| 444 | # warnings, then Carp starts by loading warnings, then warnings | ||||
| 445 | # tries to import from Carp, and gets nothing because Carp is in | ||||
| 446 | # the process of loading and hasn't defined its import method yet. | ||||
| 447 | # So we work around that by manually exporting to warnings here. | ||||
| 448 | 2 | 47µs | 2 | 20µs | # spent 12µs (5+7) within Carp::BEGIN@448 which was called:
# once (5µs+7µs) by Module::Pluggable::Object::BEGIN@7 at line 448 # spent 12µs making 1 call to Carp::BEGIN@448
# spent 7µs making 1 call to strict::unimport |
| 449 | *{"warnings::$_"} = \&$_ foreach @EXPORT; | ||||
| 450 | } | ||||
| 451 | |||||
| 452 | 1 | 7µs | 1; | ||
| 453 | |||||
| 454 | __END__ | ||||
# spent 8µs within Carp::CORE:match which was called 6 times, avg 1µs/call:
# 6 times (8µs+0s) by Carp::format_arg at line 202, avg 1µs/call | |||||
sub Carp::CORE:subst; # opcode |