Subject: | encode() clobbers $@ |
When Convert::BER->encode() is called from a DESTROY method inside an
eval { }, $@ is overwritten.
I have encountered this with DBD::JDBC (0.70) - please see the attached
minimal test case, and attached patch that fixes the problem for me.
Thanks!
Subject: | convert_ber_eval_clobber_fix.patch |
--- BER.pm.orig 2012-07-26 16:33:01.934316033 +0200
+++ BER.pm 2012-07-26 16:34:12.074124931 +0200
@@ -662,6 +662,7 @@
sub encode {
my $ber = shift;
local($SIG{'__DIE__'});
+ local($@);
$ber->[ Convert::BER::_INDEX() ] = [];
Subject: | convert_ber_eval_clobber_example.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
eval {
my $some_thing=Some::Thing->new;
die "CAUGHT\n";
};
my $error=$@;
isnt($error, '', '$@ is not empty');
is($error, "CAUGHT\n", '$@ is CAUGHT');
done_testing;
package Some::Thing;
use Convert::BER;
sub new {
my ($class)=@_;
return bless {}, $class;
}
sub DESTROY {
my $ber=Convert::BER->new;
$ber->encode(INTEGER=>1); # This clobbers $@
}