Commit | Line | Data |
---|---|---|
a0d0e21e LW |
1 | package Carp; |
2 | ||
3 | # This package implements handy routines for modules that wish to throw | |
4 | # exceptions outside of the current package. | |
5 | ||
6 | require Exporter; | |
7 | @ISA = Exporter; | |
8 | @EXPORT = qw(confess croak carp); | |
9 | ||
10 | sub longmess { | |
11 | my $error = shift; | |
12 | my $mess = ""; | |
13 | my $i = 2; | |
14 | my ($pack,$file,$line,$sub); | |
15 | while (($pack,$file,$line,$sub) = caller($i++)) { | |
16 | $mess .= "\t$sub " if $error eq "called"; | |
17 | $mess .= "$error at $file line $line\n"; | |
18 | $error = "called"; | |
19 | } | |
20 | $mess || $error; | |
21 | } | |
22 | ||
23 | sub shortmess { | |
24 | my $error = shift; | |
25 | my ($curpack) = caller(1); | |
26 | my $i = 2; | |
27 | my ($pack,$file,$line,$sub); | |
28 | while (($pack,$file,$line,$sub) = caller($i++)) { | |
29 | return "$error at $file line $line\n" if $pack ne $curpack; | |
30 | } | |
31 | longmess $error; | |
32 | } | |
33 | ||
34 | sub confess { die longmess @_; } | |
35 | sub croak { die shortmess @_; } | |
36 | sub carp { warn shortmess @_; } | |
37 |