| 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"
MC/DC0%0/1
$main::opt_resfile ||= "process.res"
$main::opt_resfile
Truth table50%1/2
A
A= $main::opt_resfile
| |||||||||||||
| 18 | 10 | ▶ | die "Missing attribute: 'file=s'" unless $opt_file; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 30 | 10 | my $num = <$fh>; | |||||||||||
| 31 | 10 | ▶ | Reject("Failed to read from $opt_file: $!") unless defined $num; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 10 | ▶ | if ($num =~ /(\d+)/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 10 | $num = $1; | |||||||||||
| 34 | } else { | ||||||||||||
| 35 | 0 | ▶ | Reject("Cannot parse contents of $opt_file: " . | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | (defined($num) ? "undef" : $num)); | ||||||||||||
| 37 | } | ||||||||||||
| 38 | 10 | ▶ | close($fh) or Reject("Failed to close $opt_file: $!"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | |||||||||||||
| 40 | 10 | ▶ | open($fh, ">>$opt_resfile") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | or Reject("Failed to open $opt_resfile for output: $!"); | ||||||||||||
| 42 | 10 | ▶ | flock($fh, Fcntl::LOCK_EX()) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | or Reject("Failed to lock $opt_resfile: $!"); | ||||||||||||
| 44 | 10 | ▶ | seek($fh, 0, 2) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | or Reject("Failed to seek in $opt_resfile: $!"); | ||||||||||||
| 46 | 10 | ▶ | (print $fh "OK ($num)\n") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | or Reject("Failed to write to $opt_resfile: $!"); | ||||||||||||
| 48 | 10 | ▶ | close($fh) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | or Reject("Failed to close $opt_resfile: $!"); | ||||||||||||
| 50 | 10 | print "Status: OK\n"; | |||||||||||