From: Steve Hay Date: Tue, 3 May 2005 08:51:24 +0000 (+0000) Subject: Fix croak() and confess() so that they don't clobber $! X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=62e1ddac2ea58cd2a35011515be4801254772ba8;p=p5sagit%2Fp5-mst-13.2.git Fix croak() and confess() so that they don't clobber $! (plus tests to check this) p4raw-id: //depot/perl@24374 --- diff --git a/lib/Carp.pm b/lib/Carp.pm index b2e634c..d2854c0 100644 --- a/lib/Carp.pm +++ b/lib/Carp.pm @@ -226,8 +226,8 @@ sub export_fail { sub longmess { { - local $@; - # XXX fix require to not clear $@? + local($@, $!); + # XXX fix require to not clear $@ or $!? # don't use require unless we need to (for Safe compartments) require Carp::Heavy unless $INC{"Carp/Heavy.pm"}; } @@ -251,8 +251,8 @@ sub longmess { sub shortmess { # Short-circuit &longmess if called via multiple packages { - local $@; - # XXX fix require to not clear $@? + local($@, $!); + # XXX fix require to not clear $@ or $!? # don't use require unless we need to (for Safe compartments) require Carp::Heavy unless $INC{"Carp/Heavy.pm"}; } diff --git a/lib/Carp.t b/lib/Carp.t index 47f83c9..d07e202 100644 --- a/lib/Carp.t +++ b/lib/Carp.t @@ -6,7 +6,7 @@ BEGIN { use Carp qw(carp cluck croak confess); -plan tests => 19; +plan tests => 21; ok 1; @@ -155,3 +155,9 @@ sub w { cluck @_ } main::w(1); } } + +# Check that croak() and confess() don't clobber $! +runperl(prog => 'use Carp; $@=q{Phooey}; $!=42; croak(q{Dead})', stderr => 1); +is($?>>8, 42, 'croak() doesn\'t clobber $!'); +runperl(prog => 'use Carp; $@=q{Phooey}; $!=42; confess(q{Dead})', stderr => 1); +is($?>>8, 42, 'confess() doesn\'t clobber $!');