App::Gitc::Reversible - Simple reversible computation for gitc
version 0.60
use App::Gitc::Reversible; reversibly { # do something with a side effect open my $fh, '>', '/tmp/file' or die; # specify how that side effect can be undone # (assuming '/tmp/file' did not exist before) to_undo { close $fh; unlink '/tmp/file' }; operation_that_might_die($fh); operation_that_might_get_SIGINTed($fh); });
Perform computations and automatically reverse their side effects if the computations fail. One often wants to perform a series of operations, some of which have side effects, and properly "undo" all side effects if something goes wrong with one of the operations. By invoking your code "reversibly", the undos are handled for you.
Call this sub from inside the coderef argument of "reversibly" to produce a warning if the coderef fails. Only one message is active at a time. In other words, subsequent calls to "failure_warning" change the warning that would be produced.
Call this sub from inside the coderef argument of "reversibly" to provide a coderef which should be executed on failure. It can accept a bare code block like:
to_undo { print "undo something\n" };
See "reversibly" for further information.
Executes a code reference ($code) allowing operations with side effects to be automatically reversed if $code fails or is interrupted. For example:
$code
reversibly { print "hello\n"; to_undo { print "goodbye\n" }; die "uh oh\n" if $something_bad; };
just prints "hello" if $something_bad is false. If it's true, then both "hello" and "goodbye" are printed and the exception "uh oh" is rethrown.
$something_bad
Upon failure, any code refs provided by calling "to_undo" are executed in reverse order. Conceptually, we're unwinding the stack of side effects that $code performed up to the point of failure.
If $code is interrupted with SIGINT, the side effects are undone and an exception "SIGINT\n" is thrown.
Nested calls to reversibly are handled correctly.
reversibly
Data::Transaactional, Object::Transaction.
Grant Street Group <developers@grantstreet.com>
This software is Copyright (c) 2013 by Grant Street Group.
This is free software, licensed under:
The GNU Affero General Public License, Version 3, November 2007
To install App::Gitc::Test, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Gitc::Test
CPAN shell
perl -MCPAN -e shell install App::Gitc::Test
For more information on module installation, please visit the detailed CPAN module installation guide.