# Carp::Heavy uses some variables in common with Carp.
package Carp;
=head1 NAME
Carp::Heavy - 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;
package DB;
my %call_info;
@call_info{
qw(pack file line sub has_args wantarray evaltext is_require)
} = caller($i);
unless (defined $call_info{pack}) {
return ();
}
my $sub_name = Carp::get_subname(\%call_info);
if ($call_info{has_args}) {
my @args = map {Carp::format_arg($_)} @DB::args;
if ($MaxArgNums and @args > $MaxArgNums) { # More than we want to show?
$#args = $MaxArgNums;
push @args, '...';
}
# Push the args onto the subroutine
$sub_name .= '(' . join (', ', @args) . ')';
}
$call_info{sub_name} = $sub_name;
return wantarray() ? %call_info : \%call_info;
}
# Transform an argument to a function into a string.
sub format_arg {
my $arg = shift;
if (ref($arg)) {
$arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg";
}elsif (not defined($arg)) {
$arg = 'undef';
}
$arg =~ s/'/\\'/g;
$arg = str_len_trim($arg, $MaxArgLen);
# Quote it?
$arg = "'$arg'" unless $arg =~ /^-?[\d.]+\z/;
# The following handling of "control chars" is direct from
# the original code - it is broken on Unicode though.
# Suggestions?
utf8::is_utf8($arg)
or $arg =~ s/([[:cntrl:]]|[[:^ascii:]])/sprintf("\\x{%x}",ord($1))/eg;
return $arg;
}
# Takes an inheritance cache and a package and returns
# an anon hash of known inheritances and anon array of
# inheritances which consequences have not been figured
# for.
sub get_status {
my $cache = shift;
my $pkg = shift;
$cache->{$pkg} ||= [{$pkg => $pkg}, [trusts_directly($pkg)]];
return @{$cache->{$pkg}};
}
# Takes the info from caller() and figures out the name of
# the sub/require/eval
sub get_subname {
my $info = shift;
if (defined($info->{evaltext})) {
my $eval = $info->{evaltext};
if ($info->{is_require}) {
return "require $eval";
}
else {
$eval =~ s/([\\\'])/\\$1/g;
return "eval '" . str_len_trim($eval, $MaxEvalLen) . "'";
}
}
return ($info->{sub} eq '(eval)') ? 'eval {...}' : $info->{sub};
}
# Figures out what call (from the point of view of the caller)
# the long error backtrace should start at.
sub long_error_loc {
my $i;
my $lvl = $CarpLevel;
{
my $pkg = caller(++$i);
=1= |