Watchdog.pm

filter: Statementstmt 37.5% 15 / 40 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 3 totaltotal 26.7% 19 / 71 CC 8 SCAR 21.6
CC
8
Cov
27%
new
20.0
alarm
12.0
_unlink_file
6.0
CRAP 8.7
↑ Summary sample.pl »
1 package Proc::Watchdog;
2  
3 1 require 5.005_62;
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $VERSION = '1.01';
9  
10 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
11 0 my $type = shift;
12 0 ▶ my $class = ref($type) || $type || "Proc::Watchdog";
Condition0%0/5
ref $type || $type || 'Proc::Watchdog'
l!l
00
ref $type or $type
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $type || $type || 'Proc::Watchdog'
ref $type $type
Truth table0%0/3
A or B
A= ref $typeB= $type
ABresult
1X1
011
000
13  
14 0 my $flags = shift;
15  
16 0 ▶ bless { path => ($flags->{-path} || '/tmp') ,
Condition0%0/2
$flags->{'-path'} || '/tmp'
l!l
00
MC/DC0%0/1
$flags->{'-path'} || '/tmp'
$flags->{'-path'}
Truth table0%0/2
A
A= $flags->{'-path'}
Aresult
11
00
17 file => undef
18 }, $class;
19 }
20  
21 0 ▶sub _unlink_file ($) {
Subroutine _unlink_file: not called CC=2 SCAR=17.9
22 0 my $self = shift;
23  
24 0 ▶ if ($self->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"file"}) 0 0 0
25 0 unlink $self->{file};
26 0 delete $self->{file};
27 }
28 }
29  
30 0 ▶sub _create_file ($$) {
Subroutine _create_file: not called CC=2 SCAR=17.9
31 0 my $self = shift;
32 0 my $time = shift;
33  
34 0 $self->{file} = $self->{path} . '/watchdog.' . $$;
35
36 my $fh = new IO::File ">" . $self->{file}
37 0 ▶ or croak "Cannot create watchdog file ", $self->{file}, ": $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new('>' . $self->{"file"}) or croak("Cannot create watchdog file ", $self->{"file"}, ": $!\n") 0 0 0
38
39 0 $fh->print($time, "\n");
40 0 $fh->close;
41 }
42  
43 0 ▶sub alarm ($$) {
Subroutine alarm: not called CC=3 SCAR=24.8
Pod undocumented
44 0 my $self = shift;
45 0 my $time = shift;
46  
47 0 $self->_unlink_file;
48  
49 0 ▶ if ($time < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($time < 0) { } 0 0 0
elsif ($time == 0) { } 0 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 0 ▶sub reset () {
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my $self = shift;
62  
63 0 $self->_unlink_file;
64 }
65  
66 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
67 0 my $self = shift;
68 0 $self->_unlink_file;
69 }
70  
71 1 1;
72  
73 __END__
↑ Summary sample.pl »