blib/script/gank

filter: Statementstmt 47.1% 42 / 89 Branchbran 3.3% 1 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.7% 15 / 16 Podpod n/a totaltotal 41.4% 58 / 140 CC 18 SCAR 48.9
CC
18
Cov
35%
process_files
272.0
set_options
2.5
__ANON__
2.1
CRAP 132.6
↑ Summary lib/Encode/Guess/Educated.pm »
1 #!/usr/local/bin/perl
2  
3 24 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use warnings FATAL => "utf8";
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use open qw(:std :utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 24 ▶use Getopt::Long qw[ GetOptions ];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use Pod::Usage qw[ pod2usage ];
Subroutine BEGIN: called CC=1 SCAR=0.0
12 24 ▶use Carp qw[ confess ];
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 24 ▶use Encode::Guess::Educated;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ########################################################################
17  
18 24 our $Errors = 0;
19 24 our $VERSION = "1.0 (2012-12-28)";
20 24 our %Opt = ();
21  
22 ########################################################################
23  
24 24 main();
25 0 ▶exit($Errors == 0 ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$main::Errors == 0 ? : 0 0 0
26  
27 ########################################################################
28  
29 24 ▶sub main {
Subroutine main: called CC=1 SCAR=0.4
30 24 set_traps();
31 24 set_options();
32 0 process_files();
33 }
34  
35 24 ▶sub set_traps {
Subroutine set_traps: called CC=1 SCAR=0.0
36 24 $| = 1;
37 24 ▶ $SIG{__WARN__} = sub { confess "FATALIZED WARNING @_" };
Subroutine __ANON__: called CC=1 SCAR=0.0
38 24 ▶ $SIG{__DIE__} = sub { $^S || confess "UNCAUGHT FATAL @_" };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$^S or confess("UNCAUGHT FATAL @_") 0 24 24
39 }
40  
41 24 ▶sub set_options {
Subroutine set_options: called CC=2 SCAR=9.2
42  
43 24 Getopt::Long::Configure qw[ bundling auto_version ];
44  
45 24 ▶ GetOptions(\%Opt, qw[
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%main::Opt, ("help|h|?", "man|m", "debug|d", "dump-byte-table|B", "dump-training-data|D", "training-datafile|t", "model|m", "list-models|L", "short|s", "long|l")) or pod2usage(2) 0 0 0
46  
47 help|h|?
48 man|m
49  
50 debug|d
51 dump-byte-table|B
52 dump-training-data|D
53  
54 training-datafile|t
55 model|m
56 list-models|L
57  
58 short|s
59 long|l
60  
61 ]) || pod2usage(2);
62  
63  
64 }
65  
66 ########################################################################
67  
68 0 ▶sub process_files {
Subroutine process_files: not called CC=16 SCAR=56.1
69  
70 0 my $obj = Encode::Guess::Educated->new();
71  
72 0 ▶ if ($Opt{"dump-bytes-table"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"dump-bytes-table"}) 0 0 0
73 0 $obj->dump_byte_table();
74 }
75  
76 0 ▶ if ($Opt{"dump-training-data"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"dump-training-data"}) 0 0 0
77 0 $obj->dump_training_data();
78 }
79  
80 0 ▶ if ($Opt{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Opt{"debug"}) 0 0 0
81 0 $obj->enable_debugging(1);
82 }
83  
84 0 for my $file (@ARGV) {
85  
86 0 ▶ unless (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
87 0 print STDERR "$0: can't stat $file: $!\n";
88 0 $Errors++;
89 0 next;
90 }
91  
92 0 ▶ unless (-f _) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f _) 0 0 0
93 0 print STDERR "$0: $file isn't a regular file\n";
94 0 $Errors++;
95 0 next;
96 }
97  
98 0 ▶ unless (-s _) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-s _) 0 0 0
99 0 print STDERR "$0: $file is empty\n";
100 0 $Errors++;
101 0 next;
102 }
103  
104 0 my $found;
105  
106 0 eval { $found = $obj->guess_file_encoding($file) };
107  
108 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
109 0 my $msg = $@;
110 # $msg =~ s/\s+at \S+ line \d.*$//s;
111 0 $Errors++;
112 0 print STDERR "$0: $msg\n";
113 0 next;
114 }
115  
116 0 ▶ if (! $found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 0 0
117 0 print STDERR "$0: Can't guess encoding of $file: ", $obj->get_errmsg();
118 0 $Errors++;
119 0 next;
120 }
121  
122 0 my $enc = $obj->get_guessed_encoding();
123  
124 0 ▶ print "$file: " if @ARGV > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV > 1 0 0 0
125 0 say $enc;
126  
127 0 ▶ next unless $Opt{long} || $Opt{short};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::Opt{"long"} or $main::Opt{"short"} 0 0 0
Condition0%0/3
$main::Opt{"long"} or $main::Opt{"short"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$main::Opt{"long"} or $main::Opt{"short"}
$main::Opt{"long"} $main::Opt{"short"}
Truth table0%0/3
A or B
A= $main::Opt{"long"}B= $main::Opt{"short"}
ABresult
1X1
011
000
128  
129 0 my $reason;
130 0 ▶ if ($Opt{short}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($main::Opt{'short'}) { } 0 0 0
elsif ($main::Opt{'long'}) { } 0 0 0
131 0 $reason = $obj->get_short_report();
132 }
133 elsif ($Opt{long}) {
134 0 $reason = $obj->get_long_report();
135 }
136 else {
137 0 die "not reached";
138 }
139  
140 0 for ($reason) {
141 0 s/^/\t/gm;
142 0 s/\R*\z/\n/;
143 }
144 0 say $reason;
145 }
146  
147 }
↑ Summary lib/Encode/Guess/Educated.pm »