File Coverage

blib/lib/Radioactive/Decay.pm
Criterion Covered Total %
statement 6 7 85.7
branch n/a
condition n/a
subroutine 4 5 80.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Radioactive::Decay;
2              
3             =head1 NAME
4              
5             Radioactive::Decay - allow scalar values to decay over time
6              
7             =head1 SYNOPSIS
8              
9             use Radioactive::Decay;
10              
11             my $halflife = 10;
12             tie my $var, $Radioactive::Decay, $halflife;
13              
14             $var = 40;
15             sleep 10;
16             print $var; # 20
17             sleep 10;
18             print $var; # 10
19              
20             =head1 DESCRIPTION
21              
22             This allows you to tie a scalar variable so that it will decay over
23             time.
24              
25             For example, if you set a half-life of 30 seconds, then a variable which
26             is set to 100 now will be 25 in a minute's time.
27              
28             We're sure there are all manner of useful applications for this, and
29             hopefully someone will let us know what they are.
30              
31             =head1 AUTHOR
32              
33             Tony Bowden and Marty Pauley
34              
35             =head1 BUGS and QUERIES
36              
37             Please direct all correspondence regarding this module to:
38             bug-Radioactive-Decay@rt.cpan.org
39              
40             =head1 COPYRIGHT AND LICENSE
41              
42             Copyright (C) 2000-2005 Tony Bowden, Marty Pauley
43              
44             This program is free software; you can redistribute it and/or modify
45             it under the terms of the GNU General Public License; either version
46             2 of the License, or (at your option) any later version.
47              
48             This program is distributed in the hope that it will be useful,
49             but WITHOUT ANY WARRANTY; without even the implied warranty of
50             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
51              
52             =cut
53              
54             $VERSION = "1.00";
55 1     1   895 use strict;
  1         2  
  1         164  
56              
57 1     1   795 sub TIESCALAR { bless [0,log(2)/$_[1], time], $_[0]; }
58 1     1   21 sub STORE { $_[0]->[0] = $_[1] }
59 3     3   3003058 sub FETCH { $_[0]->[0] * exp(-$_[0]->[1] * (time - $_[0]->[2])) }
60 0     0     sub DESTROY {}
61              
62             return q/
63             make me laugh make me cry enrage me don't try to disengage me
64             /;
65