blib/lib/Dist/Zilla/App/Command/podchecker.pm

filter: Statementstmt 98.5% 67 / 68 Branchbran 85.0% 17 / 20 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 91.6% 11 / 12 Podpod 100% 5 / 5 totaltotal 93.8% 106 / 113 CC 19 SCAR 15.9
CC
19
Cov
95%
check_file
7.0
files_to_check
7.0
execute
6.0
CRAP 4.9
↑ Summary
1 ## no critic (NamingConventions::Capitalization) dzil runs the command of the lowercase name
2 package Dist::Zilla::App::Command::podchecker 0.001;
3 ## use critic
4  
5 # ABSTRACT: Check the POD of a distribution as its build weaves it
6  
7 2 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Dist::Zilla::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 0 ▶sub abstract { return 'check the POD of the distribution as the build weaves it' }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
15  
16 5 ▶sub usage_desc { return '%c podchecker %o [ <file> ... ]' }
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
17  
18  
19 5 ▶sub execute {
Subroutine execute: called CC=6 SCAR=17.9
Pod documented
20 5 my ( $self, $opt, $args ) = @_;
21  
22 # What the plugins log would mix with the report. A plugin that fails
23 # still dies with its message.
24 5 my $chrome = $self->app->chrome;
25 5 $chrome->logger->mute;
26 5 my $zilla = $self->zilla;
27  
28 # The phases of a build up to the content of the files, in the order of
29 # podpreview, which is the order of Dist::Zilla::Dist::Builder::build_in.
30 5 my %phases = ( before_build => -BeforeBuild, gather_files => -FileGatherer, prune_files => -FilePruner, munge_files => -FileMunger );
31 5 for my $phase (qw{before_build gather_files prune_files munge_files}) {
32 20 for my $plugin ( @{ $zilla->plugins_with( $phases{$phase} ) } ) {
33 25 $plugin->$phase;
34 }
35 }
36  
37 5 my @files = $self->files_to_check($args);
38 4 my $bad = 0;
39 4 for my $file (@files) {
40 5 ▶ $bad++ if !$self->check_file($file);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->check_file($file) 2 3 5
41 }
42 4 ▶ die "$bad of " . scalar(@files) . " file(s) have POD errors\n" if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 2 2 4
43 2 return;
44 }
45  
46  
47 5 ▶sub files_to_check {
Subroutine files_to_check: called CC=7 SCAR=19.5
Pod documented
48 5 my ( $self, $names ) = @_;
49 5 my $zilla = $self->zilla;
50 5 ▶ if ( !@$names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$names) 1 4 5
51 1 my ( %seen, @found );
52 1 for my $finder (qw{:InstallModules :PerlExecFiles}) {
53 2 for my $file ( @{ $zilla->find_files($finder) } ) {
54 2 ▶ push @found, $file if !$seen{ $file->name }++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$file->name}++ 2 0 2
55 }
56 }
57 1 return @found;
58 }
59 4 my %by_name;
60 4 for my $file ( @{ $zilla->files } ) {
61 20 $by_name{ $file->name } = $file;
62 }
63 4 my @missing = grep { !exists $by_name{$_} } @$names;
64 4 ▶ die 'Not a file of the distribution: ' . join( q{, }, @missing ) . "\n" if @missing;
Branch: 1 branch
BranchTrueFalseTotal
if @missing 1 3 4
65 3 return @by_name{@$names};
66 }
67  
68  
69 5 ▶sub check_file {
Subroutine check_file: called CC=7 SCAR=19.5
Pod documented
70 5 my ( $self, $file ) = @_;
71 5 my $checker = Dist::Zilla::App::Command::podchecker::Checker->new( -warnings => 1 );
72 5 $checker->output_fh( \*STDOUT );
73 5 $checker->source_filename( $file->name );
74 5 $checker->parse_string_document( $file->encoded_content );
75 5 my $counted = $checker->num_errors;
76 5 ▶ my $errors = $counted < 0 ? $checker->errors : $counted;
Branch: 1 branch
BranchTrueFalseTotal
$counted < 0 ? : 1 4 5
77 5 ▶ if ( $errors <= 0 && $counted < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errors <= 0 and $counted < 0) 1 4 5
Condition100%3/3
$errors <= 0 and $counted < 0
!ll&&!rl&&r
221
MC/DC100%2/2
$errors <= 0 and $counted < 0
$errors <= 0 $counted < 0
Truth table100%3/3
A and B
A= $errors <= 0B= $counted < 0
ABresult
0X0
100
111
78 1 ▶ print {*STDOUT} $file->name . " does not contain any pod commands.\n" or die "Cannot print: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
print {*STDOUT;} $file->name . " does not contain any pod commands.\n" or die "Cannot print: $!\n" 1 0 1
79 1 return 1;
80 }
81 4 ▶ print {*STDOUT} $file->name . ( $errors ? " has $errors pod syntax error(s).\n" : " pod syntax OK.\n" ) or die "Cannot print: $!\n";
Branch: 2 branches
BranchTrueFalseTotal
print {*STDOUT;} $file->name . ($errors ? " has $errors pod syntax error(s).\n" : " pod syntax OK.\n") or die "Cannot print: $!\n" 4 0 4
$errors ? : 2 2 4
82 4 return !$errors;
83 }
84  
85 # Pod::Checker sets num_errors to -1 at the end of a document in which it saw
86 # no POD command that it knows, and so drops the errors that it counted.
87 # Here, because App::Cmd would load a module of its own under Command as a
88 # command.
89 package Dist::Zilla::App::Command::podchecker::Checker 0.001; ## no critic (NamingConventions::Capitalization) under the command of the lowercase name
90  
91 2 ▶use parent 'Pod::Checker';
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 6 ▶sub end_Document { ## no critic (NamingConventions::Capitalization) the name of the hook of Pod::Simple::Methody
Subroutine end_Document: called CC=1 SCAR=0.0
94 6 my ( $self, @args ) = @_;
95 6 $self->{ __PACKAGE__ . '/errors' } = $self->num_errors;
96 6 return $self->SUPER::end_Document(@args);
97 }
98  
99 2 ▶sub errors {
Subroutine errors: called CC=2 SCAR=7.2
100 2 my ($self) = @_;
101 2 ▶ return $self->{ __PACKAGE__ . '/errors' } // -1;
Condition50%1/2
$self->{"Dist::Zilla::App::Command::podchecker::Checker/errors"} // -1
l!l
20
MC/DC0%0/1
$self->{"Dist::Zilla::App::Command::podchecker::Checker/errors"} // -1
$self->{"Dist::Zilla::App::Command::podchecker::Checker/errors"}
Truth table50%1/2
A
A= $self->{"Dist::Zilla::App::Command::podchecker::Checker/errors"}
Aresult
11
00
102 }
103  
104 package Dist::Zilla::App::Command::podchecker; ## no critic (NamingConventions::Capitalization) the POD below belongs to the command
105  
106  
107 2 1;
108  
109 __END__
↑ Summary