1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
=== lib/DBIx/Class/Row.pm
==================================================================
--- lib/DBIx/Class/Row.pm (revision 14032)
+++ lib/DBIx/Class/Row.pm (local)
@@ -159,12 +159,10 @@
%{$self->{_inflated_column} || {}});
if(!$self->{_rel_in_storage}) {
- $source->storage->txn_begin;
# The guard will save us if we blow out of this scope via die
+ $rollback_guard = $source->storage->txn_scope_guard;
- $rollback_guard = Scope::Guard->new(sub { $source->storage->txn_rollback });
-
## Should all be in relationship_data, but we need to get rid of the
## 'filter' reltype..
## These are the FK rels, need their IDs for the insert.
@@ -246,8 +244,7 @@
}
}
}
- $source->storage->txn_commit;
- $rollback_guard->dismiss;
+ $rollback_guard->commit;
}
$self->in_storage(1);
=== lib/DBIx/Class/Storage/TxnScopeGuard.pm
==================================================================
--- lib/DBIx/Class/Storage/TxnScopeGuard.pm (revision 14032)
+++ lib/DBIx/Class/Storage/TxnScopeGuard.pm (local)
@@ -0,0 +1,26 @@
+package DBIx::Class::Storage::TxnScopeGuard;
+
+use strict;
+use warnings;
+
+sub new {
+ my ($class, $storage) = @_;
+
+ $storage->txn_begin;
+ bless [ 0, $storage ], ref $class || $class;
+}
+
+sub commit {
+ my $self = shift;
+
+ $self->[1]->txn_commit;
+ $self->[0] = 1;
+}
+
+sub DESTROY {
+ my ($dismiss, $storage) = @$_[0];
+
+ $storage->txn_rollback unless $dismiss;
+}
+
+1;
=== lib/DBIx/Class/Storage.pm
==================================================================
--- lib/DBIx/Class/Storage.pm (revision 14032)
+++ lib/DBIx/Class/Storage.pm (local)
@@ -261,6 +261,12 @@
sub txn_rollback { die "Virtual method!" }
+sub txn_scope_guard {
+ my ($self) = @_;
+
+ return DBIx::Class::Storage::TxnScopeGuard->new($self);
+}
+
=head2 sql_maker
Returns a C<sql_maker> object - normally an object of class
|