NAME

Storm::Transaction - Execute a code block in a database transaction

SYNOPSIS

use Storm::Transaction;

$txn = Storm::Transaction->new( $storm, sub {

   ... do work on $storm ...

});

eval { $source->commit };

print "transaction successfull" if ! $@;
 

DESCRIPTION

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.

ATTRIBUTES

storm

The Storm object to perform transactions on.

code

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.

METHODS

commit

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.

AUTHOR

Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>

COPYRIGHT

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.