Tie::Scalar::Ratio - a scalar which multiplies in value every time it is accessed.
version 0.01
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
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).
Tie::Scalar::Ratio
retry()
Similarly by passing a ratio value less than 1, it can be used as a timeout or countdown feature.
Tie::Scalar::Decay
David Farrell <dfarrell@cpan.org>
This software is Copyright (c) 2016 by David Farrell.
This is free software, licensed under:
The (two-clause) FreeBSD License
To install Tie::Scalar::Ratio, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Scalar::Ratio
CPAN shell
perl -MCPAN -e shell install Tie::Scalar::Ratio
For more information on module installation, please visit the detailed CPAN module installation guide.