File Coverage

blib/lib/Dist/Zilla/Plugin/PodInherit.pm
Criterion Covered Total %
statement 38 40 95.0
branch 4 6 66.6
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 53 57 92.9


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::PodInherit;
2             # ABSTRACT: autogenerate inherited POD sections for Dist::Zilla distributions
3 1     1   3446945 use strict;
  1         2  
  1         40  
4 1     1   8 use warnings;
  1         3  
  1         35  
5              
6 1     1   6 use Moose;
  1         2  
  1         10  
7 1     1   7923 use Pod::Inherit;
  1         42738  
  1         40  
8 1     1   488 use Module::Load;
  1         1112  
  1         8  
9              
10 1     1   584 use Dist::Zilla::File::InMemory;
  1         98584  
  1         544  
11              
12             our $VERSION = '0.008';
13             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             with 'Dist::Zilla::Role::FileGatherer';
32             with 'Dist::Zilla::Role::FileInjector';
33             with 'Dist::Zilla::Role::FileFinderUser' => {
34             default_finders => [ qw( :InstallModules ) ],
35             };
36              
37             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             sub gather_files {
52 1     1 1 75127 my ($self) = @_;
53 1         2 foreach my $file (@{ $self->found_files }) {
  1         11  
54 2 50       2510 $self->process_pod($file) if $file->name =~ /\.pm$/i;
55             }
56 1         37 $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             sub process_pod {
66 2     2 1 121 my ($self, $file) = @_;
67 2 50       7 unless(-r $file->name) {
68 0         0 $self->log_debug("Skipping " . $file->name . " because we can't read it, probably InMemory/FromCode");
69 0         0 return;
70             }
71              
72 2         144 $self->log_debug("Processing " . $file->name . " for inherited methods");
73 2         285 local @INC = ('lib/', @INC);
74 2         10 my $name = $file->name;
75 2         126 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         210 Module::Load::load($cfg->_file_to_package($name));
82 2 100       37 my $content = $cfg->create_pod($name) or return;
83 1         7456 (my $output = $file->name) =~ s{\.pm$}{.pod}i;
84 1         116 $self->add_file(
85             my $new = Dist::Zilla::File::InMemory->new({
86             name => $output,
87             content => $content,
88             })
89             );
90 1         1071 $self->log_debug("Generated POD for " . $file->name . " in " . $new->name);
91 1         185 $self->generated($self->generated + 1);
92             }
93              
94             __PACKAGE__->meta->make_immutable;
95 1     1   12 no Moose;
  1         2  
  1         7  
96              
97             1;
98              
99             __END__
100              
101             =head1 BUGS
102              
103             Some of the path and extension handling may be non-portable, should probably
104             use L<File::Basename> and L<File::Spec>.
105              
106             Also, generating an entire .pod output file which is identical apart from the
107             extra inherited methods section seems suboptimal, other plugins such as
108             L<Dist::Zilla::Plugin::PodVersion> manage to update the source .pm file
109             directly so perhaps that would be a better approach.
110              
111             =head1 SEE ALSO
112              
113             =over 4
114              
115             =item * L<Pod::POM>
116              
117             =item * L<Pod::Inherit>
118              
119             =back
120              
121             =head1 AUTHOR
122              
123             Tom Molesworth <cpan@entitymodel.com>
124              
125             =head1 LICENSE
126              
127             Copyright Tom Molesworth 2012-2013. Licensed under the same terms as Perl itself.
128