Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CPAN RT 34182 (Locale::Maketext) - Don't unnecessarily localize $@.
Do it in scope only so die messages fall through when desired. Previously, there was test code to make sure $@ was not modified when maketext is called, but if the caller wraps maketext in an eval, then it's going to be modified anyways to '' at the least. If the caller does not wrap a maketext call in an eval and maketext dies, then hiding the $@ simply confuses the person debugging as to what went wrong. We do however backup/restore $@ so that it does not break any code that looks might use $@ after a successful call to maketext. eval {...} $lm->maketext($@); do_something_else($@); In the above example, $@ would be the same when passed to do_something_else
- Loading branch information
Showing
4 changed files
with
78 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use strict; | ||
use warnings; | ||
|
||
{ | ||
package TEST; | ||
use base 'Locale::Maketext'; | ||
} | ||
|
||
{ | ||
package TEST::en; | ||
use base 'TEST'; | ||
our %Lexicon = ( | ||
_AUTO => 1, | ||
); | ||
} | ||
|
||
package main; | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 10; | ||
|
||
my $lh = TEST->get_handle('en'); | ||
$@ = "foo"; | ||
is($lh->maketext("This works fine"), "This works fine", "straight forward _AUTO string test"); | ||
is($@, "foo", q{$@ isn't altered during calls to maketext}); | ||
|
||
my $err = eval { | ||
$lh->maketext('this is ] an error'); | ||
}; | ||
is($err, undef, "no return from eval"); | ||
like("$@", qr/Unbalanced\s'\]',\sin/ms, '$@ shows that ] was unbalanced'); | ||
|
||
# _try_use doesn't pollute $@ | ||
$@ = 'foo2'; | ||
is(Locale::Maketext::_try_use("This::module::does::not::exist"), 0, "0 return if module is missing when _try_use is called"); | ||
is($@, 'foo2', '$@ is unmodified by a failed _try_use'); | ||
|
||
# _try_use doesn't pollute $@ for valid call | ||
$@ = ''; | ||
is(Locale::Maketext::_try_use("Locale::Maketext::Guts"), 1, "1 return using valid module Locale::Maketext::Guts"); | ||
is($@, '', '$@ is clean after failed _try_use'); | ||
|
||
# failure_handler_auto handles $@ locally. | ||
{ | ||
$@ = ''; | ||
my $err = ''; | ||
$lh->{failure_lex}->{"foo_fail"} = sub {die("fail message");}; | ||
$err = eval {$lh->failure_handler_auto("foo_fail")}; | ||
is($err, undef, "die event calling failure_handler on bad code"); | ||
like($@, qr/^Error in maketexting "foo_fail":/ms, "\$@ is re-written as expected."); | ||
} |
This file was deleted.
Oops, something went wrong.