App-SimpleScan-Plugin-Retry

 view release on metacpan or  search on metacpan

lib/App/SimpleScan/Plugin/Retry.pm  view on Meta::CPAN

package App::SimpleScan::Plugin::Retry;

our $VERSION = '1.02';

use warnings;
use strict;
use Carp;
use Scalar::Util qw(looks_like_number);

my ($retry);

sub import {
  no strict 'refs';
  *{caller() . '::retry'}     = \&retry;
}

sub retry {
  my($self, $value) = @_;
  $retry = $value if defined $value;
  $retry;
}

sub options {
  return ('retry=s'    => \$retry,
         );
}

sub validate_options {
  my($class, $app) = @_;
  if (defined (my $count = $app->retry)) {
      $app->pragma('retry')->($app, $count);
  }
}

sub pragmas {
  return (['retry'    => \&retry_pragma],
         );
}

sub retry_pragma {
  my ($self, $args) = @_;
  if (looks_like_number($args)) {
    $args = int $args;   
    $self->stack_code(qq(mech->retry("$args");\n));
  }
  else {
    $self->stack_test(qq(fail "retry count '$args' is not a number";\n));
  }
}

1; # Magic true value required at end of module
__END__

=head1 NAME

App::SimpleScan::Plugin::Retry - implement retry pragma/command line option

=head1 VERSION

This document describes App::SimpleScan::Plugin::Retry version 1.00

=head1 SYNOPSIS

    simple_scan --retry 6

    or in a simple_scan input file:
    %%retry 6

Both of these would retry fetches up to 6 times, pausing an increasingly-long
time between each try.  If all attempts fail, the failure reported with the last fetch
is reflected back to the test program; if at any point the fetch
succeeds, further retry attempts are abandoned.

=head1 DESCRIPTION

C<App::SimpleScan::Plugin::Retry> allows C<simple_scan> to use the
C<retry> function implemented by the C<WWW::Mechanize::Pluggable>
retry plugin.

This allows you to retry a transaction multiple times; it checks
C<$mech->success> to see if the transaction was successful. 

If you need more sophisticated retry testing, you're better off scripting
this yourself using C<WWW::Mechanize::Pluggable> and 
C<WWW::Mechanize::Plugin::Retry>. One way is to use the C<%%retry> pragma in input to 
C<simple_scan --gen> to generate skeleton code, and then replace
the call to C<retry> to C<retry_if> with the appropriate 
status check subroutine (see C<WWW::Mechanize::Pluggable::Retry>
for more details).

=head1 INTERFACE 

=head2 options

Options supported by this plugin: C<--retry>, with one argument, the retry count.

=head2 pragmas

Pragmas supported by this plugin: C<%%retry>, same arguments as --retry.

=head2 retry



( run in 2.309 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )