blib/lib/File/Canonicalizer.pm

filter: Statementstmt 30.1% 19 / 63 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 22.7% 25 / 110 CC 21 SCAR 59.2
CC
21
Cov
19%
file_canonicalizer
462.0
BEGIN
1.0
BEGIN
1.0
CRAP 373.3
↑ Summary
1 package File::Canonicalizer;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 require Exporter;
9 2 our @ISA = qw(Exporter);
10 2 our @EXPORT = qw(file_canonicalizer);
11  
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 our $VERSION = '0.11';
14  
15 0 ▶sub file_canonicalizer {
Subroutine file_canonicalizer: not called CC=21 SCAR=61.4
Pod documented
16 0 my ( $inp_file # 1
17 , $out_file # 2
18 , $remove_comments_started_with_RE # 3
19 , $replace_adjacent_tabs_and_spaces_with_1_space # 4
20 , $replace_adjacent_slashes_with_single_slash # 5
21 , $remove_white_char_from_line_edges # 6
22 , $remove_empty_lines # 7
23 , $convert_to_lowercased # 8
24 , $remove_leading_zeroes # 9
25 , $sort_lines #10
26 , $aref_replacements #11
27 ) = @_ ;
28  
29 0 my %lines ;
30 my $INP;
31 0 my $OUT;
32 0 my $i ;
33 0 my $replaced_pattern;
34 0 my $replacement;
35  
36 0 ▶ unless ($inp_file) { $inp_file = '&STDIN'; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($inp_file) 0 0 0
37 0 ▶ open ($INP, "<$inp_file") || croak "Error: Can't open file \"$inp_file\" for read: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $INP, "<$inp_file" or croak(qq[Error: Can't open file "$inp_file" for read: $!]) 0 0 0
38 0 ▶ unless ($out_file) { $out_file = '&STDOUT'; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($out_file) 0 0 0
39 0 ▶ open ($OUT, ">$out_file") || croak "Error: Can't open file \"$out_file\" for write: $!" ;
Branch: 1 branch
BranchTrueFalseTotal
open $OUT, ">$out_file" or croak(qq[Error: Can't open file "$out_file" for write: $!]) 0 0 0
40  
41 0 ▶ while (<$INP>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $INP)) 0 0 0
42 {
43 0 chomp;
44 0 ▶ if ($remove_comments_started_with_RE) { s/$remove_comments_started_with_RE.+$//; }
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_comments_started_with_RE) 0 0 0
45 0 ▶ if ($replace_adjacent_tabs_and_spaces_with_1_space) { s/[ \t]+/ /g; }
Branch: 1 branch
BranchTrueFalseTotal
if ($replace_adjacent_tabs_and_spaces_with_1_space) 0 0 0
46 0 ▶ if ($replace_adjacent_slashes_with_single_slash) { s#/+#/#g; }
Branch: 1 branch
BranchTrueFalseTotal
if ($replace_adjacent_slashes_with_single_slash) 0 0 0
47 0 ▶ if ($remove_empty_lines) { (/^\s*$/) && next; }
Branch: 2 branches
BranchTrueFalseTotal
if ($remove_empty_lines) 0 0 0
/^\s*$/ and next 0 0 0
48 0 ▶ if ($remove_white_char_from_line_edges) { s/(^[ \t]*|[ \t]*$)//g; }
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_white_char_from_line_edges) 0 0 0
49 0 ▶ if ($convert_to_lowercased) { $_ = lc; }
Branch: 1 branch
BranchTrueFalseTotal
if ($convert_to_lowercased) 0 0 0
50 0 ▶ if ($remove_leading_zeroes) { s/(\W)0+(\d)/$1$2/g; }
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_leading_zeroes) 0 0 0
51  
52 0 ▶ if (defined $aref_replacements)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $aref_replacements) 0 0 0
53 {
54 0 $i = 0;
55 0 REPLACEMENTS: while (1)
56 {
57 0 ($replaced_pattern, $replacement) = (@{$aref_replacements})[$i++,$i++];
58 0 ▶ (defined $replacement) || last REPLACEMENTS;
Branch: 1 branch
BranchTrueFalseTotal
defined $replacement or last REPLACEMENTS 0 0 0
59 0 s/$replaced_pattern/$replacement/g;
60 }
61 }
62  
63 0 ▶ if ($sort_lines) { $lines{$_} = undef; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sort_lines) 0 0 0
64 0 ▶ print $OUT "$_\n" || croak "Error: Can't write to $out_file: $!";
Condition0%0/2
"$_\n" || croak("Error: Can't write to ${out_file}: $!")
l!l
00
MC/DC0%0/1
"$_\n" || croak("Error: Can't write to ${out_file}: $!")
"$_\n"
Truth table0%0/2
A
A= "$_\n"
Aresult
11
00
65 }
66  
67 0 ▶ if ($sort_lines)
Branch: 1 branch
BranchTrueFalseTotal
if ($sort_lines) 0 0 0
68 {
69 0 for (sort keys %lines)
70 0 ▶ { print $OUT "$_\n" || croak "Error: Can't write to $out_file: $!"; }
Condition0%0/2
"$_\n" || croak("Error: Can't write to ${out_file}: $!")
l!l
00
MC/DC0%0/1
"$_\n" || croak("Error: Can't write to ${out_file}: $!")
"$_\n"
Truth table0%0/2
A
A= "$_\n"
Aresult
11
00
71 }
72  
73 0 close $OUT;
74 0 close $INP;
75 } # end of 'sub file_canonicalizer'
76  
77 2 1;
78  
79 __END__
↑ Summary