Permalink
Browse files

Remove `catch` feature.

  • Loading branch information...
1 parent c5b91aa commit c185fa095d433ec9bb7da682e2af45d65f413105 @theory committed Sep 26, 2011
Showing with 30 additions and 407 deletions.
  1. +3 −0 Changes
  2. +18 −68 lib/DBIx/Connector.pm
  3. +0 −81 t/catch.t
  4. +1 −22 t/run.t
  5. +1 −46 t/run_fixup.t
  6. +1 −23 t/run_ping.t
  7. +1 −23 t/svp.t
  8. +1 −21 t/svp_fixup.t
  9. +1 −26 t/svp_ping.t
  10. +1 −23 t/txn.t
  11. +1 −51 t/txn_fixup.t
  12. +1 −23 t/txn_ping.t
View
@@ -1,6 +1,9 @@
Revision history for Perl extension DBIx::Connector.
0.48
+ - The `catch` functionality has been completely removed. Any `catch`
+ block passed to `run()`, `txn()`, or `svp()` will be ignored. Errors
+ will trigger fatal exceptions.
0.47 2011-09-26T17:12:07Z
- Use of the deprecated `catch` functionality now warns on every call,
View
@@ -140,29 +140,17 @@ sub disconnect {
return $self;
}
-sub _errh {
- return $die if !$_[0]
- || ($_[0] ne 'catch' && ref $_[0] ne 'CODE');
-
- require Carp && Carp::carp(
- 'Use of "catch" blocks has been deprecated as of DBIx::Connector 0.46. Please use Try::Tiny instead.'
- );
-
- return $_[0] eq 'catch' ? $_[1] : $_[0];
-}
-
sub run {
my $self = shift;
my $mode = ref $_[0] eq 'CODE' ? $self->{_mode} : shift;
local $self->{_mode} = $mode;
my $code = shift;
- my $errh = &_errh;
- return $self->_fixup_run($code, $errh) if $mode eq 'fixup';
- return $self->_run($code, $errh);
+ return $self->_fixup_run($code) if $mode eq 'fixup';
+ return $self->_run($code);
}
sub _run {
- my ($self, $code, $errh) = @_;
+ my ($self, $code) = @_;
my $wantarray = wantarray;
my ($err, @ret);
TRY: {
@@ -172,12 +160,12 @@ sub _run {
@ret = eval { _exec( $dbh, $code, $wantarray ) };
$err = $@;
}
- if ($err) { return $errh->($err) for $err }
+ if ($err) { return $die->($err) for $err }
return $wantarray ? @ret : $ret[0];
}
sub _fixup_run {
- my ($self, $code, $errh) = @_;
+ my ($self, $code) = @_;
my $dbh = $self->_dbh;
my ($err, @ret);
@@ -187,7 +175,7 @@ sub _fixup_run {
@ret = eval { _exec( $dbh, $code, $wantarray ) };
$err = $@;
}
- if ($err) { return $errh->($err) for $err }
+ if ($err) { return $die->($err) for $err }
return wantarray ? @ret : $ret[0];
}
@@ -199,14 +187,14 @@ sub _fixup_run {
}
if ($err) {
- if ($self->connected) { return $errh->($err) for $err }
+ if ($self->connected) { return $die->($err) for $err }
# Not connected. Try again.
TRY: {
local $@;
@ret = eval { _exec( $self->_connect, $code, $wantarray ) };
$err = $@;
}
- if ($err) { return $errh->($err) for $err }
+ if ($err) { return $die->($err) for $err }
}
return $wantarray ? @ret : $ret[0];
@@ -217,13 +205,12 @@ sub txn {
my $mode = ref $_[0] eq 'CODE' ? $self->{_mode} : shift;
local $self->{_mode} = $mode;
my $code = shift;
- my $errh = &_errh;
- return $self->_txn_fixup_run($code, $errh) if $mode eq 'fixup';
- return $self->_txn_run($code, $errh);
+ return $self->_txn_fixup_run($code) if $mode eq 'fixup';
+ return $self->_txn_run($code);
}
sub _txn_run {
- my ($self, $code, $errh) = @_;
+ my ($self, $code) = @_;
my $driver = $self->driver;
my $wantarray = wantarray;
@@ -235,7 +222,7 @@ sub _txn_run {
unless ($dbh->FETCH('AutoCommit')) {
local $self->{_in_run} = 1;
@ret = eval { _exec( $dbh, $code, $wantarray ) };
- if ($err = $@) { return $errh->($err) for $err }
+ if ($err = $@) { return $die->($err) for $err }
return $wantarray ? @ret : $ret[0];
}
# If we get here, restore the original error.
@@ -255,14 +242,14 @@ sub _txn_run {
if ($err) {
$err = $driver->_rollback($dbh, $err);
- return $errh->($err) for $err;
+ return $die->($err) for $err;
}
return $wantarray ? @ret : $ret[0];
}
sub _txn_fixup_run {
- my ($self, $code, $errh) = @_;
+ my ($self, $code) = @_;
my $dbh = $self->_dbh;
my $driver = $self->driver;
@@ -275,7 +262,7 @@ sub _txn_fixup_run {
@ret = eval { _exec( $dbh, $code, $wantarray ) };
$err = $@;
}
- if ($err) { return $errh->($err) for $err }
+ if ($err) { return $die->($err) for $err }
return wantarray ? @ret : $ret[0];
}
@@ -292,7 +279,7 @@ sub _txn_fixup_run {
if ($err) {
if ($self->connected) {
$err = $driver->_rollback($dbh, $err);
- return $errh->($err) for $err;
+ return $die->($err) for $err;
}
# Not connected. Try again.
TRY: {
@@ -307,7 +294,7 @@ sub _txn_fixup_run {
}
if ($err) {
$err = $driver->_rollback($dbh, $err);
- return $errh->($err) for $err;
+ return $die->($err) for $err;
}
}
@@ -324,7 +311,6 @@ sub svp {
my $mode = ref $_[0] eq 'CODE' ? $self->{_mode} : shift;
local $self->{_mode} = $mode;
my $code = shift;
- my $errh = &_errh;
my ($err, @ret);
my $wantarray = wantarray;
@@ -348,7 +334,7 @@ sub svp {
if ($self->connected) {
$err = $driver->_rollback_and_release($dbh, $name, $err);
}
- return $errh->($err) for $err;
+ return $die->($err) for $err;
}
return $wantarray ? @ret : $ret[0];
@@ -603,42 +589,6 @@ Simple, huh? Better still, go for the transaction management in
L<C<txn()>|/"txn"> and the savepoint management in L<C<svp()>|/"svp">. You
won't be sorry, I promise.
-=head3 Exception Handling
-
-B<NOTE: This feature is deprecated as of DBIx::Connector 0.46 and will be
-removed by September, 2011. Please update your modules to use L<Try::Tiny>,
-instead.>
-
-Another optional feature of the execution methods L<C<run()>|/"run">,
-L<C<txn()>|/"txn">, and L<C<svp()>|/"svp"> is integrated exception handling.
-This is especially valuable if the DBI C<RaiseError> attribute is true, or if
-the C<HandleError> attribute always throws exceptions (as the
-L<Exception::Class::DBI> handler does, for example). If an exception is thrown
-by a block passed to one of these methods, by default it will simply be
-propagated back to you (after any necessary transaction or savepoint
-rollbacks). You can of course use the standard Perl exception handling to deal
-with this situation:
-
- eval {
- $conn->run(sub { die 'WTF!' });
- };
- if (my $err = $@) {
- warn "Caught exception: $_";
- }
-
-Best of all is to simply pass a C<catch> code block to the execution method:
-
- $conn->run(sub {
- die 'WTF!';
- }, catch => sub {
- warn "Caught exception: $_";
- });
-
-Either way, when an exception handler is passed, C<$@> is properly localized,
-so that if it happens to have a value before you call the execution method,
-that value will be preserved afterward. This is, therefore, the recommended
-way to handle execution exceptions in DBIx::Connector.
-
=head3 Rollback Exceptions
In the event of a rollback in L<C<txn()>|/"txn"> or L<C<svp()>|/"svp">, if the
View
@@ -1,81 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-use warnings;
-use Test::More tests => 14;
-#use Test::More 'no_plan';
-use Test::MockModule;
-
-my $CLASS;
-BEGIN {
- $CLASS = 'DBIx::Connector';
- use_ok $CLASS or die;
-}
-
-ok my $conn = $CLASS->new( 'dbi:ExampleP:dummy', '', '' ), 'Construct connector';
-
-sub run_inner {
- shift->run(sub {
- die 'WTF!';
- }, catch => sub {
- die 'run_inner said: '. $_;
- });
-}
-
-sub run_outer {
- shift->run(sub {
- run_inner( $conn );
- }, catch => sub {
- die 'run_outer said: '. $_;
- });
-}
-
-sub txn_inner {
- shift->txn(sub {
- die 'WTF!';
- }, catch => sub {
- die 'txn_inner said: '. $_;
- });
-}
-
-sub txn_outer {
- shift->txn(sub {
- txn_inner( $conn );
- }, catch => sub {
- die 'txn_outer said: '. $_;
- });
-}
-
-my $driver = Test::MockModule->new("$CLASS\::Driver");
-
-# Mock the savepoint driver methods.
-$driver->mock( $_ => sub { shift } ) for qw(savepoint release rollback_to);
-
-sub svp_inner {
- shift->svp(sub {
- die 'WTF!';
- }, catch => sub {
- die 'svp_inner said: '. $_;
- });
-}
-
-sub svp_outer {
- shift->svp(sub {
- svp_inner( $conn );
- }, catch => sub {
- die 'svp_outer said: '. $_;
- });
-}
-
-foreach my $mode (qw/ping no_ping fixup/) {
- ok $conn->mode( $mode ), qq{Set mode to "$mode"};
- local $@;
- eval { run_outer($conn); };
- like $@, qr{run_outer said: run_inner said: WTF!}, "$mode run should handle nesting";
- eval { txn_outer($conn); };
- like $@, qr{txn_outer said: txn_inner said: WTF!}, "$mode txn should handle nesting";
- eval { svp_outer($conn); };
- like $@, qr{svp_outer said: svp_inner said: Savepoint aborted: WTF!},
- "$mode svp should handle nesting";
-}
-
View
23 t/run.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 69;
+use Test::More tests => 59;
#use Test::More 'no_plan';
use Test::MockModule;
@@ -116,27 +116,6 @@ $conn->run(sub {
});
});
-$@ = 'foo';
-ok $conn->run(sub {
- die 'WTF!';
-}, sub {
- like $_, qr/WTF!/, 'Should catch exception';
- like shift, qr/WTF!/, 'catch arg should also be the exception';
-}), 'Catch and handle an exception';
-is $@, 'foo', '$@ should not be changed';
-
-ok $conn->run(sub {
- die 'WTF!';
-}, catch => sub {
- like $_, qr/WTF!/, 'Should catch another exception';
- like shift, qr/WTF!/, 'catch arg should also be the new exception';
-}), 'Catch and handle another exception';
-is $@, 'foo', '$@ still should not be changed';
-
-eval { $conn->run(sub { die 'WTF!' }, catch => sub { die 'OW!' }) };
-ok my $e = $@, 'Should catch exception thrown by catch';
-like $e, qr/OW!/, 'And it should be the expected exception';
-
# Test mode.
$conn->run(sub {
is $conn->mode, 'no_ping', 'Default mode should be no_ping';
View
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 64;
+use Test::More tests => 49;
#use Test::More 'no_plan';
use Test::MockModule;
@@ -128,48 +128,3 @@ $conn->run( fixup => sub {
ok $conn->{_in_run}, '_in_run should be set inside nested run( fixup => )';
});
});
-
-# Check exception handling.
-$@ = 'foo';
-ok $conn->run(fixup => sub {
- die 'WTF!';
-}, sub {
- like $_, qr/WTF!/, 'Should catch exception';
- like shift, qr/WTF!/, 'catch arg should also be the exception';
-}), 'Catch and handle an exception';
-is $@, 'foo', '$@ should not be changed';
-
-ok $conn->run(fixup => sub {
- die 'WTF!';
-}, catch => sub {
- like $_, qr/WTF!/, 'Should catch another exception';
- like shift, qr/WTF!/, 'catch arg should also be the new exception';
-}), 'Catch and handle another exception';
-is $@, 'foo', '$@ still should not be changed';
-
-eval { $conn->run(fixup => sub { die 'WTF!' }, catch => sub { die 'OW!' }) };
-ok my $e = $@, 'Should catch exception thrown by catch';
-like $e, qr/OW!/, 'And it should be the expected exception';
-
-# Throw an error from a second execution due to a disconnect.
-$die = 1;
-$calls = undef;
-$@ = undef;
-eval {
- $conn->run( fixup => sub {
- my $dbha = shift;
- ok $conn->{_in_run}, '_in_run should be true';
- $calls++;
- if ($die) {
- $die = 0;
- $dbha->{Active} = 0;
- die 'WTF?';
- } else {
- die 'WTF';
- }
- }, catch => sub { die 'OW!' });
-};
-
-is $calls, 2, 'Sub should have been called twice';
-ok $e = $@, 'Should catch exception thrown by catch';
-like $e, qr/OW!/, 'And it should be the expected exception';
Oops, something went wrong.

0 comments on commit c185fa0

Please sign in to comment.