« blib/lib/Dist/Zilla/Plugin/DBIO/SetMeta.pm
↑ Summary
blib/lib/Dist/Zilla/Plugin/DBIO/VersionLockstepTest.pm »
| 1 | package Dist::Zilla::Plugin::DBIO::PodCheckerTest; | ||
| 2 | # ABSTRACT: Generate xt/author/pod-checker.t, a Pod::Checker gate on the built POD | ||
| 3 | 8 | our $VERSION = '0.900007'; | |
| 4 | 8 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 8 | ▶ | use Dist::Zilla::File::InMemory; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 8 | with 'Dist::Zilla::Role::FileGatherer'; | |
| 7 | |||
| 8 | |||
| 9 | 4 | ▶ | sub gather_files { |
|
Subroutine
gather_files: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 10 | 4 | my ($self) = @_; | |
| 11 | 4 | $self->add_file(Dist::Zilla::File::InMemory->new( | |
| 12 | name => 'xt/author/pod-checker.t', | ||
| 13 | content => $self->_template, | ||
| 14 | )); | ||
| 15 | 4 | $self->log_debug('gathered xt/author/pod-checker.t'); | |
| 16 | } | ||
| 17 | |||
| 18 | 4 | ▶ | sub _template { |
|
Subroutine
_template: called CC=1 SCAR=0.0
| |||
| 19 | 4 | return <<'PERL'; | |
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use File::Find (); | ||
| 23 | use Pod::Checker (); | ||
| 24 | use Test::More; | ||
| 25 | |||
| 26 | # Pod::Checker over the built distribution: modules under lib/, scripts under | ||
| 27 | # bin/. This is the woven POD -- what gets installed -- so it catches what no | ||
| 28 | # source file shows, above all an L</name> whose heading the woven document | ||
| 29 | # does not have ("unresolved internal link"). | ||
| 30 | # | ||
| 31 | # Paths are relative to the distribution root, which is where `make test` and | ||
| 32 | # `prove` run from. | ||
| 33 | my @files; | ||
| 34 | for my $dir (grep { -d } qw(lib bin)) { | ||
| 35 | File::Find::find({ | ||
| 36 | no_chdir => 1, | ||
| 37 | wanted => sub { | ||
| 38 | push @files, $_ if -f && ($dir eq 'bin' || /\.(?:pm|pod)\z/); | ||
| 39 | }, | ||
| 40 | }, $dir); | ||
| 41 | } | ||
| 42 | |||
| 43 | # Started from the wrong directory this would otherwise pass on nothing. | ||
| 44 | ok scalar(@files), 'found files to check under lib/ and bin/' | ||
| 45 | or diag 'nothing found -- run this test from the distribution root'; | ||
| 46 | |||
| 47 | for my $file (sort @files) { | ||
| 48 | my $report = ''; | ||
| 49 | open my $out, '>:encoding(UTF-8)', \$report | ||
| 50 | or die "cannot open in-memory handle: $!"; | ||
| 51 | |||
| 52 | # Errors only: warnings are not reported, so a green run stays quiet. | ||
| 53 | my $checker = Pod::Checker->new(-warnings => 0); | ||
| 54 | $checker->parse_from_file($file, $out); | ||
| 55 | close $out; | ||
| 56 | |||
| 57 | # num_errors is -1 for a file without any POD -- nothing to check, no fault. | ||
| 58 | ok $checker->num_errors <= 0, "POD of $file" | ||
| 59 | or diag $report; | ||
| 60 | } | ||
| 61 | |||
| 62 | done_testing; | ||
| 63 | PERL | ||
| 64 | } | ||
| 65 | |||
| 66 | 8 | __PACKAGE__->meta->make_immutable; | |
| 67 | 8 | ▶ | no Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 68 | 8 | 1; | |
| 69 | |||
| 70 | __END__ | ||