CLI/Perl.pm

filter: Statementstmt 41.9% 26 / 62 Branchbran 6.2% 1 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 3 totaltotal 37.6% 35 / 93 CC 11 SCAR 31.1
CC
11
Cov
35%
run
56.0
_show_error
20.0
new
6.0
CRAP 22.5
↑ Summary Perl.pm »
1 package Spellunker::CLI::Perl;
2 1 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Spellunker::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Term::ANSIColor qw(colored);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶require Win32::Console::ANSI if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 1 1
10 1 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use version; our $VERSION = version->declare("v0.3.2");
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my $class = shift;
16 0 ▶ bless {
Branch: 1 branch
BranchTrueFalseTotal
-t STDOUT ? : 0 0 0
17 color => -t STDOUT ? 1 : 0,
18 }, $class;
19 }
20  
21 0 ▶sub color { $_[0]->{color} }
Subroutine color: not called CC=1 SCAR=6.9
Pod undocumented
22  
23 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod undocumented
24 0 my $self = shift;
25  
26 0 my $p = Getopt::Long::Parser->new(
27 config => [qw(posix_default no_ignore_case auto_help)]
28 );
29 0 $p->getoptions(
30 'subname' => \my $subname,
31 'v|version' => \my $show_version
32 );
33 0 ▶ if ($show_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_version) 0 0 0
34 0 print "spellunker-pod: $VERSION\n";
35 0 exit 0;
36 }
37  
38 0 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) { } 0 0 0
39 0 my $fail = 0;
40 0 for my $filename (@ARGV) {
41 0 my $spellunker = Spellunker::Perl->new_from_file($filename);
42 0 my @err;
43 0 push @err, $spellunker->check_comment();
44 0 ▶ push @err, $spellunker->check_sub_name() if $subname;
Branch: 1 branch
BranchTrueFalseTotal
if $subname 0 0 0
45 0 $self->_show_error($filename, @err);
46 0 ▶ $fail++ if @err;
Branch: 1 branch
BranchTrueFalseTotal
if @err 0 0 0
47 }
48 0 exit $fail;
49 } else {
50 0 my $content = join('', <>);
51 0 my $spellunker = Spellunker::Perl->new_from_string($content);
52 0 my @err;
53 0 push @err, $spellunker->check_comment();
54 0 ▶ push @err, $spellunker->check_sub_name() if $subname;
Branch: 1 branch
BranchTrueFalseTotal
if $subname 0 0 0
55 0 $self->_show_error('-', @err);
56 0 exit @err ? 1 : 0;
57 }
58 }
59  
60 0 ▶sub _show_error {
Subroutine _show_error: not called CC=4 SCAR=30.0
61 0 my ($self, $filename, @err) = @_;
62  
63 0 for (@err) {
64 0 my ($lineno, $line, $errs) = @$_;
65 0 my $result;
66 0 ▶ if ($self->color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->color) { } 0 0 0
67 0 $result = $line;
68 0 $result =~ s!\Q$_!colored(['red'], $_)!e for @$errs;
69 } else {
70 0 $result = join ' ', @$errs;
71 }
72 0 print "$filename: $lineno: $result\n";
73 }
74 }
75  
76 1 1;
↑ Summary Perl.pm »