Retry(3)

πŸ“¦
version 1.03 Β· 2 versions
, in fedora 43

πŸ’– 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