/
Timely.pm
66 lines (38 loc) · 1.16 KB
/
Timely.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package Tie::Timely;
use strict;
our $VERSION = '1.025';
sub TIESCALAR {
my( $class, $value, $lifetime ) = @_;
my $self = bless [ undef, $lifetime, time ], $class;
$self->STORE( $value );
return $self;
}
sub FETCH { time - $_[0]->[2] > $_[0]->[1] ? () : $_[0]->[0] }
sub STORE { @{ $_[0] }[0,2] = ( $_[1], time ) }
1;
__END__
=encoding utf8
=head1 NAME
Tie::Timely - Time out scalar values
=head1 SYNOPSIS
use Tie::Timely;
my $interval = 5;
tie my $scalar, 'Amelia', $interval;
# now $scalar is 'Amelia'
sleep 6;
# now the interval has elapsed and the value is forgotten
# set the value again and it starts a new interval
$scalar = 'Llama';
=head1 DESCRIPTION
This module creates a tied scalar that forgets its value after the
interval that you specify. The next time you set the value it resets
the interval;
=head1 SOURCE AVAILABILITY
This source is in Github:
https://github.com/briandfoy/tie-timely/
=head1 AUTHOR
brian d foy, C<< <brian.d.foy@gmail.com> >>
=head1 COPYRIGHT AND LICENSE
Copyright © 2005-2024, brian d foy <briandfoy@pobox.com>. All rights reserved.
You may redistribute this under the terms of the Artistic License 2.0.
=cut