Tue Oct 14 00:25:25 BST 2008
Die::Retry - a perl module to easily retry on exceptions
I've just written
Die::Retry
- a
perl module which makes is easy to write a concise exception retry loop.
The module is only useful if any exception can be silently caught and the code in question re-run, but in that case it makes it very easy to write the loop in question:
1 use Die::Retry qw( retry ); 2 my $retval = retry( sub { some_func_with_exceptions($param1, $param2) } 3 , times => 3 4 , delay => 0 5 );
In that example the code ref:
1 sub { some_func_with_exceptions($param1, $param2) }</pre>
is called up to three times if exceptions are thrown. There is no
delay between retries. Finally - if a successful call is made to the code
ref $retval
will get the (scalar context) return value of the
code ref call.
I'm submitting this to CPAN and have already set it up on GitHub and Ohloh.
Comment by: Bradley Dean at Mon, 20 Oct 2008 22:56:49 (BST)
I've just found
Attempt
which does exactly what I coded for Die::Retry
- in fact both the
code and the syntax are practically identical. So dies Die::Retry
.