12 qw(pack file line sub has_args wantarray evaltext is_require)
15 unless (defined $call_info{pack}) {
19 my $sub_name = Carp::get_subname(\%call_info);
20 if ($call_info{has_args}) {
21 # Reuse the @args array to avoid warnings. :-)
22 local @args = map {Carp::format_arg($_)} @args;
23 if ($MaxArgNums and @args > $MaxArgNums) { # More than we want to show?
27 # Push the args onto the subroutine
28 $sub_name .= '(' . join (',', @args) . ')';
30 $call_info{sub_name} = $sub_name;
31 return wantarray() ? %call_info : \%call_info;
34 # Transform an argument to a function into a string.
37 if (not defined($arg)) {
41 $arg .= ''; # Make it a string;
44 $arg = str_len_trim($arg, $MaxLenArg);
47 $arg = "'$arg'" unless $arg =~ /^-?[\d.]+\z/;
49 # The following handling of "control chars" is direct from
50 # the original code - I think it is broken on Unicode though.
52 $arg =~ s/([[:cntrl:]]|[[^:ascii:]])/sprintf("\\x{%x}",ord($1))/eg;
56 # Takes an inheritance cache and a package and returns
57 # an anon hash of known inheritances and anon array of
58 # inheritances which consequences have not been figured
63 $cache->{$pkg} ||= [{$pkg => $pkg}, [trusts_directly($pkg)]];
64 return @{$cache->{$pkg}};
67 # Takes the info from caller() and figures out the name of
68 # the sub/require/eval
71 if (defined($info->{eval})) {
72 my $eval = $info->{eval};
73 if ($info->{is_require}) {
74 return "require $eval";
77 $eval =~ s/([\\\'])/\\$1/g;
78 return str_len_trim($eval, $MaxEvalLen);
82 return ($info->{sub} eq '(eval)') ? 'eval {...}' : $info->{sub};
85 # Figures out what call (from the point of view of the caller)
86 # the long error backtrace should start at.
91 my $pkg = caller(++$i);
92 unless(defined($pkg)) {
93 # This *shouldn't* happen.
96 $i = long_error_loc();
100 # OK, now I am irritated.
104 redo if $CarpInternal{$pkg};
105 redo unless 0 > --$lvl;
106 redo if $Internal{$pkg};
113 return @_ if ref($_[0]); # WHAT IS THIS FOR???
114 my $i = long_error_loc();
115 return ret_backtrace($i, @_);
118 # Returns a full stack backtrace starting from where it is
121 my ($i, @error) = @_;
123 my $err = join '', @error;
127 if (defined &Thread::tid) {
128 my $tid = Thread->self->tid;
129 $tid_msg = " thread $tid" if $tid;
136 my %i = caller_info($i);
137 $mess = "$err at $i{file} line $i{line}$tid_msg\n";
140 while (my %i = caller_info(++$i)) {
141 $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n";
144 return $mess || $err;
148 my ($i, @error) = @_;
150 my $err = join '', @error;
154 if (defined &Thread::tid) {
155 my $tid = Thread->self->tid;
156 $tid_msg = " thread $tid" if $tid;
159 my %i = caller_info($i);
160 return "$err at $i{file} line $i{line}$tid_msg\n";
164 sub short_error_loc {
167 my $lvl = $CarpLevel;
169 my $called = caller($i++);
170 my $caller = caller($i);
171 return 0 unless defined($caller); # What happened?
172 redo if $Internal{$caller};
173 redo if $CarpInternal{$called};
174 redo if trusts($called, $caller, $cache);
175 redo if trusts($caller, $called, $cache);
176 redo unless 0 > --$lvl;
181 sub shortmess_heavy {
182 return longmess_heavy(@_) if $Verbose;
183 return @_ if ref($_[0]); # WHAT IS THIS FOR???
184 my $i = short_error_loc();
193 # If a string is too long, trims it with ...
196 my $max = shift || 0;
197 if (2 < $max and $max < length($str)) {
198 substr($str, $max - 3) = '...';
203 # Takes two packages and an optional cache. Says whether the
204 # first inherits from the second.
206 # Recursive versions of this have to work to avoid certain
207 # possible endless loops, and when following long chains of
208 # inheritance are less efficient.
212 my $cache = shift || {};
213 my ($known, $partial) = get_status($cache, $child);
214 # Figure out consequences until we have an answer
215 while (@$partial and not exists $known->{$parent}) {
216 my $anc = shift @$partial;
217 next if exists $known->{$anc};
219 my ($anc_knows, $anc_partial) = get_status($cache, $anc);
220 my @found = keys %$anc_knows;
221 @$known{@found} = ();
222 push @$partial, @$anc_partial;
224 return exists $known->{$parent};
227 # Takes a package and gives a list of those trusted directly
228 sub trusts_directly {
230 return @{"$class\::ISA"};