Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Proper exception handling on Perl < 5.14.

  • Loading branch information...
commit f19491fe54ba88683e9a2bf62c1110ce68198779 1 parent d7d2fbf
David E. Wheeler authored
Showing with 41 additions and 25 deletions.
  1. +2 −0  Changes
  2. +39 −25 lib/DBIx/Connector.pm
2  Changes
View
@@ -1,6 +1,8 @@
Revision history for Perl extension DBIx::Connector.
0.51
+ - Fixed internal exception handling on Perls less than 5.14, where some
+ exceptions woult not be propagated to the caller.
0.50 2012-02-14T18:25:07Z
- The `catch` functionality has been completely removed. Any `catch`
64 lib/DBIx/Connector.pm
View
@@ -162,10 +162,14 @@ sub _fixup_run {
if $self->{_in_run} || !$dbh->FETCH('AutoCommit');
local $self->{_in_run} = 1;
- local $@;
- my @ret = eval { _exec( $dbh, $code, $wantarray ) };
+ my ($err, @ret);
+ TRY: {
+ local $@;
+ @ret = eval { _exec( $dbh, $code, $wantarray ) };
+ $err = $@;
+ }
- if (my $err = $@) {
+ if ($err) {
die $err if $self->connected;
# Not connected. Try again.
return _exec( $self->_connect, $code, $wantarray, @_ );
@@ -193,15 +197,18 @@ sub _txn_run {
return _exec( $dbh, $code, $wantarray );
}
- my @ret; local $@;
- eval {
- local $self->{_in_run} = 1;
- $driver->begin_work($dbh);
- @ret = _exec( $dbh, $code, $wantarray );
- $driver->commit($dbh);
- };
+ my ($err, @ret);
+ TRY: {
+ eval {
+ local $self->{_in_run} = 1;
+ $driver->begin_work($dbh);
+ @ret = _exec( $dbh, $code, $wantarray );
+ $driver->commit($dbh);
+ };
+ $err = $@;
+ }
- if (my $err = $@) {
+ if ($err) {
$err = $driver->_rollback($dbh, $err);
die $err;
}
@@ -219,27 +226,34 @@ sub _txn_fixup_run {
return _exec( $dbh, $code, $wantarray ) unless $dbh->FETCH('AutoCommit');
- my @ret; local $@;
- eval {
- $driver->begin_work($dbh);
- @ret = _exec( $dbh, $code, $wantarray );
- $driver->commit($dbh);
- };
+ my ($err, @ret);
+ TRY: {
+ eval {
+ $driver->begin_work($dbh);
+ @ret = _exec( $dbh, $code, $wantarray );
+ $driver->commit($dbh);
+ };
+ $err = $@;
+ }
- if (my $err = $@) {
+ if ($err) {
if ($self->connected) {
$err = $driver->_rollback($dbh, $err);
die $err;
}
+
# Not connected. Try again.
- local $@;
$dbh = $self->_connect;
- eval {
- $driver->begin_work($dbh);
- @ret = _exec( $dbh, $code, $wantarray );
- $driver->commit($dbh);
- };
- if ($err = $@) {
+ TRY: {
+ local $@;
+ eval {
+ $driver->begin_work($dbh);
+ @ret = _exec( $dbh, $code, $wantarray );
+ $driver->commit($dbh);
+ };
+ $err = $@;
+ }
+ if ($err) {
$err = $driver->_rollback($dbh, $err);
die $err;
}
Please sign in to comment.
Something went wrong with that request. Please try again.