File Coverage

blib/lib/Dist/Zilla/Plugin/PodLoom.pm
Criterion Covered Total %
statement 50 50 100.0
branch 8 14 57.1
condition 3 6 50.0
subroutine 11 11 100.0
pod 0 2 0.0
total 72 83 86.7


line stmt bran cond sub pod time code
1             #---------------------------------------------------------------------
2             package Dist::Zilla::Plugin::PodLoom;
3             #
4             # Copyright 2009 Christopher J. Madsen
5             #
6             # Author: Christopher J. Madsen <perl@cjmweb.net>
7             # Created: 7 Oct 2009
8             #
9             # This program is free software; you can redistribute it and/or modify
10             # it under the same terms as Perl itself.
11             #
12             # This program is distributed in the hope that it will be useful,
13             # but WITHOUT ANY WARRANTY; without even the implied warranty of
14             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
15             # GNU General Public License or the Artistic License for more details.
16             #
17             # ABSTRACT: Process module documentation through Pod::Loom
18             #---------------------------------------------------------------------
19              
20             our $VERSION = '5.001';
21             # This file is part of Dist-Zilla-Plugin-PodLoom 5.001 (July 18, 2015)
22              
23              
24 2     2   712654 use Moose 0.65; # attr fulfills requires
  2         367032  
  2         15  
25 2     2   12165 use Moose::Autobox;
  2         341963  
  2         19  
26             with(qw(Dist::Zilla::Role::FileMunger
27             Dist::Zilla::Role::ModuleInfo
28             Dist::Zilla::Role::FileFinderUser) => {
29             default_finders => [ ':InstallModules' ],
30             },
31             );
32              
33             # List minimum versions for AutoPrereqs:
34 2     2   1191 use 5.008;
  2         7  
35 2     2   687 use Dist::Zilla 4.200001 (); # abstract_from_file change
  2         1119167  
  2         227  
36 2     2   1946 use Dist::Zilla::Role::ModuleInfo 0.08 (); # from Plugins, not PluginBundle
  2         59960  
  2         83  
37              
38 2     2   1494 use Hash::Merge::Simple ();
  2         1014  
  2         66  
39 2     2   1199 use Pod::Loom 0.05 (); # bugtracker
  2         256164  
  2         1588  
40              
41              
42             has template => (
43             is => 'ro',
44             isa => 'Str',
45             default => 'Default',
46             );
47              
48              
49             has data_file => (
50             is => 'ro',
51             isa => 'Str',
52             init_arg => 'data',
53             );
54              
55             has data => (
56             is => 'ro',
57             isa => 'HashRef',
58             init_arg => undef,
59             lazy => 1,
60             builder => '_initialize_data',
61             );
62              
63             has loom => (
64             is => 'ro',
65             isa => 'Pod::Loom',
66             init_arg => undef,
67             lazy => 1,
68             default => sub { Pod::Loom->new(template => shift->template) },
69             );
70              
71             #---------------------------------------------------------------------
72             sub _initialize_data
73             {
74 1     1   3 my $plugin = shift;
75              
76 1         32 my $fname = $plugin->data_file;
77              
78 1 50       3 return {} unless $fname;
79              
80 1 50       36 open my $fh, '<', $fname or die "can't open $fname for reading: $!";
81 1         2 my $code = do { local $/; <$fh> };
  1         4  
  1         22  
82 1         7 close $fh;
83              
84 1         3 local $@;
85 1         92 my $result = eval "package Dist::Zilla::Plugin::PodLoom::_eval; $code";
86              
87 1 50       7 die $@ if $@;
88              
89 1         32 return $result;
90             } # end _initialize_data
91              
92             #---------------------------------------------------------------------
93             sub munge_files {
94 1     1 0 64724 my ($self) = @_;
95              
96 1         8 $self->munge_file($_) for $self->found_files->flatten;
97             } # end munge_files
98              
99             #---------------------------------------------------------------------
100             sub munge_file
101             {
102 2     2 0 1595 my ($self, $file) = @_;
103              
104 2         16 my $info = $self->get_module_info($file);
105              
106 2         7962 my $abstract = Dist::Zilla::Util->abstract_from_file($file);
107 2         5665 my $repo = $self->zilla->distmeta->{resources}{repository};
108              
109 2         23905 my $module = $info->name;
110 2 100 66     29 if (!$module or $module eq 'main') {
111 1         6 $module = $file->name;
112 1         54 $module =~ s!^.*/!!s; # Strip directory names
113             }
114              
115             my $dataHash = Hash::Merge::Simple::merge(
116             {
117             ($abstract ? (abstract => $abstract) : ()),
118             authors => $self->zilla->authors,
119             dist => $self->zilla->name,
120             license_notice => $self->zilla->license->notice,
121             module => $module,
122             bugtracker => $self->zilla->distmeta->{resources}{bugtracker},
123             repository => $repo->{web} || $repo->{url},
124             # Have to stringify version object:
125 2 50 33     76 ($info->version ? (version => q{} . $info->version) : ()),
    50          
126             zilla => $self->zilla,
127             }, $self->data,
128             );
129              
130 2 50       170 my $method = Dist::Zilla->VERSION < 5 ? 'content' : 'encoded_content';
131              
132 2         20 my $content = $file->$method;
133              
134 2         259 $file->$method( $self->loom->weave(\$content, $file->name, $dataHash) );
135              
136 2         186560 return;
137             } # end munge_file
138              
139             #---------------------------------------------------------------------
140             around dump_config => sub {
141             my ($orig, $self) = @_;
142             my $config = $self->$orig;
143              
144             $config->{'Pod::Loom version'} = Pod::Loom->VERSION;
145              
146             return $config;
147             }; # end dump_config
148              
149             #---------------------------------------------------------------------
150 2     2   23 no Moose;
  2         5  
  2         20  
151             __PACKAGE__->meta->make_immutable;
152             1;
153              
154             __END__
155              
156             =head1 NAME
157              
158             Dist::Zilla::Plugin::PodLoom - Process module documentation through Pod::Loom
159              
160             =head1 VERSION
161              
162             This document describes version 5.001 of
163             Dist::Zilla::Plugin::PodLoom, released July 18, 2015
164             as part of Dist-Zilla-Plugin-PodLoom version 5.001.
165              
166             =head1 SYNOPSIS
167              
168             In your F<dist.ini>:
169              
170             [PodLoom]
171             template = Default ; this is the default
172             data = loom.pl ; there is no default for this
173              
174             =head1 DESCRIPTION
175              
176             If included, this plugin will process each F<.pm> and F<.pod> file
177             under F<lib> or in the root directory through Pod::Loom.
178              
179             =head1 ATTRIBUTES
180              
181             =head2 data
182              
183             Since Pod::Loom templates may want configuration that doesn't fit in
184             an INI file, you can specify a file containing Perl code to evaluate.
185             The result should be a hash reference, which will be passed to
186             Pod::Loom's C<weave> method.
187              
188             PodLoom automatically includes the following keys, which will be
189             merged with the hashref from your code. (Your code can override these
190             values.)
191              
192             =over
193              
194             =item abstract
195              
196             The abstract for the file being processed (if it can be determined)
197              
198             =item authors
199              
200             C<< $zilla->authors >>
201              
202             =item dist
203              
204             C<< $zilla->name >>
205              
206             =item license_notice
207              
208             C<< $zilla->license->notice >>
209              
210             =item module
211              
212             The primary package of the file being processed. If Module::Metadata
213             could not determine the package, or if it is explicitly C<main>, this
214             is the filename (without directories), because that's the equivalent
215             of a package name for scripts.
216              
217             =item repository
218              
219             C<< $zilla->distmeta->{resources}{repository}{web} >>
220             (or the C<url> key if C<web> is not set)
221              
222             =item version
223              
224             The version number of the file being processed
225             (if Module::Metadata could determine it)
226              
227             =item zilla
228              
229             The Dist::Zilla object itself
230              
231             =back
232              
233              
234             =for Pod::Coverage
235             munge_files?
236              
237             =head2 finder
238              
239             This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder>
240             whose files will be processed by L<Pod::Loom>. It may be specified
241             multiple times. The default value is C<:InstallModules>.
242              
243              
244             =head2 template
245              
246             This will be passed to Pod::Loom as its C<template>.
247             Defaults to C<Default>.
248              
249             =head1 INCOMPATIBILITIES
250              
251             None reported.
252              
253             =head1 BUGS AND LIMITATIONS
254              
255             No bugs have been reported.
256              
257             =head1 AUTHOR
258              
259             Christopher J. Madsen S<C<< <perl AT cjmweb.net> >>>
260              
261             Please report any bugs or feature requests
262             to S<C<< <bug-Dist-Zilla-Plugin-PodLoom AT rt.cpan.org> >>>
263             or through the web interface at
264             L<< http://rt.cpan.org/Public/Bug/Report.html?Queue=Dist-Zilla-Plugin-PodLoom >>.
265              
266             You can follow or contribute to Dist-Zilla-Plugin-PodLoom's development at
267             L<< https://github.com/madsen/dist-zilla-plugin-podloom >>.
268              
269             =head1 COPYRIGHT AND LICENSE
270              
271             This software is copyright (c) 2015 by Christopher J. Madsen.
272              
273             This is free software; you can redistribute it and/or modify it under
274             the same terms as the Perl 5 programming language system itself.
275              
276             =head1 DISCLAIMER OF WARRANTY
277              
278             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
279             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
280             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
281             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
282             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
283             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
284             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
285             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
286             NECESSARY SERVICING, REPAIR, OR CORRECTION.
287              
288             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
289             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
290             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE
291             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
292             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
293             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
294             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
295             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
296             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
297             SUCH DAMAGES.
298              
299             =cut