[Bast-commits] r9369 - in DBIx-Class/0.08/branches/try-tiny: .
lib/DBIx lib/DBIx/Class lib/DBIx/Class/Schema lib/DBIx/Class/Storage
tonvoon at dev.catalyst.perl.org
tonvoon at dev.catalyst.perl.org
Fri May 14 21:25:02 GMT 2010
Author: tonvoon
Date: 2010-05-14 22:25:02 +0100 (Fri, 14 May 2010)
New Revision: 9369
Modified:
DBIx-Class/0.08/branches/try-tiny/Makefile.PL
DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class.pm
DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Schema/Versioned.pm
DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage.pm
DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm
Log:
Conversion of eval => try (part 1)
Modified: DBIx-Class/0.08/branches/try-tiny/Makefile.PL
===================================================================
--- DBIx-Class/0.08/branches/try-tiny/Makefile.PL 2010-05-14 21:01:42 UTC (rev 9368)
+++ DBIx-Class/0.08/branches/try-tiny/Makefile.PL 2010-05-14 21:25:02 UTC (rev 9369)
@@ -50,6 +50,7 @@
'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
Modified: DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Schema/Versioned.pm
===================================================================
--- DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Schema/Versioned.pm 2010-05-14 21:01:42 UTC (rev 9368)
+++ DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Schema/Versioned.pm 2010-05-14 21:25:02 UTC (rev 9369)
@@ -503,8 +503,9 @@
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;
};
@@ -723,10 +724,14 @@
{
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;
}
Modified: DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm 2010-05-14 21:01:42 UTC (rev 9368)
+++ DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage/DBI.pm 2010-05-14 21:25:02 UTC (rev 9369)
@@ -15,6 +15,7 @@
use List::Util();
use Data::Dumper::Concise();
use Sub::Name ();
+use Try::Tiny;
use File::Path ();
@@ -157,8 +158,7 @@
# some databases need this to stop spewing warnings
if (my $dbh = $self->_dbh) {
- local $@;
- eval {
+ try {
%{ $dbh->{CachedKids} } = ();
$dbh->disconnect;
};
Modified: DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage.pm
===================================================================
--- DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage.pm 2010-05-14 21:01:42 UTC (rev 9368)
+++ DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class/Storage.pm 2010-05-14 21:25:02 UTC (rev 9369)
@@ -158,16 +158,15 @@
};
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
@@ -197,7 +196,7 @@
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
@@ -212,16 +211,12 @@
$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
@@ -230,9 +225,8 @@
$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;
Modified: DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class.pm 2010-05-14 21:01:42 UTC (rev 9368)
+++ DBIx-Class/0.08/branches/try-tiny/lib/DBIx/Class.pm 2010-05-14 21:25:02 UTC (rev 9369)
@@ -11,6 +11,7 @@
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(@_);
@@ -42,8 +43,14 @@
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;
More information about the Bast-commits
mailing list