From: Glenn Linderman Date: Mon, 30 Oct 2006 12:50:21 +0000 (-0800) Subject: Re: New version diagnostic breaks a bunch of modules. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=746d7dd7d06cedb05d9bb8a5b7714677c4dba404;p=p5sagit%2Fp5-mst-13.2.git Re: New version diagnostic breaks a bunch of modules. Message-ID: <4546658D.6090507@NevCal.com> p4raw-id: //depot/perl@29230 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 5ef30d7..db1980f 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -1288,13 +1288,17 @@ trapped within an eval(), $@ contains the reference. This behavior permits a more elaborate exception handling implementation using objects that maintain arbitrary state about the nature of the exception. Such a scheme is sometimes preferable to matching particular string values of $@ using -regular expressions. Here's an example: +regular expressions. Because $@ is a global variable, and eval() may be +used within object implementations, care must be taken that analyzing the +error object doesn't replace the reference in the global variable. The +easiest solution is to make a local copy of the reference before doing +other manipulations. Here's an example: use Scalar::Util 'blessed'; eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; - if ($@) { - if (blessed($@) && $@->isa("Some::Module::Exception")) { + if (my $ev_err = $@) { + if (blessed($ev_err) && $ev_err->isa("Some::Module::Exception")) { # handle Some::Module::Exception } else {