Radioactive::Decay - allow scalar values to decay over time


Radioactive-Decay documentation Contained in the Radioactive-Decay distribution.

Index


Code Index:

NAME

Top

Radioactive::Decay - allow scalar values to decay over time

SYNOPSIS

Top

  use Radioactive::Decay;

  my $halflife = 10;
  tie my $var, $Radioactive::Decay, $halflife;

  $var = 40;
  sleep 10;
  print $var;  # 20
  sleep 10;
  print $var;  # 10

DESCRIPTION

Top

This allows you to tie a scalar variable so that it will decay over time.

For example, if you set a half-life of 30 seconds, then a variable which is set to 100 now will be 25 in a minute's time.

We're sure there are all manner of useful applications for this, and hopefully someone will let us know what they are.

AUTHOR

Top

Tony Bowden and Marty Pauley

BUGS and QUERIES

Top

Please direct all correspondence regarding this module to: bug-Radioactive-Decay@rt.cpan.org

COPYRIGHT AND LICENSE

Top


Radioactive-Decay documentation Contained in the Radioactive-Decay distribution.

package Radioactive::Decay;

$VERSION = "1.00";
use strict;

sub TIESCALAR { bless [0,log(2)/$_[1], time], $_[0]; }
sub STORE     { $_[0]->[0] = $_[1] }
sub FETCH     { $_[0]->[0] * exp(-$_[0]->[1] * (time - $_[0]->[2])) }
sub DESTROY   {}

return q/
    make me laugh make me cry enrage me don't try to disengage me
/;