3 # This package implements handy routines for modules that wish to throw
4 # exceptions outside of the current package.
6 $CarpLevel = 0; # How many extra package levels to skip on carp.
10 @EXPORT = qw(confess croak carp);
15 my $i = 1 + $CarpLevel;
16 my ($pack,$file,$line,$sub);
17 while (($pack,$file,$line,$sub) = caller($i++)) {
18 $mess .= "\t$sub " if $error eq "called";
19 $mess .= "$error at $file line $line\n";
25 sub shortmess { # Short-circuit &longmess if called via multiple packages
26 my $error = $_[0]; # Instead of "shift"
27 my ($curpack) = caller(1);
28 my $extra = $CarpLevel;
30 my ($pack,$file,$line,$sub);
31 while (($pack,$file,$line,$sub) = caller($i++)) {
32 if ($pack ne $curpack) {
37 return "$error at $file line $line\n";
44 sub confess { die longmess @_; }
45 sub croak { die shortmess @_; }
46 sub carp { warn shortmess @_; }