my $storage = $weakself->storage;
my $cur_depth = $storage->transaction_depth;
- if (defined $txn_init_depth and $run_err eq '') {
+ if (defined $txn_init_depth and not $run_err) {
my $delta_txn = (1 + $txn_init_depth) - $cur_depth;
if ($delta_txn) {
}
# something above threw an error (could be the begin, the code or the commit)
- if ($run_err ne '') {
+ if ($run_err) {
# attempt a rollback if we did begin in the first place
if ($txn_begin_ok) {
'Exception-arrayref contents preserved',
);
+# Exception class which stringifies to empty string
+{
+ package DBICTest::ExceptionEmptyString;
+ use overload bool => sub { 1 }, '""' => sub { "" }, fallback => 1;
+ sub new { bless {}, shift; }
+}
+
+dies_ok (sub {
+ $schema->txn_do (sub { die DBICTest::ExceptionEmptyString->new });
+}, 'Exception-empty string object thrown');
+
+isa_ok $@, 'DBICTest::ExceptionEmptyString', "Exception-empty string";
+
done_testing;
isa_ok( $@, 'DBIx::Class::Exception' );
# Now lets rethrow via exception_action
-$schema->exception_action(sub { die @_ });
-throws_ok \&$throw, $ex_regex;
+{
+ my $handler_execution_counter = 0;
+
+ $schema->exception_action(sub {
+ $handler_execution_counter++;
+ like $_[0], $ex_regex, "Exception is precisely passed to exception_action";
+ die @_
+ });
+
+ throws_ok \&$throw, $ex_regex;
+ is $handler_execution_counter, 1, "exception_action handler executed exactly once";
+}
#
# This should have never worked!!!
throws_ok { $schema->storage->throw_exception('floob') }
qr/DBICTest::Exception is handling this: floob/;
+# Exception class which stringifies to empty string
+{
+ package DBICTest::ExceptionEmptyString;
+ use overload bool => sub { 1 }, '""' => sub { "" }, fallback => 1;
+ sub new { bless {}, shift; }
+}
+
+# Try the exception-empty string class
+$schema->exception_action(sub { die DBICTest::ExceptionEmptyString->new });
+dies_ok \&$throw;
+
+my $throw_x_empty_string = sub { $schema->txn_do (sub { die DBICTest::ExceptionEmptyString->new }); };
+$schema->exception_action(sub { die @_ });
+dies_ok \&$throw_x_empty_string, 'exception_action handles exception object-empty string';
+isa_ok $@, 'DBICTest::ExceptionEmptyString', "exception rethrown by exception_action";
+
done_testing;