On Tue, Apr 21, 2009 at 3:11 PM, Bill Ward <b...@wards.net> wrote: > Something like Object::Retry maybe? Then things can inherit from it?
The proposed module sounds more like a has-a than an is-a. Or maybe just a new method that would get included in the caller's namespace. Set the defaults at import time, then call it with a single coderef: use retry MIN_SLEEP => 3, MAX_SLEEP => 10, TIMEOUT => 120 my $asdf_server_connection; retry sub { $asdf_server_connection = connect ( (new socket), ...) or die } # whatever the retry::retry routine would be something like sub retry::retry($) { my $start_time = time; my $result; for(;;){ eval { $result = &$_[0]; 1 } and return $result; my $E = $@; $LOGGER and $LOGGER->( "$E invoked from @{[caller]}"); time - $start_time > $TIMEOUT and die "$E\n"; sleep ($MIN_SLEEP + rand ( $MAX_SLEEP - $MIN_SLEEP )) } } Everything in all-caps would be retry:: package variables, or scalars tied to a per-caller(1)[0] hash to mitigate AAAD surprises. Or incorporated into the particular Retry::Object, as you are wisely suggesting. I've written stuff like that often enough that it would be cool to be able to have a standard name and API for it, too. -- "Your appreciation is my glorious gratuity." -- Herman Melville on IP rights