The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tie::Scalar::Ratio - a scalar which multiplies in value every time it is accessed.

VERSION

version 0.01

SYNOPSIS

  use Tie::Scalar::Ratio;

  tie(my $doubler, 'Tie::Scalar::Ratio', 2, 1);

  print $doubler; # 1
  print $doubler; # 2
  print $doubler; # 4
  print $doubler; # 8

  tie(my $halver, 'Tie::Scalar::Ratio', 0.5, 80);

  print $halver; # 80
  print $halver; # 40
  print $halver; # 20
  print $halver; # 10

DESCRIPTION

Tie::Scalar::Ratio is a class for creating tied scalars which multiply their value by a ratio everytime their value is read. I found this a useful way to make a retry() function increase its sleep duration after every attempt, without re-writing the function (I just passed a Tie::Scalar::Ratio object as the duration scalar).

Similarly by passing a ratio value less than 1, it can be used as a timeout or countdown feature.

SEE ALSO

Tie::Scalar::Decay

AUTHOR

David Farrell <dfarrell@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2016 by David Farrell.

This is free software, licensed under:

  The (two-clause) FreeBSD License