File Coverage

blib/lib/Dist/Zilla/Plugin/RecommendedPrereqs.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             #---------------------------------------------------------------------
2             package Dist::Zilla::Plugin::RecommendedPrereqs;
3             #
4             # Copyright 2011 Christopher J. Madsen
5             #
6             # Author: Christopher J. Madsen <perl@cjmweb.net>
7             # Created: 31 Oct 2011
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: Look for comments recommending prerequisites
18             #---------------------------------------------------------------------
19              
20             our $VERSION = '4.21';
21             # This file is part of Dist-Zilla-Plugins-CJM 4.26 (December 13, 2014)
22              
23              
24 1     1   1418 use 5.008;
  1         3  
  1         44  
25 1     1   291 use Moose;
  0            
  0            
26             with(
27             'Dist::Zilla::Role::PrereqSource',
28             'Dist::Zilla::Role::FileFinderUser' => {
29             default_finders => [ ':InstallModules', ':ExecFiles' ],
30             },
31             'Dist::Zilla::Role::FileFinderUser' => {
32             method => 'found_test_files',
33             finder_arg_names => [ 'test_finder' ],
34             default_finders => [ ':TestFiles' ],
35             },
36             );
37              
38             use namespace::autoclean;
39              
40             #=====================================================================
41              
42             use CPAN::Meta::Requirements ();
43             use version ();
44              
45             sub register_prereqs
46             {
47             my $self = shift;
48              
49             my @sets = (
50             [ runtime => 'found_files' ],
51             [ test => 'found_test_files' ],
52             );
53              
54             my %runtime;
55              
56             for my $fileset (@sets) {
57             my ($phase, $method) = @$fileset;
58              
59             my %req = map { $_ => CPAN::Meta::Requirements->new } qw(RECOMMEND SUGGEST);
60              
61             my $files = $self->$method;
62              
63             foreach my $file (@$files) {
64             $self->log_debug("Checking " . $file->name);
65             my $content = $file->content;
66              
67             while ($content =~ /^ [ \t]* \# [ \t]* (RECOMMEND|SUGGEST) [ \t]+ PREREQ:
68             [ \t]* (\S+) (?: [ \t]+ (\S+) )?/mgx) {
69             $req{$1}->add_minimum($2, $3 || 0);
70             }
71             } # end foreach $file
72              
73             # we're done, add what we've found
74             while (my ($type, $req) = each %req) {
75             $req = $req->as_string_hash;
76              
77             if ($phase eq 'runtime') {
78             $runtime{$type} = $req;
79             } else {
80             delete $req->{$_} for
81             grep { exists $req->{$_} and $runtime{$type}{$_} ge $req->{$_} }
82             keys %{ $runtime{$type} || {} };
83             }
84              
85             $self->zilla->register_prereqs({ phase => $phase, type => "\L${type}s" },
86             %$req) if %$req;
87             }
88             } # end foreach $fileset
89             } # end register_prereqs
90              
91             #=====================================================================
92             # Package Return Value:
93              
94             __PACKAGE__->meta->make_immutable;
95             1;
96              
97             __END__
98              
99             =head1 NAME
100              
101             Dist::Zilla::Plugin::RecommendedPrereqs - Look for comments recommending prerequisites
102              
103             =head1 VERSION
104              
105             This document describes version 4.21 of
106             Dist::Zilla::Plugin::RecommendedPrereqs, released December 13, 2014
107             as part of Dist-Zilla-Plugins-CJM version 4.26.
108              
109             =head1 SYNOPSIS
110              
111             In your F<dist.ini>:
112              
113             [RecommendedPrereqs]
114              
115             In your code:
116              
117             # RECOMMEND PREREQ: Foo::Bar 1.0
118             # SUGGEST PREREQ: Foo::Suggested
119              
120             =head1 DESCRIPTION
121              
122             If included, this plugin will look for special comments that specify
123             suggested or recommended prerequisites. It's intended as a companion
124             to L<AutoPrereqs|Dist::Zilla::Plugin::AutoPrereqs>, which can only
125             determine required prerequisites.
126              
127             Each comment must be on a line by itself, and begin with either
128             S<C<RECOMMEND PREREQ:>> or S<C<SUGGEST PREREQ:>> followed by the
129             module name. The name may be followed by the minimum version, which
130             may in turn be followed by a note explaining the prereq (which will be
131             ignored). If the note is present, the version I<must> be present,
132             even if it's 0.
133              
134             =head1 INCOMPATIBILITIES
135              
136             None reported.
137              
138             =head1 BUGS AND LIMITATIONS
139              
140             The parser currently just looks for lines beginning with a C<#> (which
141             may be preceded by whitespace). This means it looks in strings and
142             here docs, as well as after C<__END__>. This behavior may be fixed in
143             the future and should not be depended on.
144              
145              
146             =for Pod::Coverage
147             register_prereqs
148              
149             =head1 AUTHOR
150              
151             Christopher J. Madsen S<C<< <perl AT cjmweb.net> >>>
152              
153             Please report any bugs or feature requests
154             to S<C<< <bug-Dist-Zilla-Plugins-CJM AT rt.cpan.org> >>>
155             or through the web interface at
156             L<< http://rt.cpan.org/Public/Bug/Report.html?Queue=Dist-Zilla-Plugins-CJM >>.
157              
158             You can follow or contribute to Dist-Zilla-Plugins-CJM's development at
159             L<< https://github.com/madsen/dist-zilla-plugins-cjm >>.
160              
161             =head1 COPYRIGHT AND LICENSE
162              
163             This software is copyright (c) 2014 by Christopher J. Madsen.
164              
165             This is free software; you can redistribute it and/or modify it under
166             the same terms as the Perl 5 programming language system itself.
167              
168             =head1 DISCLAIMER OF WARRANTY
169              
170             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
171             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
172             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
173             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
174             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
175             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
176             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
177             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
178             NECESSARY SERVICING, REPAIR, OR CORRECTION.
179              
180             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
181             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
182             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE
183             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
184             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
185             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
186             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
187             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
188             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
189             SUCH DAMAGES.
190              
191             =cut