From: Steve Hay Date: Wed, 21 Sep 2005 16:19:03 +0000 (+0000) Subject: Localize $@ in Locale::Maketext::maketext() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5350a4e5afd114d2b90f90330f8524ae889fdb03;p=p5sagit%2Fp5-mst-13.2.git Localize $@ in Locale::Maketext::maketext() so that $lh->maketext("Error: [_1]\n", $@) works as expected Also added a new test for this fix p4raw-id: //depot/perl@25547 --- diff --git a/lib/Locale/Maketext.pm b/lib/Locale/Maketext.pm index 98c4450..f60d03d 100644 --- a/lib/Locale/Maketext.pm +++ b/lib/Locale/Maketext.pm @@ -14,7 +14,7 @@ use I18N::LangTags 0.30 (); BEGIN { unless(defined &DEBUG) { *DEBUG = sub () {0} } } # define the constant 'DEBUG' at compile-time -$VERSION = "1.09"; +$VERSION = "1.09_01"; @ISA = (); $MATCH_SUPERS = 1; @@ -175,6 +175,9 @@ sub maketext { my($handle, $phrase) = splice(@_,0,2); + # Don't interefere with $@ in case that's being interpolated into the msg. + local $@; + # Look up the value: my $value; diff --git a/lib/Locale/Maketext/t/30_local.t b/lib/Locale/Maketext/t/30_local.t new file mode 100644 index 0000000..a3761dd --- /dev/null +++ b/lib/Locale/Maketext/t/30_local.t @@ -0,0 +1,30 @@ + +require 5; +use Test; +BEGIN { plan tests => 4; } +use Locale::Maketext; +print "# Hi there...\n"; +ok 1; + +print "# --- Making sure that Perl globals are localized ---\n"; + +# declare a class... +{ + package Woozle; + @ISA = ('Locale::Maketext'); + %Lexicon = ( + _AUTO => 1 + ); + keys %Lexicon; # dodges the 'used only once' warning +} + +my $lh; +print "# Basic sanity:\n"; +ok defined( $lh = Woozle->new() ) && ref($lh); + +print "# Make sure \$@ is localized...\n"; +$@ = 'foo'; +ok $lh && $lh->maketext('Eval error: [_1]', $@), "Eval error: foo"; + +print "# Byebye!\n"; +ok 1;