Author image Shutterstock, Inc.

NAME

DB::Transaction - feather-weight transaction management for your DBI handles

SYNOPSIS

    use DB::Transaction qw(run_in_transaction);

    my $dbh = My::Application->get_dbh;

    run_in_transaction {
        $dbh->do('
            update risky_business -- in some fashion
        ');
    } db_handle => $dbh, on_error => 'rollback';

DESCRIPTION

DB::Transaction provides one function: run_in_transaction

EXPORTS

By default, none. On request, run_in_transaction.

run_in_transaction BLOCK db_handle => $db_handle, on_error => ['rollback' | 'continue']

Begin a transaction on $db_handle, then run BLOCK. Any errors raised in the course of executing BLOCK will cause the current transaction to be handled according to your on_error specification.

on_error may be one of these two options:

  • rollback -- call this dbh's ->rollback method

  • continue -- just keep on chugging, man!

on_error => 'rollback' is the default behavior.

Transactions may be nested, though your underlying database may not support nested transactions. It's up to you to know whether this is supported or not.

CONTRIBUTING

To contribute back to this project, log in to your GitHub account and visit http://github.com/shutterstock/perl-db-transaction, then fork the repository.

Create a feature branch, make your changes, push them back to your fork, and submit a pull request via GitHub.

    # fork the project in github

    git clone git://github.com/<your-name>/perl-db-transaction.git
    git checkout -b feature-add-spiffy-functionality

    emacs -nw t/spiffy-functionality.t   # hack hack hack
    emacs -nw lib/DB/Transaction.pm      # hack hack hack

    git push feature-add-spiffy-functionality origin

    # submit pull request via github

AUTHORS

Written by Aaron Cohen <morninded@cpan.org> and Belden Lyman <belden@cpan.org> at Shutterstock, Inc. Released to CPAN by Shutterstock, Inc.

If you like the idea of working at a company that supports open-source development, why not checkout our jobs page and drop us a line?

COPYRIGHT AND LICENSE

    (c) 2013 Shutterstock, Inc. All rights reserved.

This library is free software: you may redistribute it and/or modify it under the same terms as Perl itself; either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.