Subject: | DESTROY wipes out exception handling |
If I initialise CGI::Session then die() with a message, the message
gets lost which makes debugging rather frustrating. I am using the
postgresql driver. The error seems to be that eval{} is used within
the cleanup, which wipes out $@ if no error occurs.
The attached patch provides the best description of the problem by
offering a quick-and-dirty fix for my case. There probably is a much
better way; perhaps use Error qw(:try)?
Version CGI::Session 4.07, perl 5.8.6, Linux 2.6.10
Subject: | exception-fix.patch |
diff -U3 -r ./Session/Driver/postgresql.pm /usr/lib/perl5/site_perl/5.8.6/CGI/Session/Driver/postgresql.pm
--- ./Session/Driver/postgresql.pm 2006-03-09 12:02:19.000000000 +0000
+++ /usr/lib/perl5/site_perl/5.8.6/CGI/Session/Driver/postgresql.pm 2006-03-15 13:24:11.560071302 +0000
@@ -63,14 +63,20 @@
sub __ex_and_ret {
my ($dbh,$sql,$datastr,$sid,$type) = @_;
+ my $save_error = $@;
eval {
my $sth = $dbh->prepare($sql) or return 0;
$sth->bind_param(1,$datastr,{ pg_type => $type }) or return 0;
$sth->bind_param(2,$sid) or return 0;
$sth->execute() or return 0;
};
- return 0 if $@;
- return 1;
+ if ($@) {
+ $@ = $save_error;
+ return 0;
+ } else {
+ $@ = $save_error;
+ return 1;
+ }
}
1;