Subject: | WWW::Scripter::Plugin::JavaScript::Guard makes $@ not usable |
I though this is a bug of WWW::Scripter, so first created it there: https://rt.cpan.org/Ticket/Display.html?id=108645
Copy of this ticket below.
After eval() method $@ becomes always empty. Even after explicit die(). This makes exceptions handling not usable.
Try test below. Expected output: "Error - Fatality!". Actual output: "No errors".
use strict;
use WWW::Scripter;
eval {
my $scripter = WWW::Scripter->new;
$scripter->use_plugin('JavaScript');
$scripter->eval("var t = false;");
die "Fatality!";
};
if (my $err = $@) {
die "Error - $err";
}
warn "No errors";
Solution I found is simple:
--- lib/WWW/Scripter/Plugin/JavaScript.pm.orig 2015-11-10 15:04:57.442103176 +0600
+++ lib/WWW/Scripter/Plugin/JavaScript.pm 2015-11-10 15:05:11.673215672 +0600
@@ -192,7 +192,7 @@
package WWW::Scripter::Plugin::JavaScript::Guard;
sub new { bless \(my $object = pop) }
-DESTROY { eval { ${$_[0]}->destroy } }
+DESTROY { local $@; eval { ${$_[0]}->destroy } }
# ------------------ DOCS --------------------#
Can you apply this patch and make new release?
Thanks.