| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0/Carp.pm |
| Statements | Executed 1267 statements in 3.27ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 16 | 2 | 2 | 162µs | 465µs | Carp::short_error_loc |
| 32 | 1 | 1 | 106µs | 174µs | Carp::get_status |
| 32 | 2 | 1 | 77µs | 252µs | Carp::trusts |
| 32 | 1 | 1 | 69µs | 69µs | Carp::trusts_directly |
| 44 | 3 | 1 | 63µs | 63µs | Carp::_cgc |
| 3 | 1 | 1 | 60µs | 123µs | Carp::caller_info |
| 6 | 1 | 1 | 43µs | 54µs | Carp::format_arg |
| 3 | 1 | 1 | 24µs | 289µs | Carp::shortmess |
| 3 | 1 | 1 | 23µs | 146µs | Carp::ret_summary |
| 1 | 1 | 1 | 18µs | 28µs | Carp::BEGIN@6 |
| 3 | 1 | 1 | 17µs | 314µs | Carp::croak |
| 3 | 1 | 1 | 13µs | 256µs | Carp::shortmess_heavy |
| 2 | 2 | 1 | 11µs | 11µs | Carp::_fetch_sub |
| 1 | 1 | 1 | 7µs | 7µs | Carp::BEGIN@3 |
| 1 | 1 | 1 | 6µs | 10µs | Carp::BEGIN@73 |
| 1 | 1 | 1 | 6µs | 16µs | Carp::BEGIN@589 |
| 1 | 1 | 1 | 6µs | 12µs | Carp::BEGIN@602 |
| 3 | 1 | 1 | 6µs | 6µs | Carp::get_subname |
| 1 | 1 | 1 | 5µs | 12µs | Carp::BEGIN@61 |
| 1 | 1 | 1 | 5µs | 13µs | Carp::BEGIN@609 |
| 1 | 1 | 1 | 5µs | 7µs | Carp::BEGIN@4 |
| 6 | 1 | 1 | 5µs | 5µs | Carp::CORE:match (opcode) |
| 1 | 1 | 1 | 5µs | 15µs | Carp::BEGIN@131 |
| 1 | 1 | 1 | 4µs | 4µs | Carp::BEGIN@49 |
| 1 | 1 | 1 | 4µs | 4µs | Carp::BEGIN@171 |
| 1 | 1 | 1 | 3µs | 6µs | Carp::BEGIN@5 |
| 12 | 2 | 1 | 3µs | 3µs | Carp::CORE:subst (opcode) |
| 0 | 0 | 0 | 0s | 0s | Carp::__ANON__[:261] |
| 0 | 0 | 0 | 0s | 0s | Carp::__ANON__[:272] |
| 0 | 0 | 0 | 0s | 0s | Carp::__ANON__[:66] |
| 0 | 0 | 0 | 0s | 0s | Carp::__ANON__[:86] |
| 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 |
| 0 | 0 | 0 | 0s | 0s | Carp::str_len_trim |
| 0 | 0 | 0 | 0s | 0s | Regexp::CARP_TRACE |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Carp; | ||||
| 2 | |||||
| 3 | 2 | 23µs | 1 | 7µs | # spent 7µs within Carp::BEGIN@3 which was called:
# once (7µs+0s) by Attribute::Handlers::BEGIN@3 at line 3 # spent 7µs making 1 call to Carp::BEGIN@3 |
| 4 | 3 | 15µs | 2 | 8µs | # spent 7µs (5+2) within Carp::BEGIN@4 which was called:
# once (5µs+2µs) by Attribute::Handlers::BEGIN@3 at line 4 # spent 7µs making 1 call to Carp::BEGIN@4
# spent 2µs making 1 call to strict::import |
| 5 | 2 | 42µs | 2 | 9µs | # spent 6µs (3+3) within Carp::BEGIN@5 which was called:
# once (3µs+3µs) by Attribute::Handlers::BEGIN@3 at line 5 # spent 6µs making 1 call to Carp::BEGIN@5
# spent 3µs making 1 call to warnings::import |
| 6 | # spent 28µs (18+9) within Carp::BEGIN@6 which was called:
# once (18µs+9µs) by Attribute::Handlers::BEGIN@3 at line 26 | ||||
| 7 | # Very old versions of warnings.pm load Carp. This can go wrong due | ||||
| 8 | # to the circular dependency. If warnings is invoked before Carp, | ||||
| 9 | # then warnings starts by loading Carp, then Carp (above) tries to | ||||
| 10 | # invoke warnings, and gets nothing because warnings is in the process | ||||
| 11 | # of loading and hasn't defined its import method yet. If we were | ||||
| 12 | # only turning on warnings ("use warnings" above) this wouldn't be too | ||||
| 13 | # bad, because Carp would just gets the state of the -w switch and so | ||||
| 14 | # might not get some warnings that it wanted. The real problem is | ||||
| 15 | # that we then want to turn off Unicode warnings, but "no warnings | ||||
| 16 | # 'utf8'" won't be effective if we're in this circular-dependency | ||||
| 17 | # situation. So, if warnings.pm is an affected version, we turn | ||||
| 18 | # off all warnings ourselves by directly setting ${^WARNING_BITS}. | ||||
| 19 | # On unaffected versions, we turn off just Unicode warnings, via | ||||
| 20 | # the proper API. | ||||
| 21 | 1 | 12µs | if(!defined($warnings::VERSION) || eval($warnings::VERSION) < 1.06) { # spent 2µs executing statements in string eval | ||
| 22 | ${^WARNING_BITS} = ""; | ||||
| 23 | } else { | ||||
| 24 | 1 | 1µs | 1 | 9µs | "warnings"->unimport("utf8"); # spent 9µs making 1 call to warnings::unimport |
| 25 | } | ||||
| 26 | 1 | 114µs | 1 | 28µs | } # spent 28µs making 1 call to Carp::BEGIN@6 |
| 27 | |||||
| 28 | sub _fetch_sub { # fetch sub without autovivifying | ||||
| 29 | 2 | 1µs | my($pack, $sub) = @_; | ||
| 30 | 2 | 600ns | $pack .= '::'; | ||
| 31 | # only works with top-level packages | ||||
| 32 | 2 | 600ns | return unless exists($::{$pack}); | ||
| 33 | 2 | 1µs | for ($::{$pack}) { | ||
| 34 | 2 | 3µs | return unless ref \$_ eq 'GLOB' && *$_{HASH} && exists $$_{$sub}; | ||
| 35 | 2 | 900ns | for ($$_{$sub}) { | ||
| 36 | return ref \$_ eq 'GLOB' ? *$_{CODE} : undef | ||||
| 37 | 2 | 7µs | } | ||
| 38 | } | ||||
| 39 | } | ||||
| 40 | |||||
| 41 | # UTF8_REGEXP_PROBLEM is a compile-time constant indicating whether Carp | ||||
| 42 | # must avoid applying a regular expression to an upgraded (is_utf8) | ||||
| 43 | # string. There are multiple problems, on different Perl versions, | ||||
| 44 | # that require this to be avoided. All versions prior to 5.13.8 will | ||||
| 45 | # load utf8_heavy.pl for the swash system, even if the regexp doesn't | ||||
| 46 | # use character classes. Perl 5.6 and Perls [5.11.2, 5.13.11) exhibit | ||||
| 47 | # specific problems when Carp is being invoked in the aftermath of a | ||||
| 48 | # syntax error. | ||||
| 49 | # spent 4µs within Carp::BEGIN@49 which was called:
# once (4µs+0s) by Attribute::Handlers::BEGIN@3 at line 55 | ||||
| 50 | 1 | 6µs | if("$]" < 5.013011) { | ||
| 51 | *UTF8_REGEXP_PROBLEM = sub () { 1 }; | ||||
| 52 | } else { | ||||
| 53 | 1 | 800ns | *UTF8_REGEXP_PROBLEM = sub () { 0 }; | ||
| 54 | } | ||||
| 55 | 1 | 51µs | 1 | 4µs | } # spent 4µs making 1 call to Carp::BEGIN@49 |
| 56 | |||||
| 57 | # is_utf8() is essentially the utf8::is_utf8() function, which indicates | ||||
| 58 | # whether a string is represented in the upgraded form (using UTF-8 | ||||
| 59 | # internally). As utf8::is_utf8() is only available from Perl 5.8 | ||||
| 60 | # onwards, extra effort is required here to make it work on Perl 5.6. | ||||
| 61 | # spent 12µs (5+6) within Carp::BEGIN@61 which was called:
# once (5µs+6µs) by Attribute::Handlers::BEGIN@3 at line 68 | ||||
| 62 | 1 | 3µs | 1 | 6µs | if(defined(my $sub = _fetch_sub utf8 => 'is_utf8')) { # spent 6µs making 1 call to Carp::_fetch_sub |
| 63 | *is_utf8 = $sub; | ||||
| 64 | } else { | ||||
| 65 | # black magic for perl 5.6 | ||||
| 66 | *is_utf8 = sub { unpack("C", "\xaa".$_[0]) != 170 }; | ||||
| 67 | } | ||||
| 68 | 1 | 77µs | 1 | 12µs | } # spent 12µs making 1 call to Carp::BEGIN@61 |
| 69 | |||||
| 70 | # The downgrade() function defined here is to be used for attempts to | ||||
| 71 | # downgrade where it is acceptable to fail. It must be called with a | ||||
| 72 | # second argument that is a true value. | ||||
| 73 | # spent 10µs (6+4) within Carp::BEGIN@73 which was called:
# once (6µs+4µs) by Attribute::Handlers::BEGIN@3 at line 88 | ||||
| 74 | 1 | 3µs | 1 | 4µs | if(defined(my $sub = _fetch_sub utf8 => 'downgrade')) { # spent 4µs making 1 call to Carp::_fetch_sub |
| 75 | *downgrade = \&{"utf8::downgrade"}; | ||||
| 76 | } else { | ||||
| 77 | *downgrade = sub { | ||||
| 78 | my $r = ""; | ||||
| 79 | my $l = length($_[0]); | ||||
| 80 | for(my $i = 0; $i != $l; $i++) { | ||||
| 81 | my $o = ord(substr($_[0], $i, 1)); | ||||
| 82 | return if $o > 255; | ||||
| 83 | $r .= chr($o); | ||||
| 84 | } | ||||
| 85 | $_[0] = $r; | ||||
| 86 | }; | ||||
| 87 | } | ||||
| 88 | 1 | 120µs | 1 | 10µs | } # spent 10µs making 1 call to Carp::BEGIN@73 |
| 89 | |||||
| 90 | 1 | 300ns | our $VERSION = '1.36'; | ||
| 91 | |||||
| 92 | 1 | 100ns | our $MaxEvalLen = 0; | ||
| 93 | 1 | 100ns | our $Verbose = 0; | ||
| 94 | 1 | 100ns | our $CarpLevel = 0; | ||
| 95 | 1 | 0s | our $MaxArgLen = 64; # How much of each argument to print. 0 = all. | ||
| 96 | 1 | 100ns | our $MaxArgNums = 8; # How many arguments to print. 0 = all. | ||
| 97 | 1 | 200ns | our $RefArgFormatter = undef; # allow caller to format reference arguments | ||
| 98 | |||||
| 99 | 1 | 386µs | require Exporter; | ||
| 100 | 1 | 4µs | our @ISA = ('Exporter'); | ||
| 101 | 1 | 600ns | our @EXPORT = qw(confess croak carp); | ||
| 102 | 1 | 500ns | our @EXPORT_OK = qw(cluck verbose longmess shortmess); | ||
| 103 | 1 | 300ns | our @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode | ||
| 104 | |||||
| 105 | # The members of %Internal are packages that are internal to perl. | ||||
| 106 | # Carp will not report errors from within these packages if it | ||||
| 107 | # can. The members of %CarpInternal are internal to Perl's warning | ||||
| 108 | # system. Carp will not report errors from within these packages | ||||
| 109 | # either, and will not report calls *to* these packages for carp and | ||||
| 110 | # croak. They replace $CarpLevel, which is deprecated. The | ||||
| 111 | # $Max(EvalLen|(Arg(Len|Nums)) variables are used to specify how the eval | ||||
| 112 | # text and function arguments should be formatted when printed. | ||||
| 113 | |||||
| 114 | our %CarpInternal; | ||||
| 115 | our %Internal; | ||||
| 116 | |||||
| 117 | # disable these by default, so they can live w/o require Carp | ||||
| 118 | 1 | 700ns | $CarpInternal{Carp}++; | ||
| 119 | 1 | 200ns | $CarpInternal{warnings}++; | ||
| 120 | 1 | 200ns | $Internal{Exporter}++; | ||
| 121 | 1 | 100ns | $Internal{'Exporter::Heavy'}++; | ||
| 122 | |||||
| 123 | # if the caller specifies verbose usage ("perl -MCarp=verbose script.pl") | ||||
| 124 | # then the following method will be called by the Exporter which knows | ||||
| 125 | # to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word | ||||
| 126 | # 'verbose'. | ||||
| 127 | |||||
| 128 | sub export_fail { shift; $Verbose = shift if $_[0] eq 'verbose'; @_ } | ||||
| 129 | |||||
| 130 | sub _cgc { | ||||
| 131 | 2 | 205µs | 2 | 25µs | # spent 15µs (5+10) within Carp::BEGIN@131 which was called:
# once (5µs+10µs) by Attribute::Handlers::BEGIN@3 at line 131 # spent 15µs making 1 call to Carp::BEGIN@131
# spent 10µs making 1 call to strict::unimport |
| 132 | 44 | 46µs | return \&{"CORE::GLOBAL::caller"} if defined &{"CORE::GLOBAL::caller"}; | ||
| 133 | 44 | 39µs | return; | ||
| 134 | } | ||||
| 135 | |||||
| 136 | sub longmess { | ||||
| 137 | local($!, $^E); | ||||
| 138 | # Icky backwards compatibility wrapper. :-( | ||||
| 139 | # | ||||
| 140 | # The story is that the original implementation hard-coded the | ||||
| 141 | # number of call levels to go back, so calls to longmess were off | ||||
| 142 | # by one. Other code began calling longmess and expecting this | ||||
| 143 | # behaviour, so the replacement has to emulate that behaviour. | ||||
| 144 | my $cgc = _cgc(); | ||||
| 145 | my $call_pack = $cgc ? $cgc->() : caller(); | ||||
| 146 | if ( $Internal{$call_pack} or $CarpInternal{$call_pack} ) { | ||||
| 147 | return longmess_heavy(@_); | ||||
| 148 | } | ||||
| 149 | else { | ||||
| 150 | local $CarpLevel = $CarpLevel + 1; | ||||
| 151 | return longmess_heavy(@_); | ||||
| 152 | } | ||||
| 153 | } | ||||
| 154 | |||||
| 155 | our @CARP_NOT; | ||||
| 156 | |||||
| 157 | # spent 289µs (24+265) within Carp::shortmess which was called 3 times, avg 96µs/call:
# 3 times (24µs+265µs) by Carp::croak at line 166, avg 96µs/call | ||||
| 158 | 3 | 5µs | local($!, $^E); | ||
| 159 | 3 | 3µs | 3 | 9µs | my $cgc = _cgc(); # spent 9µs making 3 calls to Carp::_cgc, avg 3µs/call |
| 160 | |||||
| 161 | # Icky backwards compatibility wrapper. :-( | ||||
| 162 | 3 | 5µs | local @CARP_NOT = $cgc ? $cgc->() : caller(); | ||
| 163 | 3 | 9µs | 3 | 256µs | shortmess_heavy(@_); # spent 256µs making 3 calls to Carp::shortmess_heavy, avg 85µs/call |
| 164 | } | ||||
| 165 | |||||
| 166 | 3 | 35µs | 6 | 298µs | # spent 314µs (17+298) within Carp::croak which was called 3 times, avg 105µs/call:
# 3 times (17µs+298µs) by Exporter::Heavy::heavy_export at line 159 of Exporter/Heavy.pm, avg 105µs/call # spent 289µs making 3 calls to Carp::shortmess, avg 96µs/call
# spent 9µs making 3 calls to Exporter::Heavy::__ANON__[Exporter/Heavy.pm:63], avg 3µs/call |
| 167 | sub confess { die longmess @_ } | ||||
| 168 | sub carp { warn shortmess @_ } | ||||
| 169 | sub cluck { warn longmess @_ } | ||||
| 170 | |||||
| 171 | # spent 4µs within Carp::BEGIN@171 which was called:
# once (4µs+0s) by Attribute::Handlers::BEGIN@3 at line 178 | ||||
| 172 | 1 | 4µs | if("$]" >= 5.015002 || ("$]" >= 5.014002 && "$]" < 5.015) || | ||
| 173 | ("$]" >= 5.012005 && "$]" < 5.013)) { | ||||
| 174 | *CALLER_OVERRIDE_CHECK_OK = sub () { 1 }; | ||||
| 175 | } else { | ||||
| 176 | *CALLER_OVERRIDE_CHECK_OK = sub () { 0 }; | ||||
| 177 | } | ||||
| 178 | 1 | 1.33ms | 1 | 4µs | } # spent 4µs making 1 call to Carp::BEGIN@171 |
| 179 | |||||
| 180 | # spent 123µs (60+63) within Carp::caller_info which was called 3 times, avg 41µs/call:
# 3 times (60µs+63µs) by Carp::ret_summary at line 498, avg 41µs/call | ||||
| 181 | 3 | 2µs | my $i = shift(@_) + 1; | ||
| 182 | 3 | 500ns | my %call_info; | ||
| 183 | 3 | 1µs | 3 | 3µs | my $cgc = _cgc(); # spent 3µs making 3 calls to Carp::_cgc, avg 1µs/call |
| 184 | { | ||||
| 185 | # Some things override caller() but forget to implement the | ||||
| 186 | # @DB::args part of it, which we need. We check for this by | ||||
| 187 | # pre-populating @DB::args with a sentinel which no-one else | ||||
| 188 | # has the address of, so that we can detect whether @DB::args | ||||
| 189 | # has been properly populated. However, on earlier versions | ||||
| 190 | # of perl this check tickles a bug in CORE::caller() which | ||||
| 191 | # leaks memory. So we only check on fixed perls. | ||||
| 192 | 6 | 4µs | @DB::args = \$i if CALLER_OVERRIDE_CHECK_OK; | ||
| 193 | package DB; | ||||
| 194 | |||||
| 195 | 3 | 13µs | |||
| - - | |||||
| 199 | 3 | 1µs | unless ( defined $call_info{file} ) { | ||
| 200 | return (); | ||||
| 201 | } | ||||
| 202 | |||||
| 203 | 3 | 3µs | 3 | 6µs | my $sub_name = Carp::get_subname( \%call_info ); # spent 6µs making 3 calls to Carp::get_subname, avg 2µs/call |
| 204 | 3 | 1µs | if ( $call_info{has_args} ) { | ||
| 205 | 3 | 300ns | my @args; | ||
| 206 | 3 | 1µs | if (CALLER_OVERRIDE_CHECK_OK && @DB::args == 1 | ||
| 207 | && ref $DB::args[0] eq ref \$i | ||||
| 208 | && $DB::args[0] == \$i ) { | ||||
| 209 | @DB::args = (); # Don't let anyone see the address of $i | ||||
| 210 | local $@; | ||||
| 211 | my $where = eval { | ||||
| 212 | my $func = $cgc or return ''; | ||||
| 213 | my $gv = | ||||
| 214 | (_fetch_sub B => 'svref_2object' or return '') | ||||
| 215 | ->($func)->GV; | ||||
| 216 | my $package = $gv->STASH->NAME; | ||||
| 217 | my $subname = $gv->NAME; | ||||
| 218 | return unless defined $package && defined $subname; | ||||
| 219 | |||||
| 220 | # returning CORE::GLOBAL::caller isn't useful for tracing the cause: | ||||
| 221 | return if $package eq 'CORE::GLOBAL' && $subname eq 'caller'; | ||||
| 222 | " in &${package}::$subname"; | ||||
| 223 | } || ''; | ||||
| 224 | @args | ||||
| 225 | = "** Incomplete caller override detected$where; \@DB::args were not set **"; | ||||
| 226 | } | ||||
| 227 | else { | ||||
| 228 | 3 | 2µs | @args = @DB::args; | ||
| 229 | 3 | 600ns | my $overflow; | ||
| 230 | 3 | 1µs | if ( $MaxArgNums and @args > $MaxArgNums ) | ||
| 231 | { # More than we want to show? | ||||
| 232 | $#args = $MaxArgNums; | ||||
| 233 | $overflow = 1; | ||||
| 234 | } | ||||
| 235 | |||||
| 236 | 9 | 9µs | 6 | 54µs | @args = map { Carp::format_arg($_) } @args; # spent 54µs making 6 calls to Carp::format_arg, avg 9µs/call |
| 237 | |||||
| 238 | 3 | 500ns | if ($overflow) { | ||
| 239 | push @args, '...'; | ||||
| 240 | } | ||||
| 241 | } | ||||
| 242 | |||||
| 243 | # Push the args onto the subroutine | ||||
| 244 | 3 | 4µs | $sub_name .= '(' . join( ', ', @args ) . ')'; | ||
| 245 | } | ||||
| 246 | 3 | 800ns | $call_info{sub_name} = $sub_name; | ||
| 247 | 3 | 11µs | return wantarray() ? %call_info : \%call_info; | ||
| 248 | } | ||||
| 249 | |||||
| 250 | # Transform an argument to a function into a string. | ||||
| 251 | our $in_recurse; | ||||
| 252 | # spent 54µs (43+11) within Carp::format_arg which was called 6 times, avg 9µs/call:
# 6 times (43µs+11µs) by Carp::caller_info at line 236, avg 9µs/call | ||||
| 253 | 6 | 2µs | my $arg = shift; | ||
| 254 | |||||
| 255 | 6 | 800ns | if ( ref($arg) ) { | ||
| 256 | # legitimate, let's not leak it. | ||||
| 257 | if (!$in_recurse && | ||||
| 258 | do { | ||||
| 259 | local $@; | ||||
| 260 | local $in_recurse = 1; | ||||
| 261 | local $SIG{__DIE__} = sub{}; | ||||
| 262 | eval {$arg->can('CARP_TRACE') } | ||||
| 263 | }) | ||||
| 264 | { | ||||
| 265 | return $arg->CARP_TRACE(); | ||||
| 266 | } | ||||
| 267 | elsif (!$in_recurse && | ||||
| 268 | defined($RefArgFormatter) && | ||||
| 269 | do { | ||||
| 270 | local $@; | ||||
| 271 | local $in_recurse = 1; | ||||
| 272 | local $SIG{__DIE__} = sub{}; | ||||
| 273 | eval {$arg = $RefArgFormatter->($arg); 1} | ||||
| 274 | }) | ||||
| 275 | { | ||||
| 276 | return $arg; | ||||
| 277 | } | ||||
| 278 | else | ||||
| 279 | { | ||||
| 280 | my $sub = _fetch_sub(overload => 'StrVal'); | ||||
| 281 | return $sub ? &$sub($arg) : "$arg"; | ||||
| 282 | } | ||||
| 283 | } | ||||
| 284 | 6 | 500ns | return "undef" if !defined($arg); | ||
| 285 | 6 | 9µs | 6 | 2µs | downgrade($arg, 1); # spent 2µs making 6 calls to utf8::downgrade, avg 333ns/call |
| 286 | 6 | 11µs | 6 | 5µs | return $arg if !(UTF8_REGEXP_PROBLEM && is_utf8($arg)) && # spent 5µs making 6 calls to Carp::CORE:match, avg 800ns/call |
| 287 | $arg =~ /\A-?[0-9]+(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?\z/; | ||||
| 288 | 6 | 1µs | my $suffix = ""; | ||
| 289 | 6 | 2µs | if ( 2 < $MaxArgLen and $MaxArgLen < length($arg) ) { | ||
| 290 | substr ( $arg, $MaxArgLen - 3 ) = ""; | ||||
| 291 | $suffix = "..."; | ||||
| 292 | } | ||||
| 293 | 6 | 800ns | if(UTF8_REGEXP_PROBLEM && is_utf8($arg)) { | ||
| 294 | for(my $i = length($arg); $i--; ) { | ||||
| 295 | my $c = substr($arg, $i, 1); | ||||
| 296 | my $x = substr($arg, 0, 0); # work around bug on Perl 5.8.{1,2} | ||||
| 297 | if($c eq "\"" || $c eq "\\" || $c eq "\$" || $c eq "\@") { | ||||
| 298 | substr $arg, $i, 0, "\\"; | ||||
| 299 | next; | ||||
| 300 | } | ||||
| 301 | my $o = ord($c); | ||||
| 302 | |||||
| 303 | # This code is repeated in Regexp::CARP_TRACE() | ||||
| 304 | if ($] ge 5.007_003) { | ||||
| 305 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
| 306 | if utf8::native_to_unicode($o) < utf8::native_to_unicode(0x20) | ||||
| 307 | || utf8::native_to_unicode($o) > utf8::native_to_unicode(0x7e); | ||||
| 308 | } elsif (ord("A") == 65) { | ||||
| 309 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
| 310 | if $o < 0x20 || $o > 0x7e; | ||||
| 311 | } else { # Early EBCDIC | ||||
| 312 | |||||
| 313 | # 3 EBCDIC code pages supported then; all controls but one | ||||
| 314 | # are the code points below SPACE. The other one is 0x5F on | ||||
| 315 | # POSIX-BC; FF on the other two. | ||||
| 316 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
| 317 | if $o < ord(" ") || ((ord ("^") == 106) | ||||
| 318 | ? $o == 0x5f | ||||
| 319 | : $o == 0xff); | ||||
| 320 | } | ||||
| 321 | } | ||||
| 322 | } else { | ||||
| 323 | 6 | 8µs | 6 | 2µs | $arg =~ s/([\"\\\$\@])/\\$1/g; # spent 2µs making 6 calls to Carp::CORE:subst, avg 333ns/call |
| 324 | # This is all the ASCII printables spelled-out. It is portable to all | ||||
| 325 | # Perl versions and platforms (such as EBCDIC). There are other more | ||||
| 326 | # compact ways to do this, but may not work everywhere every version. | ||||
| 327 | 6 | 6µs | 6 | 1µs | $arg =~ s/([^ !"\$\%#'()*+,\-.\/0123456789:;<=>?\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]^_`abcdefghijklmnopqrstuvwxyz\{|}~])/sprintf("\\x{%x}",ord($1))/eg; # spent 1µs making 6 calls to Carp::CORE:subst, avg 200ns/call |
| 328 | } | ||||
| 329 | 6 | 6µs | 6 | 1µs | downgrade($arg, 1); # spent 1µs making 6 calls to utf8::downgrade, avg 183ns/call |
| 330 | 6 | 9µs | return "\"".$arg."\"".$suffix; | ||
| 331 | } | ||||
| 332 | |||||
| 333 | sub Regexp::CARP_TRACE { | ||||
| 334 | my $arg = "$_[0]"; | ||||
| 335 | downgrade($arg, 1); | ||||
| 336 | if(UTF8_REGEXP_PROBLEM && is_utf8($arg)) { | ||||
| 337 | for(my $i = length($arg); $i--; ) { | ||||
| 338 | my $o = ord(substr($arg, $i, 1)); | ||||
| 339 | my $x = substr($arg, 0, 0); # work around bug on Perl 5.8.{1,2} | ||||
| 340 | |||||
| 341 | # This code is repeated in format_arg() | ||||
| 342 | if ($] ge 5.007_003) { | ||||
| 343 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
| 344 | if utf8::native_to_unicode($o) < utf8::native_to_unicode(0x20) | ||||
| 345 | || utf8::native_to_unicode($o) > utf8::native_to_unicode(0x7e); | ||||
| 346 | } elsif (ord("A") == 65) { | ||||
| 347 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
| 348 | if $o < 0x20 || $o > 0x7e; | ||||
| 349 | } else { # Early EBCDIC | ||||
| 350 | substr $arg, $i, 1, sprintf("\\x{%x}", $o) | ||||
| 351 | if $o < ord(" ") || ((ord ("^") == 106) | ||||
| 352 | ? $o == 0x5f | ||||
| 353 | : $o == 0xff); | ||||
| 354 | } | ||||
| 355 | } | ||||
| 356 | } else { | ||||
| 357 | # See comment in format_arg() about this same regex. | ||||
| 358 | $arg =~ s/([^ !"\$\%#'()*+,\-.\/0123456789:;<=>?\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]^_`abcdefghijklmnopqrstuvwxyz\{|}~])/sprintf("\\x{%x}",ord($1))/eg; | ||||
| 359 | } | ||||
| 360 | downgrade($arg, 1); | ||||
| 361 | my $suffix = ""; | ||||
| 362 | if($arg =~ /\A\(\?\^?([a-z]*)(?:-[a-z]*)?:(.*)\)\z/s) { | ||||
| 363 | ($suffix, $arg) = ($1, $2); | ||||
| 364 | } | ||||
| 365 | if ( 2 < $MaxArgLen and $MaxArgLen < length($arg) ) { | ||||
| 366 | substr ( $arg, $MaxArgLen - 3 ) = ""; | ||||
| 367 | $suffix = "...".$suffix; | ||||
| 368 | } | ||||
| 369 | return "qr($arg)$suffix"; | ||||
| 370 | } | ||||
| 371 | |||||
| 372 | # Takes an inheritance cache and a package and returns | ||||
| 373 | # an anon hash of known inheritances and anon array of | ||||
| 374 | # inheritances which consequences have not been figured | ||||
| 375 | # for. | ||||
| 376 | # spent 174µs (106+69) within Carp::get_status which was called 32 times, avg 5µs/call:
# 32 times (106µs+69µs) by Carp::trusts at line 571, avg 5µs/call | ||||
| 377 | 32 | 3µs | my $cache = shift; | ||
| 378 | 32 | 3µs | my $pkg = shift; | ||
| 379 | 32 | 65µs | 32 | 69µs | $cache->{$pkg} ||= [ { $pkg => $pkg }, [ trusts_directly($pkg) ] ]; # spent 69µs making 32 calls to Carp::trusts_directly, avg 2µs/call |
| 380 | 32 | 35µs | return @{ $cache->{$pkg} }; | ||
| 381 | } | ||||
| 382 | |||||
| 383 | # Takes the info from caller() and figures out the name of | ||||
| 384 | # the sub/require/eval | ||||
| 385 | # spent 6µs within Carp::get_subname which was called 3 times, avg 2µs/call:
# 3 times (6µs+0s) by Carp::caller_info at line 203, avg 2µs/call | ||||
| 386 | 3 | 600ns | my $info = shift; | ||
| 387 | 3 | 1µs | if ( defined( $info->{evaltext} ) ) { | ||
| 388 | my $eval = $info->{evaltext}; | ||||
| 389 | if ( $info->{is_require} ) { | ||||
| 390 | return "require $eval"; | ||||
| 391 | } | ||||
| 392 | else { | ||||
| 393 | $eval =~ s/([\\\'])/\\$1/g; | ||||
| 394 | return "eval '" . str_len_trim( $eval, $MaxEvalLen ) . "'"; | ||||
| 395 | } | ||||
| 396 | } | ||||
| 397 | |||||
| 398 | # this can happen on older perls when the sub (or the stash containing it) | ||||
| 399 | # has been deleted | ||||
| 400 | 3 | 700ns | if ( !defined( $info->{sub} ) ) { | ||
| 401 | return '__ANON__::__ANON__'; | ||||
| 402 | } | ||||
| 403 | |||||
| 404 | 3 | 5µs | return ( $info->{sub} eq '(eval)' ) ? 'eval {...}' : $info->{sub}; | ||
| 405 | } | ||||
| 406 | |||||
| 407 | # Figures out what call (from the point of view of the caller) | ||||
| 408 | # the long error backtrace should start at. | ||||
| 409 | sub long_error_loc { | ||||
| 410 | my $i; | ||||
| 411 | my $lvl = $CarpLevel; | ||||
| 412 | { | ||||
| 413 | ++$i; | ||||
| 414 | my $cgc = _cgc(); | ||||
| 415 | my @caller = $cgc ? $cgc->($i) : caller($i); | ||||
| 416 | my $pkg = $caller[0]; | ||||
| 417 | unless ( defined($pkg) ) { | ||||
| 418 | |||||
| 419 | # This *shouldn't* happen. | ||||
| 420 | if (%Internal) { | ||||
| 421 | local %Internal; | ||||
| 422 | $i = long_error_loc(); | ||||
| 423 | last; | ||||
| 424 | } | ||||
| 425 | elsif (defined $caller[2]) { | ||||
| 426 | # this can happen when the stash has been deleted | ||||
| 427 | # in that case, just assume that it's a reasonable place to | ||||
| 428 | # stop (the file and line data will still be intact in any | ||||
| 429 | # case) - the only issue is that we can't detect if the | ||||
| 430 | # deleted package was internal (so don't do that then) | ||||
| 431 | # -doy | ||||
| 432 | redo unless 0 > --$lvl; | ||||
| 433 | last; | ||||
| 434 | } | ||||
| 435 | else { | ||||
| 436 | return 2; | ||||
| 437 | } | ||||
| 438 | } | ||||
| 439 | redo if $CarpInternal{$pkg}; | ||||
| 440 | redo unless 0 > --$lvl; | ||||
| 441 | redo if $Internal{$pkg}; | ||||
| 442 | } | ||||
| 443 | return $i - 1; | ||||
| 444 | } | ||||
| 445 | |||||
| 446 | sub longmess_heavy { | ||||
| 447 | return @_ if ref( $_[0] ); # don't break references as exceptions | ||||
| 448 | my $i = long_error_loc(); | ||||
| 449 | return ret_backtrace( $i, @_ ); | ||||
| 450 | } | ||||
| 451 | |||||
| 452 | # Returns a full stack backtrace starting from where it is | ||||
| 453 | # told. | ||||
| 454 | sub ret_backtrace { | ||||
| 455 | my ( $i, @error ) = @_; | ||||
| 456 | my $mess; | ||||
| 457 | my $err = join '', @error; | ||||
| 458 | $i++; | ||||
| 459 | |||||
| 460 | my $tid_msg = ''; | ||||
| 461 | if ( defined &threads::tid ) { | ||||
| 462 | my $tid = threads->tid; | ||||
| 463 | $tid_msg = " thread $tid" if $tid; | ||||
| 464 | } | ||||
| 465 | |||||
| 466 | my %i = caller_info($i); | ||||
| 467 | $mess = "$err at $i{file} line $i{line}$tid_msg"; | ||||
| 468 | if( defined $. ) { | ||||
| 469 | local $@ = ''; | ||||
| 470 | local $SIG{__DIE__}; | ||||
| 471 | eval { | ||||
| 472 | CORE::die; | ||||
| 473 | }; | ||||
| 474 | if($@ =~ /^Died at .*(, <.*?> line \d+).$/ ) { | ||||
| 475 | $mess .= $1; | ||||
| 476 | } | ||||
| 477 | } | ||||
| 478 | $mess .= "\.\n"; | ||||
| 479 | |||||
| 480 | while ( my %i = caller_info( ++$i ) ) { | ||||
| 481 | $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; | ||||
| 482 | } | ||||
| 483 | |||||
| 484 | return $mess; | ||||
| 485 | } | ||||
| 486 | |||||
| 487 | # spent 146µs (23+123) within Carp::ret_summary which was called 3 times, avg 49µs/call:
# 3 times (23µs+123µs) by Carp::shortmess_heavy at line 543, avg 49µs/call | ||||
| 488 | 3 | 2µs | my ( $i, @error ) = @_; | ||
| 489 | 3 | 2µs | my $err = join '', @error; | ||
| 490 | 3 | 300ns | $i++; | ||
| 491 | |||||
| 492 | 3 | 700ns | my $tid_msg = ''; | ||
| 493 | 3 | 900ns | if ( defined &threads::tid ) { | ||
| 494 | my $tid = threads->tid; | ||||
| 495 | $tid_msg = " thread $tid" if $tid; | ||||
| 496 | } | ||||
| 497 | |||||
| 498 | 3 | 8µs | 3 | 123µs | my %i = caller_info($i); # spent 123µs making 3 calls to Carp::caller_info, avg 41µs/call |
| 499 | 3 | 9µs | return "$err at $i{file} line $i{line}$tid_msg\.\n"; | ||
| 500 | } | ||||
| 501 | |||||
| 502 | # spent 465µs (162+303) within Carp::short_error_loc which was called 16 times, avg 29µs/call:
# 13 times (121µs+247µs) by warnings::__chk at line 451 of warnings.pm, avg 28µs/call
# 3 times (41µs+56µs) by Carp::shortmess_heavy at line 542, avg 32µs/call | ||||
| 503 | # You have to create your (hash)ref out here, rather than defaulting it | ||||
| 504 | # inside trusts *on a lexical*, as you want it to persist across calls. | ||||
| 505 | # (You can default it on $_[2], but that gets messy) | ||||
| 506 | 16 | 5µs | my $cache = {}; | ||
| 507 | 16 | 2µs | my $i = 1; | ||
| 508 | 16 | 2µs | my $lvl = $CarpLevel; | ||
| 509 | { | ||||
| 510 | 54 | 23µs | 38 | 51µs | my $cgc = _cgc(); # spent 51µs making 38 calls to Carp::_cgc, avg 1µs/call |
| 511 | 38 | 10µs | my $called = $cgc ? $cgc->($i) : caller($i); | ||
| 512 | 38 | 3µs | $i++; | ||
| 513 | 38 | 9µs | my $caller = $cgc ? $cgc->($i) : caller($i); | ||
| 514 | |||||
| 515 | 38 | 4µs | if (!defined($caller)) { | ||
| 516 | my @caller = $cgc ? $cgc->($i) : caller($i); | ||||
| 517 | if (@caller) { | ||||
| 518 | # if there's no package but there is other caller info, then | ||||
| 519 | # the package has been deleted - treat this as a valid package | ||||
| 520 | # in this case | ||||
| 521 | redo if defined($called) && $CarpInternal{$called}; | ||||
| 522 | redo unless 0 > --$lvl; | ||||
| 523 | last; | ||||
| 524 | } | ||||
| 525 | else { | ||||
| 526 | return 0; | ||||
| 527 | } | ||||
| 528 | } | ||||
| 529 | 38 | 7µs | redo if $Internal{$caller}; | ||
| 530 | 32 | 5µs | redo if $CarpInternal{$caller}; | ||
| 531 | 29 | 8µs | redo if $CarpInternal{$called}; | ||
| 532 | 16 | 12µs | 16 | 151µs | redo if trusts( $called, $caller, $cache ); # spent 151µs making 16 calls to Carp::trusts, avg 9µs/call |
| 533 | 16 | 9µs | 16 | 100µs | redo if trusts( $caller, $called, $cache ); # spent 100µs making 16 calls to Carp::trusts, avg 6µs/call |
| 534 | 16 | 7µs | redo unless 0 > --$lvl; | ||
| 535 | } | ||||
| 536 | 16 | 32µs | return $i - 1; | ||
| 537 | } | ||||
| 538 | |||||
| 539 | # spent 256µs (13+243) within Carp::shortmess_heavy which was called 3 times, avg 85µs/call:
# 3 times (13µs+243µs) by Carp::shortmess at line 163, avg 85µs/call | ||||
| 540 | 3 | 900ns | return longmess_heavy(@_) if $Verbose; | ||
| 541 | 3 | 700ns | return @_ if ref( $_[0] ); # don't break references as exceptions | ||
| 542 | 3 | 3µs | 3 | 97µs | my $i = short_error_loc(); # spent 97µs making 3 calls to Carp::short_error_loc, avg 32µs/call |
| 543 | 3 | 7µs | 3 | 146µs | if ($i) { # spent 146µs making 3 calls to Carp::ret_summary, avg 49µs/call |
| 544 | ret_summary( $i, @_ ); | ||||
| 545 | } | ||||
| 546 | else { | ||||
| 547 | longmess_heavy(@_); | ||||
| 548 | } | ||||
| 549 | } | ||||
| 550 | |||||
| 551 | # If a string is too long, trims it with ... | ||||
| 552 | sub str_len_trim { | ||||
| 553 | my $str = shift; | ||||
| 554 | my $max = shift || 0; | ||||
| 555 | if ( 2 < $max and $max < length($str) ) { | ||||
| 556 | substr( $str, $max - 3 ) = '...'; | ||||
| 557 | } | ||||
| 558 | return $str; | ||||
| 559 | } | ||||
| 560 | |||||
| 561 | # Takes two packages and an optional cache. Says whether the | ||||
| 562 | # first inherits from the second. | ||||
| 563 | # | ||||
| 564 | # Recursive versions of this have to work to avoid certain | ||||
| 565 | # possible endless loops, and when following long chains of | ||||
| 566 | # inheritance are less efficient. | ||||
| 567 | sub trusts { | ||||
| 568 | 32 | 5µs | my $child = shift; | ||
| 569 | 32 | 3µs | my $parent = shift; | ||
| 570 | 32 | 3µs | my $cache = shift; | ||
| 571 | 32 | 21µs | 32 | 174µs | my ( $known, $partial ) = get_status( $cache, $child ); # spent 174µs making 32 calls to Carp::get_status, avg 5µs/call |
| 572 | |||||
| 573 | # Figure out consequences until we have an answer | ||||
| 574 | 32 | 9µs | while ( @$partial and not exists $known->{$parent} ) { | ||
| 575 | my $anc = shift @$partial; | ||||
| 576 | next if exists $known->{$anc}; | ||||
| 577 | $known->{$anc}++; | ||||
| 578 | my ( $anc_knows, $anc_partial ) = get_status( $cache, $anc ); | ||||
| 579 | my @found = keys %$anc_knows; | ||||
| 580 | @$known{@found} = (); | ||||
| 581 | push @$partial, @$anc_partial; | ||||
| 582 | } | ||||
| 583 | 32 | 35µs | return exists $known->{$parent}; | ||
| 584 | } | ||||
| 585 | |||||
| 586 | # Takes a package and gives a list of those trusted directly | ||||
| 587 | # spent 69µs within Carp::trusts_directly which was called 32 times, avg 2µs/call:
# 32 times (69µs+0s) by Carp::get_status at line 379, avg 2µs/call | ||||
| 588 | 32 | 4µs | my $class = shift; | ||
| 589 | 2 | 64µs | 2 | 25µs | # spent 16µs (6+10) within Carp::BEGIN@589 which was called:
# once (6µs+10µs) by Attribute::Handlers::BEGIN@3 at line 589 # spent 16µs making 1 call to Carp::BEGIN@589
# spent 10µs making 1 call to strict::unimport |
| 590 | 32 | 17µs | my $stash = \%{"$class\::"}; | ||
| 591 | 32 | 10µs | for my $var (qw/ CARP_NOT ISA /) { | ||
| 592 | # Don't try using the variable until we know it exists, | ||||
| 593 | # to avoid polluting the caller's namespace. | ||||
| 594 | 64 | 18µs | if ( $stash->{$var} && *{$stash->{$var}}{ARRAY} && @{$stash->{$var}} ) { | ||
| 595 | return @{$stash->{$var}} | ||||
| 596 | } | ||||
| 597 | } | ||||
| 598 | 32 | 33µs | return; | ||
| 599 | } | ||||
| 600 | |||||
| 601 | 1 | 600ns | if(!defined($warnings::VERSION) || | ||
| 602 | 3 | 28µs | 2 | 18µs | # spent 12µs (6+6) within Carp::BEGIN@602 which was called:
# once (6µs+6µs) by Attribute::Handlers::BEGIN@3 at line 602 # spent 12µs making 1 call to Carp::BEGIN@602
# spent 6µs making 1 call to warnings::unimport |
| 603 | # Very old versions of warnings.pm import from Carp. This can go | ||||
| 604 | # wrong due to the circular dependency. If Carp is invoked before | ||||
| 605 | # warnings, then Carp starts by loading warnings, then warnings | ||||
| 606 | # tries to import from Carp, and gets nothing because Carp is in | ||||
| 607 | # the process of loading and hasn't defined its import method yet. | ||||
| 608 | # So we work around that by manually exporting to warnings here. | ||||
| 609 | 2 | 56µs | 2 | 21µs | # spent 13µs (5+8) within Carp::BEGIN@609 which was called:
# once (5µs+8µs) by Attribute::Handlers::BEGIN@3 at line 609 # spent 13µs making 1 call to Carp::BEGIN@609
# spent 8µs making 1 call to strict::unimport |
| 610 | *{"warnings::$_"} = \&$_ foreach @EXPORT; | ||||
| 611 | } | ||||
| 612 | |||||
| 613 | 1 | 8µs | 1; | ||
| 614 | |||||
| 615 | __END__ | ||||
# spent 5µs within Carp::CORE:match which was called 6 times, avg 800ns/call:
# 6 times (5µs+0s) by Carp::format_arg at line 286, avg 800ns/call | |||||
sub Carp::CORE:subst; # opcode |