Retry(3)
π Retry β the manual page, bestie edition π
okay so this is Retry, a User Contributed Perl Documentation page, and honestly? it's giving one-feature module energy and I respect it so much. π
β¨ NAME β¨
Retry β that's it, that's the name, she said it herself π
πΈ SYNOPSIS πΈ
A one-feature module, no notes, no bloat. This provides a method to wrap any function in automatic retry logic, with exponential back-off delays, and a callback for each time an attempt fails. Obsessed fr fr.
Example:
use Retry;
use Try::Tiny;
use LWP::UserAgent;
my $code_to_retry = sub {
my $r = LWP::UserAgent->new->get("http://example.com");
die $r->status_line unless $r->is_success;
return $r;
};
my $agent = Retry->new(
# This callback is optional:
failure_callback => sub { warn "Transient error: " . $_[0]; },
);
try {
$agent->retry($code_to_retry)
}
catch {
warn "All attempts failed: $_";
};
π¦ ATTRIBUTES π¦
retry_delay
This is the initial delay used when the routine failed, before retrying again. Lowkey the calm-before-the-storm moment. π
Every subsequent failure doubles the amount. it's giving exponential, it's giving drama, it's giving math.
It defaults to 8 seconds.
max_retry_attempts
The maximum number of retries we should attempt before giving up completely. Like, bestie, we tried, we really did. π
It defaults to 5.
failure_callback
Optional. To be notified of every failure (even if we eventually succeed on a later retry β yes, even the messy ones π), install a subroutine callback here.
For example:
Retry->new(
failure_callback => sub { warn "failed $count++ times" }
);
π METHODS π
retry
Its purpose is to execute the passed subroutine, over and over, until it succeeds, or the number of retries is exceeded. The delay between retries increases exponentially. (Failure is indicated by the sub dying.) π
If the subroutine succeeds, then its scalar return value will be returned by retry. periodt.
For example, you could replace this:
my $val = unreliable_web_request();
With this:
my $val = Retry->new->retry(
sub { unreliable_web_request() }
);
glow up honestly β¨
π AUTHOR π
Toby Corkindale -- <https://github.com/TJC/>
π LICENSE π
This module is released under the Perl Artistic License 2.0: <http://www.perlfoundation.org/artistic_license_2_0>
It is based upon source code which is Copyright 2010 Strategic Data Pty Ltd, however it is used and released with permission.
π SEE ALSO π
Attempt
Retry differs from Attempt in having exponentially increasing delays, and by having a callback inbetween attempts.
However Attempt has a simpler syntax. (different vibe, still valid π«Ά)
k that's the whole page, no cap, every single detail kept, every flag and default and license line intact π
okay and one last thing β this whole page is perl v5.42.0, dated 2025-07-25, so likeβ¦ shoutout to the perl 5.42.0 era besties, we're all here, we're all retrying, we're all slaying π
πΈβ¨
π¦ where this page comes from
- fedora 43: perl-Retry 1.03-25.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms