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.

    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.


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.)


Handles the actual retry, waiting and recursively calling the originally-called method as needed.


Joe McMahon, <>


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



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.