line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Proc::Watchdog; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
4
|
1
|
|
|
1
|
|
657
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
414
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
794
|
use IO::File; |
|
1
|
|
|
|
|
10814
|
|
|
1
|
|
|
|
|
808
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
0
|
|
my $type = shift; |
12
|
0
|
|
0
|
|
|
|
my $class = ref($type) || $type || "Proc::Watchdog"; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $flags = shift; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
0
|
|
|
|
bless { path => ($flags->{-path} || '/tmp') , |
17
|
|
|
|
|
|
|
file => undef |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _unlink_file ($) { |
22
|
0
|
|
|
0
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if ($self->{file}) { |
25
|
0
|
|
|
|
|
|
unlink $self->{file}; |
26
|
0
|
|
|
|
|
|
delete $self->{file}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _create_file ($$) { |
31
|
0
|
|
|
0
|
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my $time = shift; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self->{file} = $self->{path} . '/watchdog.' . $$; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
my $fh = new IO::File ">" . $self->{file} |
37
|
|
|
|
|
|
|
or croak "Cannot create watchdog file ", $self->{file}, ": $!\n"; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$fh->print($time, "\n"); |
40
|
0
|
|
|
|
|
|
$fh->close; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub alarm ($$) { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
my $time = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->_unlink_file; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($time < 0) { |
|
|
0
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
croak "->alarm() must be called with a positive timeout\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ($time == 0) { |
53
|
0
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
|
|
|
|
|
$self->_create_file($time); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub reset () { |
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->_unlink_file; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub DESTROY { |
67
|
0
|
|
|
0
|
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
$self->_unlink_file; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |