line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## |
2
|
|
|
|
|
|
|
## Timer Class for Chronic Scheduler |
3
|
|
|
|
|
|
|
## Author: Vipul Ved Prakash . |
4
|
|
|
|
|
|
|
## $Id: Timer.pm,v 1.2 2004/08/15 21:02:36 hackworth Exp $ |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Schedule::Chronic::Timer; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
|
|
|
|
|
|
|
10
|
0
|
|
|
0
|
0
|
|
my ($class, $direction) = @_; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $self = bless { |
13
|
|
|
|
|
|
|
value => 0, |
14
|
|
|
|
|
|
|
starttime => time(), |
15
|
|
|
|
|
|
|
direction => $direction, |
16
|
|
|
|
|
|
|
running => 0, |
17
|
|
|
|
|
|
|
}, $class; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
return $self; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub set { |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
0
|
|
$_[0]->{value} = $_[1]; |
27
|
0
|
|
|
|
|
|
$_[0]->{starttime} = time(); |
28
|
0
|
|
|
|
|
|
$_[0]->start(); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub start { |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
0
|
|
$_[0]->{running} = 1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub stop { |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
0
|
|
$_[0]->{running} = 0; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub running { |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
0
|
|
$_[0]->{running}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get { |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
58
|
0
|
|
|
|
|
|
my $ticks = 0; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ($self->{running}) { |
61
|
0
|
0
|
|
|
|
|
if ($self->{direction} eq 'up') { |
62
|
0
|
|
|
|
|
|
$ticks = $self->{value} - (time() - $self->{starttime}); |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
|
$ticks = ($self->{value} + $self->{starttime}) - time(); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
return $self->{value}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $ticks; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|