1 package # Hide from pause for now - till we get it working
2 DBIx::Class::Storage::TxnScopeGuard;
8 my ($class, $storage) = @_;
11 bless [ 0, $storage ], ref $class || $class;
17 $self->[1]->txn_commit;
22 my ($dismiss, $storage) = @{$_[0]};
27 Carp::cluck("A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or an error - bad")
31 eval { $storage->txn_rollback };
32 my $rollback_exception = $@;
33 if($rollback_exception) {
34 my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
36 $storage->throw_exception(
37 "Transaction aborted: ${exception}. "
38 . "Rollback failed: ${rollback_exception}"
39 ) unless $rollback_exception =~ /$exception_class/;
50 DBIx::Class::Storage::TxnScopeGuard - Experimental
55 my ($self, $schema) = @_;
57 my $guard = $schema->txn_scope_guard;
59 # Multiple database operations here
66 An object that behaves much like L<Scope::Guard>, but hardcoded to do the
67 right thing with transactions in DBIx::Class.
73 Creating an instance of this class will start a new transaction. Expects a
74 L<DBIx::Class::Storage> object as its only argument.
78 Commit the transaction, and stop guarding the scope. If this method is not
79 called (i.e. an exception is thrown) and this object goes out of scope then
80 the transaction is rolled back.
86 L<DBIx::Class::Schema/txn_scope_guard>.
92 Insipred by L<Scope::Guard> by chocolateboy.
94 This module is free software. It may be used, redistributed and/or modified
95 under the same terms as Perl itself.