Storm::Transaction - Execute a code block in a database transaction
use Storm::Transaction; $txn = Storm::Transaction->new( $storm, sub { ... do work on $storm ... }); eval { $source->commit }; print "transaction successfull" if ! $@;
Storm::Transaction executes a block of code within a datbase transaction. This requires that the database supports transactions. If the database does not support transactions, the code block will simply be invoked.
Storm::Transaction
The Storm object to perform transactions on.
The code to be invoked within the transaction. If the code block finishes without any errors, then the database changes are commited. If errors are encountered, then the changes are rolled back.
Begins a new transaction and then invokes the code block to perform the work. Database changes are committed if the code block executes without any errors. If errors are thrown, then the changes work are rolled back.
It is useful to call commit within an eval { } block to trap any errors that are thrown. Alternatively, use a module like TryCatch or Try::Tiny and call commit within a try { } block.
eval { }
try { }
Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>
Copyright (c) 2010 Jeffrey Ray Hallock. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Storm, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Storm
CPAN shell
perl -MCPAN -e shell install Storm
For more information on module installation, please visit the detailed CPAN module installation guide.