Permalink
Browse files

Some more simplification possible with `catch` gone.

  • Loading branch information...
theory committed Sep 27, 2011
1 parent 1dd7ac1 commit 48729c3a1c58279fe7ca7d9ae19e62130259d6e9
Showing with 11 additions and 25 deletions.
  1. +11 −25 lib/DBIx/Connector.pm
View
@@ -148,35 +148,27 @@ sub run {
sub _run {
my ($self, $code) = @_;
- my $wantarray = wantarray;
my $dbh = $self->{_mode} eq 'ping' ? $self->dbh : $self->_dbh;
local $self->{_in_run} = 1;
- my @ret = _exec( $dbh, $code, $wantarray );
- return $wantarray ? @ret : $ret[0];
+ return _exec( $dbh, $code, wantarray );
}
sub _fixup_run {
my ($self, $code) = @_;
my $dbh = $self->_dbh;
my $wantarray = wantarray;
- if ($self->{_in_run} || !$dbh->FETCH('AutoCommit')) {
- my @ret = eval { _exec( $dbh, $code, $wantarray ) };
- return wantarray ? @ret : $ret[0];
- }
+ return _exec( $dbh, $code, $wantarray )
+ if $self->{_in_run} || !$dbh->FETCH('AutoCommit');
local $self->{_in_run} = 1;
- my (@ret, $err);
- TRY: {
- local $@;
- @ret = eval { _exec( $dbh, $code, $wantarray ) };
- $err = $@;
- }
+ local $@;
+ my @ret = eval { _exec( $dbh, $code, $wantarray ) };
- if ($err) {
+ if (my $err = $@) {
die $err if $self->connected;
# Not connected. Try again.
- @ret = _exec( $self->_connect, $code, $wantarray, @_ );
+ return _exec( $self->_connect, $code, $wantarray, @_ );
}
return $wantarray ? @ret : $ret[0];
@@ -198,12 +190,10 @@ sub _txn_run {
unless ($dbh->FETCH('AutoCommit')) {
local $self->{_in_run} = 1;
- my @ret = _exec( $dbh, $code, $wantarray );
- return $wantarray ? @ret : $ret[0];
+ return _exec( $dbh, $code, $wantarray );
}
- my @ret;
- local $@;
+ my @ret; local $@;
eval {
local $self->{_in_run} = 1;
$driver->begin_work($dbh);
@@ -227,13 +217,9 @@ sub _txn_fixup_run {
my $wantarray = wantarray;
local $self->{_in_run} = 1;
- unless ($dbh->FETCH('AutoCommit')) {
- my @ret = _exec( $dbh, $code, $wantarray );
- return $wantarray ? @ret : $ret[0];
- }
+ return _exec( $dbh, $code, $wantarray ) unless $dbh->FETCH('AutoCommit');
- my @ret;
- local $@;
+ my @ret; local $@;
eval {
$driver->begin_work($dbh);
@ret = _exec( $dbh, $code, $wantarray );

0 comments on commit 48729c3

Please sign in to comment.