WWW::Mechanize::Plugin::Retry - programatically-controlled fetch retry
Version 0.01
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 ... }
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.
Establish methods in Pluggable's namespace and set up hooks.
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.
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.
retry_if
WWW::Mechanize
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.)
WWW::Mechanize::Pluggable
last_method
Handles the actual retry, waiting and recursively calling the originally-called method as needed.
Joe McMahon, <mcmahon@yahoo-inc.com>
<mcmahon@yahoo-inc.com>
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.
bug-www-mechanize-plugin-retry@rt.cpan.org
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.
To install WWW::Mechanize::Plugin::Retry, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Mechanize::Plugin::Retry
CPAN shell
perl -MCPAN -e shell install WWW::Mechanize::Plugin::Retry
For more information on module installation, please visit the detailed CPAN module installation guide.