| 1 | package Dist::Zilla::Plugin::PodInherit; | ||||||||||
| 2 | # ABSTRACT: autogenerate inherited POD sections for Dist::Zilla distributions | ||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Pod::Inherit; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Module::Load; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Dist::Zilla::File::InMemory; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | our $VERSION = '0.009'; | |||||||||
| 13 | 2 | our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY | |||||||||
| 14 | |||||||||||
| 15 | =head1 NAME | ||||||||||
| 16 | |||||||||||
| 17 | Dist::Zilla::Plugin::PodInherit - use L<Pod::Inherit> to provide C<INHERITED METHODS> sections in POD | ||||||||||
| 18 | |||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||
| 20 | |||||||||||
| 21 | Just add [PodInherit] to dist.ini. Currently there's no config options at all. | ||||||||||
| 22 | |||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||
| 24 | |||||||||||
| 25 | Simple wrapper around L<Pod::Inherit> to provide an 'inherited methods' section for | ||||||||||
| 26 | any modules in this distribution. See the documentation for L<Pod::Inherit> for more | ||||||||||
| 27 | details. | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | 2 | with 'Dist::Zilla::Role::FileGatherer'; | |||||||||
| 32 | 2 | with 'Dist::Zilla::Role::FileInjector'; | |||||||||
| 33 | 2 | with 'Dist::Zilla::Role::FileFinderUser' => { | |||||||||
| 34 | default_finders => [ qw( :InstallModules ) ], | ||||||||||
| 35 | }; | ||||||||||
| 36 | |||||||||||
| 37 | 2 | has generated => is => 'rw', default => 0; | |||||||||
| 38 | |||||||||||
| 39 | =head1 METHODS | ||||||||||
| 40 | |||||||||||
| 41 | =cut | ||||||||||
| 42 | |||||||||||
| 43 | =head2 gather_files | ||||||||||
| 44 | |||||||||||
| 45 | Called for each matching file (using :InstallModules so we expect | ||||||||||
| 46 | to find all the .pm files), we'll attempt to do pod generation for | ||||||||||
| 47 | the ones which end in .pm (case insensitive, will also match .PM). | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub gather_files { | ||||||||
|
Subroutine
gather_files: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 52 | 1 | my ($self) = @_; | |||||||||
| 53 | 1 | foreach my $file (@{ $self->found_files }) { | |||||||||
| 54 | 2 | ▶ | $self->process_pod($file) if $file->name =~ /\.pm$/i; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | } | ||||||||||
| 56 | 1 | $self->log("Generated " . $self->generated . " POD files"); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | =head2 process_pod | ||||||||||
| 60 | |||||||||||
| 61 | Calls L<Pod::Inherit> to generate the merged C<.pod> documentation files. | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | 2 | ▶ | sub process_pod { | ||||||||
|
Subroutine
process_pod: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 66 | 2 | my ($self, $file) = @_; | |||||||||
| 67 | 2 | ▶ | unless(-r $file->name) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | $self->log_debug("Skipping " . $file->name . " because we can't read it, probably InMemory/FromCode"); | |||||||||
| 69 | 0 | return; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 2 | $self->log_debug("Processing " . $file->name . " for inherited methods"); | |||||||||
| 73 | 2 | local @INC = ('lib/', @INC); | |||||||||
| 74 | 2 | my $name = $file->name; | |||||||||
| 75 | 2 | my $cfg = Pod::Inherit->new({ | |||||||||
| 76 | input_files => [$name], | ||||||||||
| 77 | skip_underscored => 1, | ||||||||||
| 78 | method_format => 'L<%m|%c/%m>', | ||||||||||
| 79 | debug => 0, | ||||||||||
| 80 | }); | ||||||||||
| 81 | 2 | Module::Load::load($cfg->_file_to_package($name)); | |||||||||
| 82 | 2 | ▶ | my $content = $cfg->create_pod($name) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | |||||||||||
| 84 | # The encoding line does not make it through to the target file, so we | ||||||||||
| 85 | # hardcode a value here. Ideally it'd match the original source... but | ||||||||||
| 86 | # even more ideally, everything uses UTF-8 everywhere. | ||||||||||
| 87 | 1 | ▶ | $content = "=encoding utf8\n\n$content" unless $content =~ /^=encoding/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | |||||||||||
| 89 | 1 | (my $output = $file->name) =~ s{\.pm$}{.pod}i; | |||||||||
| 90 | 1 | $self->add_file( | |||||||||
| 91 | my $new = Dist::Zilla::File::InMemory->new({ | ||||||||||
| 92 | name => $output, | ||||||||||
| 93 | content => $content, | ||||||||||
| 94 | }) | ||||||||||
| 95 | ); | ||||||||||
| 96 | 1 | $self->log_debug("Generated POD for " . $file->name . " in " . $new->name); | |||||||||
| 97 | 1 | $self->generated($self->generated + 1); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 101 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 102 | |||||||||||
| 103 | 2 | 1; | |||||||||
| 104 | |||||||||||
| 105 | __END__ | ||||||||||