bin/rev

filter: Statementstmt 77.5% 38 / 49 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 78.8% 56 / 71 CC 2 SCAR 2.0
CC
2
Cov
76%
rev
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/script/seq ↑ Summary bin/uudecode »
1 #!/usr/bin/perl
2  
3 =begin metadata
4  
5 Name: rev
6 Description: reverse lines of a file
7 Author: Andy Murren, andy@murren.org
8 License: gpl
9  
10 =end metadata
11  
12 =cut
13  
14 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Getopt::Std qw(getopts);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use constant EX_SUCCESS => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use constant EX_FAILURE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 5 my $Program = basename($0);
23  
24 # unbuffer output to make it look speedier
25 5 $|++;
26  
27 5 our $VERSION = '1.5';
28  
29 5 ▶getopts('') or usage();
Branch: 1 branch
BranchTrueFalseTotal
&getopts("") or usage() 2 2 4
30 2 my $rc = EX_SUCCESS;
31 2 foreach my $file (@ARGV) {
32 1 ▶ if (-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 0 1 1
33 0 warn "$Program: '$file' is a directory\n";
34 0 $rc = EX_FAILURE;
35 0 next;
36 }
37 1 my $fh;
38 1 ▶ unless (open $fh, '<', $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, "<", $file) 0 1 1
39 0 warn "$Program: cannot open '$file': $!\n";
40 0 $rc = EX_FAILURE;
41 0 next;
42 }
43 1 rev($fh);
44 1 ▶ if ($!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!) 0 1 1
45 0 warn "$Program: '$file': $!\n";
46 0 $rc = EX_FAILURE;
47 }
48 1 ▶ unless (close $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (close $fh) 0 1 1
49 0 warn "$Program: cannot close '$file': $!\n";
50 0 $rc = EX_FAILURE;
51 0 next;
52 }
53 }
54 2 ▶rev(*STDIN) unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 1 1 2
55 2 exit $rc;
56  
57 2 ▶sub rev {
Subroutine rev: called CC=2 SCAR=6.9
58 2 my $fh = shift;
59 2 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 7 2 9
60 7 chomp;
61 7 my $r = reverse;
62 7 print $r, $/;
63 }
64 }
65  
66 2 ▶sub usage {
Subroutine usage: called CC=1 SCAR=0.0
67 2 print "usage: $Program [file ...]\n";
68 2 exit EX_FAILURE;
69 }
70  
71 1 ▶sub VERSION_MESSAGE {
Subroutine VERSION_MESSAGE: called CC=1 SCAR=0.0
72 1 print "$Program version $VERSION\n";
73 1 exit EX_SUCCESS;
74 }
75  
76 __END__
« blib/script/seq ↑ Summary bin/uudecode »