---
name: "KiokuDB::Backend::Role::TXN"
section: "3pm"
platform: "linux"
package: "libkiokudb-perl"
version: "0.57-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/KiokuDB::Backend::Role::TXN"
---

# KiokuDB::Backend::Role::TXN(3pm)

Backend level transaction support.

## NAME

KiokuDB::Backend::Role::TXN - Backend level transaction support.

## VERSION

version 0.57

## SYNOPSIS

```
    package MyBackend;
    use Moose;
    with qw(
        KiokuDB::Backend
        KiokuDB::Backend::Role::TXN
    );
    sub txn_begin { ... }
    sub txn_commit { ... }
    sub txn_rollback { ... }
```

## DESCRIPTION

This API is inspired by standard database transactions much like you get with DBI.

This is the low level interface required by "txn\_do" in KiokuDB.

## OPTIONAL METHODS

- txn\_do $code, %callbacks

  This method should evaluate the code reference in the context of a transaction, inside an `"eval"`. If any errors are caught the transaction should be aborted, otherwise it should be committed.  This is much like "txn\_do" in DBIx::Class::Schema.

  The `"rollback"` callback should be fired when the transaction will be aborted.

## REQUIRED METHODS

- txn\_begin \[ $parent\_txn \]

  Begin a new transaction.

  This method can return a transaction handle that will later be passed to `"txn_commit"` or `"txn_rollback"` as necessary.

  The current handle will be passed to nested calls to `"txn_begin"`.

- txn\_commit $txn

  Commit the transaction.

- txn\_rollback $txn

  Rollback the transaction.

## AUTHOR

Yuval Kogman \<nothingmuch@woobling.org\>

## COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.

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