1 package DBIx::Class::Storage::TxnScopeGuard;
7 my ($class, $storage) = @_;
10 bless [ 0, $storage ], ref $class || $class;
16 $self->[1]->txn_commit;
21 my ($dismiss, $storage) = @{$_[0]};
30 eval { $storage->txn_rollback };
31 my $rollback_exception = $@;
32 if($rollback_exception) {
33 my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
35 $storage->throw_exception(
36 "Transaction aborted: ${exception}. "
37 . "Rollback failed: ${rollback_exception}"
38 ) unless $rollback_exception =~ /$exception_class/;
48 DBIx::Class::Storage::TxnScopeGuard
53 my ($self, $schema) = @_;
55 my $guard = $schema->txn_scope_guard;
57 # Multiple database operations here
64 An object that behaves much like L<Scope::Guard>, but hardcoded to do the
65 right thing with transactions in DBIx::Class.
71 Creating an instance of this class will start a new transaction. Expects a
72 L<DBIx::Class::Storage> object as its only argument.
76 Commit the transaction, and stop guarding the scope. If this method is not
77 called (i.e. an exception is thrown) and this object goes out of scope then
78 the transaction is rolled back.
84 L<DBIx::Class::Schema/txn_scope_guard>.
90 Insipred by L<Scope::Guard> by chocolateboy.
92 This module is free software. It may be used, redistributed and/or modified
93 under the same terms as Perl itself.