'Data::Dumper::Concise' => '1.000',
'Scope::Guard' => '0.03',
'Context::Preserve' => '0.01',
+ 'Try::Tiny' => '0.04',
};
# this is so we can order requires alphabetically
use vars qw($VERSION);
use base qw/DBIx::Class::Componentised Class::Accessor::Grouped/;
use DBIx::Class::StartupCheck;
+use Try::Tiny;
sub mk_classdata {
shift->mk_classaccessor(@_);
sub _attr_cache {
my $self = shift;
my $cache = $self->can('__attr_cache') ? $self->__attr_cache : {};
- my $rest = eval { $self->next::method };
- return $@ ? $cache : { %$cache, %$rest };
+ my $rest;
+ my $exception;
+ try {
+ $rest = $self->next::method;
+ } catch {
+ $exception = 1;
+ };
+ return $exception ? $cache : { %$cache, %$rest };
}
1;
my ($self, $rs) = @_;
my $vtable = $self->{vschema}->resultset('Table');
- my $version = eval {
- $vtable->search({}, { order_by => { -desc => 'installed' }, rows => 1 } )
+ my $version;
+ try {
+ $version = $vtable->search({}, { order_by => { -desc => 'installed' }, rows => 1 } )
->get_column ('version')
->next;
};
{
my ($self, $rs) = @_;
- my $c = eval {
- $rs->search({ 1, 0 })->count;
+ my $c;
+ my $exception;
+ try {
+ $c = $rs->search({ 1, 0 })->count;
+ } catch {
+ $exception=1;
};
- return 0 if $@ || !defined $c;
+ return 0 if $exception || !defined $c;
return 1;
}
};
my $rs;
- eval {
+ try {
$rs = $schema->txn_do($coderef);
- };
-
- if ($@) { # Transaction failed
+ } catch {
+ # Transaction failed
die "something terrible has happened!" #
if ($@ =~ /Rollback failed/); # Rollback failed
deal_with_failed_transaction();
- }
+ };
In a nested transaction (calling txn_do() from within a txn_do() coderef) only
the outermost transaction will issue a L</txn_commit>, and txn_do() can be
my $wantarray = wantarray; # Need to save this since the context
# inside the eval{} block is independent
# of the context that called txn_do()
- eval {
+ try {
# Need to differentiate between scalar/list context to allow for
# returning a list in scalar context to get the size of the list
$coderef->(@args);
}
$self->txn_commit;
- };
-
- if ($@) {
+ } catch {
my $error = $@;
- eval {
+ try {
$self->txn_rollback;
- };
-
- if ($@) {
+ } catch {
my $rollback_error = $@;
my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
$self->throw_exception($error) # propagate nested rollback
$self->throw_exception(
"Transaction aborted: $error. Rollback failed: ${rollback_error}"
);
- } else {
- $self->throw_exception($error); # txn failed but rollback succeeded
}
+ $self->throw_exception($error); # txn failed but rollback succeeded
}
return $wantarray ? @return_values : $return_value;
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;
};