t/process

filter: Statementstmt 86.1% 31 / 36 Branchbran 45.4% 10 / 22 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 5 / 6 Podpod n/a totaltotal 70.1% 47 / 67 CC 1 SCAR 1.5
CC
1
Cov
70%
Reject
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Net/Spooler/Test.pm ↑ Summary
1 # -*- perl -*-
2  
3 # Process a file; processing it means reading the contents (number)
4 # and writing
5 #
6 # OK ($num)
7 #
8 # into the file process.res.
9  
10 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Fcntl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 10 ▶use vars qw($opt_file $opt_errors $opt_resfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 Getopt::Long::GetOptions('file=s', 'errors');
17 10 ▶$opt_resfile ||= 'process.res';
Condition50%1/2
$main::opt_resfile ||= "process.res"
l!l
010
MC/DC0%0/1
$main::opt_resfile ||= "process.res"
$main::opt_resfile
Truth table50%1/2
A
A= $main::opt_resfile
Aresult
11
00
18 10 ▶die "Missing attribute: 'file=s'" unless $opt_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $main::opt_file 0 10 10
19  
20 0 ▶sub Reject {
Subroutine Reject: not called CC=1 SCAR=6.9
21 0 my $err = shift;
22 0 print STDERR "$err\n";
23 0 print "Status: REJECT\n$err\n";
24 0 exit 1;
25 }
26  
27  
28 10 my $fh = Symbol::gensym();
29 10 ▶open($fh, "<$opt_file") or Reject("Failed to open $opt_file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$main::opt_file" or Reject("Failed to open $main::opt_file: $!") 10 0 10
30 10 my $num = <$fh>;
31 10 ▶Reject("Failed to read from $opt_file: $!") unless defined $num;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 10 10
32 10 ▶if ($num =~ /(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ /(\d+)/) { } 10 0 10
33 10 $num = $1;
34 } else {
35 0 ▶ Reject("Cannot parse contents of $opt_file: " .
Branch: 1 branch
BranchTrueFalseTotal
defined $num ? : 0 0 0
36 (defined($num) ? "undef" : $num));
37 }
38 10 ▶close($fh) or Reject("Failed to close $opt_file: $!");
Branch: 1 branch
BranchTrueFalseTotal
close $fh or Reject("Failed to close $main::opt_file: $!") 10 0 10
39  
40 10 ▶open($fh, ">>$opt_resfile")
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">>$main::opt_resfile" or Reject("Failed to open $main::opt_resfile for output: $!") 10 0 10
41 or Reject("Failed to open $opt_resfile for output: $!");
42 10 ▶flock($fh, Fcntl::LOCK_EX())
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 2 or Reject("Failed to lock $main::opt_resfile: $!") 10 0 10
43 or Reject("Failed to lock $opt_resfile: $!");
44 10 ▶seek($fh, 0, 2)
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, 0, 2 or Reject("Failed to seek in $main::opt_resfile: $!") 10 0 10
45 or Reject("Failed to seek in $opt_resfile: $!");
46 10 ▶(print $fh "OK ($num)\n")
Branch: 1 branch
BranchTrueFalseTotal
print $fh "OK ($num)\n" or Reject("Failed to write to $main::opt_resfile: $!") 10 0 10
47 or Reject("Failed to write to $opt_resfile: $!");
48 10 ▶close($fh)
Branch: 1 branch
BranchTrueFalseTotal
close $fh or Reject("Failed to close $main::opt_resfile: $!") 10 0 10
49 or Reject("Failed to close $opt_resfile: $!");
50 10 print "Status: OK\n";
« blib/lib/Net/Spooler/Test.pm ↑ Summary