line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spellunker::CLI::Perl; |
2
|
1
|
|
|
1
|
|
930
|
use 5.008005; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
17
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1464
|
use Getopt::Long; |
|
1
|
|
|
|
|
13797
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
6726
|
use Spellunker::Perl; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
1071
|
use Term::ANSIColor qw(colored); |
|
1
|
|
|
|
|
13497
|
|
|
1
|
|
|
|
|
737
|
|
9
|
|
|
|
|
|
|
require Win32::Console::ANSI if $^O eq 'MSWin32'; |
10
|
1
|
|
|
1
|
|
47
|
use PPI; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use version; our $VERSION = version->declare("v0.3.2"); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
16
|
0
|
0
|
|
|
|
|
bless { |
17
|
|
|
|
|
|
|
color => -t STDOUT ? 1 : 0, |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
0
|
|
sub color { $_[0]->{color} } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub run { |
24
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
if ($show_version) { |
34
|
0
|
|
|
|
|
|
print "spellunker-pod: $VERSION\n"; |
35
|
0
|
|
|
|
|
|
exit 0; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if (@ARGV) { |
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
|
0
|
|
|
|
|
push @err, $spellunker->check_sub_name() if $subname; |
45
|
0
|
|
|
|
|
|
$self->_show_error($filename, @err); |
46
|
0
|
0
|
|
|
|
|
$fail++ if @err; |
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
|
0
|
|
|
|
|
push @err, $spellunker->check_sub_name() if $subname; |
55
|
0
|
|
|
|
|
|
$self->_show_error('-', @err); |
56
|
0
|
0
|
|
|
|
|
exit @err ? 1 : 0; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _show_error { |
61
|
0
|
|
|
0
|
|
|
my ($self, $filename, @err) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
for (@err) { |
64
|
0
|
|
|
|
|
|
my ($lineno, $line, $errs) = @$_; |
65
|
0
|
|
|
|
|
|
my $result; |
66
|
0
|
0
|
|
|
|
|
if ($self->color) { |
67
|
0
|
|
|
|
|
|
$result = $line; |
68
|
0
|
|
|
|
|
|
$result =~ s!\Q$_!colored(['red'], $_)!e for @$errs; |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
|
$result = join ' ', @$errs; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
print "$filename: $lineno: $result\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |