NAME

DBIx::TransactionManager - transaction handling for database.

SYNOPSIS

basic usage:

use DBI;
use DBIx::TransactionManager;
my $dbh = DBI->connect('dbi:SQLite:');
my $tm = DBIx::TransactionManager->new($dbh);

$tm->txn_begin;

    $dbh->do("insert into foo (id, var) values (1,'baz')");

$tm->txn_commit;

scope_gurad usage:

use DBI;
use DBIx::TransactionManager;
my $dbh = DBI->connect('dbi:SQLite:');
my $tm = DBIx::TransactionManager->new($dbh);

my $txn = $tm->txn_scope;

    $dbh->do("insert into foo (id, var) values (1,'baz')");

$txn->commit;

nested transaction usage:

use DBI;
use DBIx::TransactionManager;
my $dbh = DBI->connect('dbi:SQLite:');
my $tm = DBIx::TransactionManager->new($dbh);

{
    my $txn = $tm->txn_scope;
    $dbh->do("insert into foo (id, var) values (1,'baz')");
    {
        my $txn2 = $tm->txn_scope;
        $dbh->do("insert into foo (id, var) values (2,'bab')");
        $txn2->commit;
    }
    {
        my $txn3 = $tm->txn_scope;
        $dbh->do("insert into foo (id, var) values (3,'bee')");
        $txn3->commit;
    }
    $txn->commit;
}

DESCRIPTION

DBIx::TransactionManager is a simple transaction manager. like DBIx::Class::Storage::TxnScopeGuard.

METHODS

my $tm = DBIx::TransactionManager->new($dbh)

get DBIx::TransactionManager's instance object. $dbh parameter must be required.

my $txn = $tm->txn_scope(%args)

get DBIx::TransactionManager::ScopeGuard's instance object. You may pass an optional argument to %args, to tell the scope guard where the scope was generated, like so:

sub mymethod {
    my $self = shift;
    my $txn = $tm->txn_scope( caller => [ caller() ] );
}

$self->mymethod();

This will allow the guard object to report the caller's location from the perspective of mymethod(), not where txn_scope() was called.

see "DBIx::TransactionManager::ScopeGuard's METHODS"

$tm->txn_begin(%args)

Start the transaction.

txn_begin may optionally take a 'caller' argument. This will allow you to provide caller information which will be used in in_transaction. For example if you have a wrapper function that calls txn_begin, you may want to let the user think that the caller was one stack above your wrapper.

# use __my__ caller!
$tm->txn_begin( caller => [ caller(0) ] ); 

$tm->txn_rollback

Rollback the transaction.

$tm->txn_commit

Commit the transaction.

$tm->in_transaction

Returns true if $txn is currently in a middle of a transaction. While normally you only need to use this value as a boolean, it actually returns a hashref consisting of 'caller' and 'pid' element. This will tell you exactly where the currently valid transaction started.

DBIx::TransactionManager::ScopeGuard's METHODS

$txn->commit

Commit the transaction.

$txn->rollback

Rollback the transaction.

AUTHOR

Atsushi Kobayashi <nekokak _at_ gmail _dot_ com>

SEE ALSO

DBIx::Class::Storage::TxnScopeGuard

DBIx::Skinny::Transaction

LICENSE

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