bin/inicat

filter: Statementstmt 77.1% 44 / 57 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod n/a totaltotal 74.3% 61 / 82 CC 1 SCAR 2.5
CC
1
Cov
75%
VERSION_MESSAGE
2.0
HELP_MESSAGE
2.0
BEGIN
1.0
CRAP 1.3
« bin/inifilter ↑ Summary
1 #!perl
2 #
3 # inicat - cat .ini files to standard output
4 #
5  
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use App::IniDiff::IniFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 my $prog = $0;
13 3 $prog =~ s:.*\/::;
14  
15 3 my $Usage = "Usage: $prog [-V] [-o outfile] [file ...]
16 -V Print version number and exit.
17 -o outfile - print output to outfile
18 file Read from file (defaults to stdin)
19 Reads the contents of the specified .ini files (or standard input
20 if no files are given), and writes them to standard output.
21 ";
22  
23 # add support for --help and --version
24 3 $Getopt::Std::STANDARD_HELP_VERSION = "true";
25 3 my $VERSION = '0.19';
26 0 ▶sub VERSION_MESSAGE {
Subroutine VERSION_MESSAGE: not called CC=1 SCAR=6.9
27 0 print "$prog: version $VERSION\n";
28 }
29 0 ▶sub HELP_MESSAGE {
Subroutine HELP_MESSAGE: not called CC=1 SCAR=6.9
30 0 print STDERR $Usage;
31 }
32  
33 3 my %opt;
34 3 ▶if (!&getopts('o:V', \%opt)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&getopts("o:V", \%opt)) 0 3 3
35 0 print STDERR $Usage;
36 0 exit 1;
37 }
38 3 ▶my $outFile = defined $opt{'o'} ? $opt{'o'} : '-';
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'o'} ? : 2 1 3
39 3 ▶if (defined $opt{'V'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"V"}) 0 3 3
40 0 print "$prog: version $VERSION\n";
41 0 exit 0;
42 }
43  
44 3 ▶if (@ARGV == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV == 0) 0 3 3
45 0 print STDERR "$prog: no files to cat\n";
46 0 die $Usage;
47 }
48  
49 3 my $out;
50 3 ▶if ($outFile eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($outFile eq '-') { } 1 2 3
51 1 $out = new IO::Handle;
52 1 ▶ if (!$out->fdopen("STDOUT", "w")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($out->fdopen("STDOUT", "w")) 0 1 1
53 0 die "$prog: can't fdopen STDOUT - $!\n";
54 }
55 }
56 else {
57 2 $out = new IO::File $outFile, 'w';
58 2 ▶ if (!defined $out) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $out) 0 2 2
59 0 die "$prog: couldn't open $outFile for writing - $!\n";
60 }
61 }
62  
63 3 my $ok = 1;
64 3 my $file;
65 3 foreach $file (@ARGV) {
66 3 my $in = new IO::File $file, "r";
67 3 ▶ if (!defined $in) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in) 0 3 3
68 0 print STDERR "$prog: can't open $file - $!\n";
69 0 $ok = 0;
70 0 next;
71 }
72 3 my $ini = new App::IniDiff::IniFile($in);
73 3 $in->close;
74 3 ▶ if (!defined $ini) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ini) 1 2 3
75 1 print STDERR "$prog: $file:${App::IniDiff::IniFile::errorString}\n";
76 1 $ok = 0;
77 1 next;
78 }
79 2 $ini->write($out);
80 }
81  
82 3 exit $ok ? 0 : 1;
83  
84 __END__
« bin/inifilter ↑ Summary