use List::Util();
use Data::Dumper::Concise();
use Sub::Name ();
+use Try::Tiny;
use File::Path ();
# some databases need this to stop spewing warnings
if (my $dbh = $self->_dbh) {
- local $@;
- eval {
+ try {
%{ $dbh->{CachedKids} } = ();
$dbh->disconnect;
};
my $tried = 0;
while(1) {
- eval {
+ my $exception;
+ my @args = @_;
+ try {
$self->_get_dbh;
$self->txn_begin;
if($want_array) {
- @result = $coderef->(@_);
+ @result = $coderef->(@args);
}
elsif(defined $want_array) {
- $result[0] = $coderef->(@_);
+ $result[0] = $coderef->(@args);
}
else {
- $coderef->(@_);
+ $coderef->(@args);
}
$self->txn_commit;
+ } catch {
+ $exception = $_;
};
- # ->connected might unset $@ - copy
- my $exception = $@;
- if(!$exception) { return $want_array ? @result : $result[0] }
+ if(! defined $exception) { return $want_array ? @result : $result[0] }
if($tried++ || $self->connected) {
- eval { $self->txn_rollback };
- my $rollback_exception = $@;
- if($rollback_exception) {
+ my $rollback_exception;
+ try { $self->txn_rollback } catch { $rollback_exception = shift };
+ if(defined $rollback_exception) {
my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
$self->throw_exception($exception) # propagate nested rollback
if $rollback_exception =~ /$exception_class/;
my %info;
- my $server_version = $self->_get_server_version;
+ my $server_version = do {
+ local $@; # might be happenin in some sort of destructor
+ try { $self->_get_server_version };
+ };
if (defined $server_version) {
$info{dbms_version} = $server_version;
}
sub _get_server_version {
- eval { shift->_get_dbh->get_info(18) };
+ shift->_get_dbh->get_info(18);
}
sub _determine_driver {
$DBI::connect_via = 'connect';
}
- eval {
+ my $caught;
+ try {
if(ref $info[0] eq 'CODE') {
$dbh = $info[0]->();
}
$dbh->{RaiseError} = 1;
$dbh->{PrintError} = 0;
}
+ } catch {
+ $caught = 1;
};
$DBI::connect_via = $old_connect_via if $old_connect_via;
$self->throw_exception("DBI Connection failed: " . ($@||$DBI::errstr))
- if !$dbh || $@;
+ if !$dbh || $caught;
$self->_dbh_autocommit($dbh->{AutoCommit});
sub _dbh_execute_inserts_with_no_binds {
my ($self, $sth, $count) = @_;
- eval {
+ my $exception;
+ try {
my $dbh = $self->_get_dbh;
local $dbh->{RaiseError} = 1;
local $dbh->{PrintError} = 0;
$sth->execute foreach 1..$count;
+ } catch {
+ $exception = shift;
};
- my $exception = $@;
# Make sure statement is finished even if there was an exception.
- eval { $sth->finish };
- $exception = $@ unless $exception;
+ try {
+ $sth->finish
+ } catch {
+ $exception = shift unless defined $exception;
+ };
- $self->throw_exception($exception) if $exception;
+ $self->throw_exception($exception) if defined $exception;
return $count;
}