Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 xt
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Build.PL
Octocat-spinner-32 Changes
Octocat-spinner-32 LICENSE
Octocat-spinner-32 META.json
Octocat-spinner-32 README.md
Octocat-spinner-32 cpanfile
README.md

NAME

Sub::Retry - retry $n times

SYNOPSIS

use Sub::Retry;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new();
my $res = retry 3, 1, sub {
    my $n = shift;
    $ua->post('http://example.com/api/foo/bar');
};

DESCRIPTION

Sub::Retry provides the function named 'retry'.

FUNCTIONS

  • retry($n_times, $delay, \&code [, \&retry_if])

    This function calls \&code. If the code throws exception, this function retry $n_times after $delay seconds.

    Return value of this function is the return value of \&code. This function cares wantarray.

    You can also customize the retry condition. In that case \&retry_if specify CodeRef. The CodeRef arguments is return value the same. (Default: retry condition is throws exception)

    use Sub::Retry;
    use Cache::Memcached::Fast;
    
    my $cache = Cache::Memcached::Fast->new(...);
    my $res = retry 3, 1, sub {
        $cache->get('foo');
    }, sub {
        my $res = shift;
        defined $res ? 0 : 1;
    };
    

AUTHOR

Tokuhiro Matsuno

LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Something went wrong with that request. Please try again.