Forgotten thing.
[p5sagit/p5-mst-13.2.git] / lib / Carp.pm
index eaa4d53..f2e042e 100644 (file)
@@ -1,5 +1,7 @@
 package Carp;
 
+our $VERSION = '1.00';
+
 =head1 NAME
 
 carp    - warn of errors (from perspective of caller)
@@ -19,6 +21,9 @@ confess - die of errors with stack backtrace
     use Carp qw(cluck);
     cluck "This is how we got here!";
 
+    print FH Carp::shortmess("This will have caller's details added");
+    print FH Carp::longmess("This will have stack backtrace added");
+
 =head1 DESCRIPTION
 
 The Carp routines are useful in your own modules because
@@ -28,6 +33,11 @@ routine Foo() that has a carp() in it, then the carp()
 will report the error as occurring where Foo() was called, 
 not where carp() was called.
 
+The routine shortmess() can be used to generate the string that
+carp/croak would have produced.   The routine longmess() can be
+used to generate the backtrace that cluck/confess would have
+produced.
+
 =head2 Forcing a Stack Trace
 
 As a debugging aid, you can force Carp to treat a croak as a confess
@@ -68,10 +78,12 @@ $MaxArgLen = 64;        # How much of each argument to print. 0 = all.
 $MaxArgNums = 8;        # How many arguments to print. 0 = all.
 $Verbose = 0;          # If true then make shortmess call longmess instead
 
+$CarpInternal{Carp}++;
+
 require Exporter;
 @ISA = ('Exporter');
 @EXPORT = qw(confess croak carp);
-@EXPORT_OK = qw(cluck verbose);
+@EXPORT_OK = qw(cluck verbose longmess shortmess);
 @EXPORT_FAIL = qw(verbose);    # hook to enable verbose mode
 
 
@@ -94,7 +106,7 @@ sub export_fail {
 # each function call on the stack.
 
 sub longmess {
-    require Carp::Heavy;
+    { local $@; require Carp::Heavy; } # XXX fix require to not clear $@?
     goto &longmess_heavy;
 }
 
@@ -106,7 +118,7 @@ sub longmess {
 # you always get a stack trace
 
 sub shortmess {        # Short-circuit &longmess if called via multiple packages
-    require Carp::Heavy;
+    { local $@; require Carp::Heavy; } # XXX fix require to not clear $@?
     goto &shortmess_heavy;
 }