This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.000
[perl5.git] / lib / Carp.pm
... / ...
CommitLineData
1package Carp;
2
3# This package implements handy routines for modules that wish to throw
4# exceptions outside of the current package.
5
6require Exporter;
7@ISA = Exporter;
8@EXPORT = qw(confess croak carp);
9
10sub 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
23sub 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
34sub confess { die longmess @_; }
35sub croak { die shortmess @_; }
36sub carp { warn shortmess @_; }
37