NAME
WWW::Mechanize::Plugin::Retry - programatically-controlled fetch retry
VERSION
Version 0.01
SYNOPSIS
use WWW::Mechanize::Pluggable;
my $foo = WWW::Mechanize::Plugin::Retry->new();
my $foo->retry_if(\&test_sub, 5, 10, 30, 60);
# Will run test_sub with the Mech object after the get.
# If the test_sub returns false, shift off one wait interval
# from the list, wait that long, and repeat. Give up if
# unsuccessful every time.
$foo->get("http://wobbly.site.net");
if ($mech->retry_failed) {
# used to detect that the retries all failed
...
}
DESCRIPTION
The Retry plugin allows you to establish a criterion by which you determine whether a page fetch or submit has worked successfully; if so, the plugin returns control to the caller. If not, the last operation is retried. This is repeated once for every item in the delay list until either we run out of delays or the transaction succeeds.
METHODS
init
Establish methods in Pluggable's namespace and set up hooks.
retry_if
Sets up the subroutine to call to see if this is a failure or not.
This subroutine should return true if the get or submit_form succeeded, and false if it did not.
retry
Sets up like retry_if
, but assigns a default test ( sub { $self->success } ). If the transaction was deemed successful by WWW::Mechanize
, then it's a success.
prehook
Record the method that we're going to retry if necessary. This must be done here because we don't want to be dependent on WWW::Mechanize
and WWW::Mechanize::Pluggable
not calling methods in WWW::Mechanize::Pluggable
, which would reset the method in last_method
. (Notably, Mech calls Mech::success internally.)
posthook
Handles the actual retry, waiting and recursively calling the originally-called method as needed.
AUTHOR
Joe McMahon, <mcmahon@yahoo-inc.com>
BUGS
Please report any bugs or feature requests to bug-www-mechanize-plugin-retry@rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Mechanize-Plugin-Retry. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2005 Joe McMahon, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.