NAME

DBIO::Storage::TxnScopeGuard - Scope-based transaction handling

VERSION

version 0.900000

SYNOPSIS

sub foo {
  my ($self, $schema) = @_;

  my $guard = $schema->txn_scope_guard;

  # Multiple database operations here

  $guard->commit;
}

DESCRIPTION

An object that behaves much like Scope::Guard, but hardcoded to do the right thing with transactions in DBIO.

METHODS

new

Creating an instance of this class will start a new transaction (by implicitly calling "txn_begin" in DBIO::Storage. Expects a DBIO::Storage object as its only argument.

commit

Commit the transaction, and stop guarding the scope. If this method is not called and this object goes out of scope (e.g. an exception is thrown) then the transaction is rolled back, via "txn_rollback" in DBIO::Storage

rollback

Roll back the transaction, and stop guarding the scope. You can use this to avoid the warning when the scope guard goes out of scope, for deliberate rollbacks.

new

Begins a transaction and returns a scope guard bound to the supplied storage.

commit

Commits the transaction and inactivates the guard.

rollback

Rolls back the transaction and inactivates the guard.

SEE ALSO

"txn_scope_guard" in DBIO::Schema.

Scope::Guard by chocolateboy (inspiration for this module)

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.