Scroll to navigation

Sub::Retry(3pm) User Contributed Perl Documentation Sub::Retry(3pm)


Sub::Retry - retry $n times


    use Sub::Retry;
    use LWP::UserAgent;
    my $ua = LWP::UserAgent->new();
    my $res = retry 3, 1, sub {
        my $n = shift;


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


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 {
    }, sub {
        my $res = shift;
        defined $res ? 0 : 1;


Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>


Copyright (C) Tokuhiro Matsuno

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

2018-09-04 perl v5.38.2