=encoding utf-8 =head1 NAME =begin original Sub::Retry - retry $n times =end original Sub::Retry - $n回繰り返す =head1 SYNOPSIS use Sub::Retry; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $res = retry 3, 1, sub { $ua->post('http://example.com/api/foo/bar'); }; =head1 DESCRIPTION =begin original Sub::Retry provides the function named 'retry'. =end original Sub::Retryは 'retry'関数を提供します. =head1 FUNCTIONS =begin original =over 4 =item retry($n_times, $delay, \&code [, \&retry_if]) This function calls C<< \&code >>. If the code throws exception, this function retry C<< $n_times >> after C<< $delay >> seconds. Return value of this function is the return value of C<< \&code >>. This function cares L. You can also customize the retry condition. In that case C<< \&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; }; =back =end original =over 4 =item retry($n_times, $delay, \&code [, \&retry_if]) C<< \&code >>を呼び出します. もし例外が投げられた場合, C<< $delay >>秒後ごとに C<< $n_times >>回リトライします. この関数の戻り値は C<< \&code >>の戻り値となります. Lは考慮されます. リトライの条件をカスタマイズすることが可能で, C<< \&retry_if >>コードリファレンスを使います. コードリファレンスの引数は, 戻り値と同じです. (デフォルトでは例外が投げられたときにリトライします). 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; }; =back =head1 AUTHOR Tokuhiro Matsuno Etokuhirom AAJKLFJEF GMAIL COME =head1 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. =cut