X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCarp%2FHeavy.pm;h=c3d3c26fa1ae61ab10d6ee898410549278eabe42;hb=98e3f270ffa30af1413b4c0412a1027dbc9b03ed;hp=d7b8990b6e02205e4e73ed351dfe842502bab354;hpb=66a4a569cc2ea11fe85bfadbec79dcd4fbf36d17;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Carp/Heavy.pm b/lib/Carp/Heavy.pm index d7b8990..c3d3c26 100644 --- a/lib/Carp/Heavy.pm +++ b/lib/Carp/Heavy.pm @@ -1,5 +1,18 @@ +# Carp::Heavy uses some variables in common with Carp. package Carp; +=head1 NAME + +Carp heavy machinery - no user serviceable parts inside + +=cut + +# use strict; # not yet + +# On one line so MakeMaker will see it. +use Carp; our $VERSION = $Carp::VERSION; + +our ($CarpLevel, $MaxArgNums, $MaxEvalLen, $MaxArgLen, $Verbose); sub caller_info { my $i = shift(@_) + 1; @@ -15,8 +28,7 @@ sub caller_info { my $sub_name = Carp::get_subname(\%call_info); if ($call_info{has_args}) { - # Reuse the @args array to avoid warnings. :-) - local @args = map {Carp::format_arg($_)} @args; + my @args = map {Carp::format_arg($_)} @DB::args; if ($MaxArgNums and @args > $MaxArgNums) { # More than we want to show? $#args = $MaxArgNums; push @args, '...'; @@ -35,10 +47,10 @@ sub format_arg { $arg = 'undef'; } elsif (ref($arg)) { - $arg .= ''; # Make it a string; + $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg"; } $arg =~ s/'/\\'/g; - $arg = str_len_trim($arg, $MaxLenArg); + $arg = str_len_trim($arg, $MaxArgLen); # Quote it? $arg = "'$arg'" unless $arg =~ /^-?[\d.]+\z/; @@ -46,8 +58,7 @@ sub format_arg { # The following handling of "control chars" is direct from # the original code - I think it is broken on Unicode though. # Suggestions? - $arg =~ s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg; - $arg =~ s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg; + $arg =~ s/([[:cntrl:]]|[[:^ascii:]])/sprintf("\\x{%x}",ord($1))/eg; return $arg; } @@ -66,14 +77,14 @@ sub get_status { # the sub/require/eval sub get_subname { my $info = shift; - if (defined($info->{eval})) { - my $eval = $info->{eval}; + if (defined($info->{evaltext})) { + my $eval = $info->{evaltext}; if ($info->{is_require}) { return "require $eval"; } else { $eval =~ s/([\\\'])/\\$1/g; - return str_len_trim($eval, $MaxEvalLen); + return "eval '" . str_len_trim($eval, $MaxEvalLen) . "'"; } } @@ -108,7 +119,7 @@ sub long_error_loc { sub longmess_heavy { - return @_ if ref($_[0]); # WHAT IS THIS FOR??? + return @_ if ref($_[0]); # don't break references as exceptions my $i = long_error_loc(); return ret_backtrace($i, @_); } @@ -127,18 +138,19 @@ sub ret_backtrace { $tid_msg = " thread $tid" if $tid; } - if ($err =~ /\n$/) { + { if ($err =~ /\n$/) { # extra block to localise $1 etc $mess = $err; } else { my %i = caller_info($i); $mess = "$err at $i{file} line $i{line}$tid_msg\n"; - } + }} while (my %i = caller_info(++$i)) { $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; + } - return $mess || $err; + return $mess; } sub ret_summary { @@ -177,7 +189,7 @@ sub short_error_loc { sub shortmess_heavy { return longmess_heavy(@_) if $Verbose; - return @_ if ref($_[0]); # WHAT IS THIS FOR??? + return @_ if ref($_[0]); # don't break references as exceptions my $i = short_error_loc(); if ($i) { ret_summary($i, @_); @@ -224,7 +236,11 @@ sub trusts { # Takes a package and gives a list of those trusted directly sub trusts_directly { my $class = shift; - return @{"$class\::ISA"}; + no strict 'refs'; + no warnings 'once'; + return @{"$class\::CARP_NOT"} + ? @{"$class\::CARP_NOT"} + : @{"$class\::ISA"}; } 1;