Spellunker/CLI/Pod.pm untested

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