DB::Transaction - feather-weight transaction management for your DBI handles
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';
DB::Transaction provides one function: run_in_transaction
By default, none. On request, run_in_transaction.
run_in_transaction
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
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.
on_error => 'rollback'
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.
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
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?
(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.
To install DB::Transaction, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DB::Transaction
CPAN shell
perl -MCPAN -e shell install DB::Transaction
For more information on module installation, please visit the detailed CPAN module installation guide.