File Coverage

blib/lib/Dist/Zilla/Plugin/AutoPrereqs.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 25 27 92.5


line stmt bran cond sub pod time code
1             # ABSTRACT: automatically extract prereqs from your modules
2              
3             use Moose;
4 6     6   4694 with(
  6         16  
  6         46  
5             'Dist::Zilla::Role::PrereqScanner',
6             'Dist::Zilla::Role::PrereqSource',
7             'Dist::Zilla::Role::PPI',
8             );
9              
10             use Dist::Zilla::Pragmas;
11 6     6   43127  
  6         15  
  6         62  
12             use Moose::Util::TypeConstraints 'enum';
13 6     6   61 use namespace::autoclean;
  6         16  
  6         78  
14 6     6   2867  
  6         14  
  6         59  
15             #pod =head1 SYNOPSIS
16             #pod
17             #pod In your F<dist.ini>:
18             #pod
19             #pod [AutoPrereqs]
20             #pod skip = ^Foo|Bar$
21             #pod skip = ^Other::Dist
22             #pod
23             #pod =head1 DESCRIPTION
24             #pod
25             #pod This plugin will extract loosely your distribution prerequisites from
26             #pod your files using L<Perl::PrereqScanner>.
27             #pod
28             #pod If some prereqs are not found, you can still add them manually with the
29             #pod L<Prereqs|Dist::Zilla::Plugin::Prereqs> plugin.
30             #pod
31             #pod This plugin will skip the modules shipped within your dist.
32             #pod
33             #pod B<Note>, if you have any non-Perl files in your C<t/> directory or other
34             #pod directories being scanned, be sure to mark those files' encoding as C<bytes>
35             #pod with the L<Encoding|Dist::Zilla::Plugin::Encoding> plugin so they won't be
36             #pod scanned:
37             #pod
38             #pod [Encoding]
39             #pod encoding = bytes
40             #pod match = ^t/data/
41             #pod
42             #pod =attr finder
43             #pod
44             #pod This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder>
45             #pod whose files will be scanned to determine runtime prerequisites. It
46             #pod may be specified multiple times. The default value is
47             #pod C<:InstallModules> and C<:ExecFiles>.
48             #pod
49             #pod =attr test_finder
50             #pod
51             #pod Just like C<finder>, but for test-phase prerequisites. The default
52             #pod value is C<:TestFiles>.
53             #pod
54             #pod =attr configure_finder
55             #pod
56             #pod Just like C<finder>, but for configure-phase prerequisites. There is
57             #pod no default value; AutoPrereqs will not determine configure-phase
58             #pod prerequisites unless you set configure_finder.
59             #pod
60             #pod =attr develop_finder
61             #pod
62             #pod Just like C<finder>, but for develop-phase prerequisites. The default value
63             #pod is C<:ExtraTestFiles>.
64             #pod
65             #pod =attr skips
66             #pod
67             #pod This is an arrayref of regular expressions, derived from all the 'skip' lines
68             #pod in the configuration. Any module names matching any of these regexes will not
69             #pod be registered as prerequisites.
70             #pod
71             #pod =attr relationship
72             #pod
73             #pod The relationship used for the registered prerequisites. The default value is
74             #pod 'requires'; other options are 'recommends' and 'suggests'.
75             #pod
76             #pod =attr extra_scanners
77             #pod
78             #pod This is an arrayref of scanner names (as expected by L<Perl::PrereqScanner>).
79             #pod It will be passed as the C<extra_scanners> parameter to L<Perl::PrereqScanner>.
80             #pod
81             #pod =attr scanners
82             #pod
83             #pod This is an arrayref of scanner names (as expected by L<Perl::PrereqScanner>).
84             #pod If present, it will be passed as the C<scanners> parameter to
85             #pod L<Perl::PrereqScanner>, which means that it will replace the default list
86             #pod of scanners.
87             #pod
88             #pod =head1 SEE ALSO
89             #pod
90             #pod L<Prereqs|Dist::Zilla::Plugin::Prereqs>, L<Perl::PrereqScanner>.
91             #pod
92             #pod =head1 CREDITS
93             #pod
94             #pod This plugin was originally contributed by Jerome Quelin.
95             #pod
96             #pod =cut
97              
98             scanner => 'scanners',
99             relationship => 'type' } }
100              
101             has extra_scanners => (
102             is => 'ro',
103             isa => 'ArrayRef[Str]',
104             default => sub { [] },
105             );
106              
107             has scanners => (
108             is => 'ro',
109             isa => 'ArrayRef[Str]',
110             predicate => 'has_scanners',
111             );
112              
113              
114             has _scanner => (
115             is => 'ro',
116             lazy => 1,
117             default => sub {
118             my $self = shift;
119              
120             require Perl::PrereqScanner;
121             Perl::PrereqScanner->VERSION('1.016'); # don't skip "lib"
122              
123             return Perl::PrereqScanner->new(
124             ($self->has_scanners ? (scanners => $self->scanners) : ()),
125             extra_scanners => $self->extra_scanners,
126             )
127             },
128             init_arg => undef,
129             );
130              
131             has type => (
132             is => 'ro',
133             isa => enum([qw(requires recommends suggests)]),
134             default => 'requires',
135             );
136              
137             my ($self, $file) = @_;
138             return $self->_scanner->scan_ppi_document($self->ppi_document_for_file($file))
139             }
140              
141 91     91 0 265 my $self = shift;
142 91         2968  
143             my $type = $self->type;
144              
145             my $reqs_by_phase = $self->scan_prereqs;
146 29     29 0 86 while (my ($phase, $reqs) = each %$reqs_by_phase) {
147             $self->zilla->register_prereqs({ phase => $phase, type => $type }, %$reqs);
148 29         1096 }
149             }
150 29         204  
151 29         219 __PACKAGE__->meta->make_immutable;
152 116         3868 1;
153              
154              
155             =pod
156              
157             =encoding UTF-8
158              
159             =head1 NAME
160              
161             Dist::Zilla::Plugin::AutoPrereqs - automatically extract prereqs from your modules
162              
163             =head1 VERSION
164              
165             version 6.028
166              
167             =head1 SYNOPSIS
168              
169             In your F<dist.ini>:
170              
171             [AutoPrereqs]
172             skip = ^Foo|Bar$
173             skip = ^Other::Dist
174              
175             =head1 DESCRIPTION
176              
177             This plugin will extract loosely your distribution prerequisites from
178             your files using L<Perl::PrereqScanner>.
179              
180             If some prereqs are not found, you can still add them manually with the
181             L<Prereqs|Dist::Zilla::Plugin::Prereqs> plugin.
182              
183             This plugin will skip the modules shipped within your dist.
184              
185             B<Note>, if you have any non-Perl files in your C<t/> directory or other
186             directories being scanned, be sure to mark those files' encoding as C<bytes>
187             with the L<Encoding|Dist::Zilla::Plugin::Encoding> plugin so they won't be
188             scanned:
189              
190             [Encoding]
191             encoding = bytes
192             match = ^t/data/
193              
194             =head1 PERL VERSION
195              
196             This module should work on any version of perl still receiving updates from
197             the Perl 5 Porters. This means it should work on any version of perl released
198             in the last two to three years. (That is, if the most recently released
199             version is v5.40, then this module should work on both v5.40 and v5.38.)
200              
201             Although it may work on older versions of perl, no guarantee is made that the
202             minimum required version will not be increased. The version may be increased
203             for any reason, and there is no promise that patches will be accepted to lower
204             the minimum required perl.
205              
206             =head1 ATTRIBUTES
207              
208             =head2 finder
209              
210             This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder>
211             whose files will be scanned to determine runtime prerequisites. It
212             may be specified multiple times. The default value is
213             C<:InstallModules> and C<:ExecFiles>.
214              
215             =head2 test_finder
216              
217             Just like C<finder>, but for test-phase prerequisites. The default
218             value is C<:TestFiles>.
219              
220             =head2 configure_finder
221              
222             Just like C<finder>, but for configure-phase prerequisites. There is
223             no default value; AutoPrereqs will not determine configure-phase
224             prerequisites unless you set configure_finder.
225              
226             =head2 develop_finder
227              
228             Just like C<finder>, but for develop-phase prerequisites. The default value
229             is C<:ExtraTestFiles>.
230              
231             =head2 skips
232              
233             This is an arrayref of regular expressions, derived from all the 'skip' lines
234             in the configuration. Any module names matching any of these regexes will not
235             be registered as prerequisites.
236              
237             =head2 relationship
238              
239             The relationship used for the registered prerequisites. The default value is
240             'requires'; other options are 'recommends' and 'suggests'.
241              
242             =head2 extra_scanners
243              
244             This is an arrayref of scanner names (as expected by L<Perl::PrereqScanner>).
245             It will be passed as the C<extra_scanners> parameter to L<Perl::PrereqScanner>.
246              
247             =head2 scanners
248              
249             This is an arrayref of scanner names (as expected by L<Perl::PrereqScanner>).
250             If present, it will be passed as the C<scanners> parameter to
251             L<Perl::PrereqScanner>, which means that it will replace the default list
252             of scanners.
253              
254             =head1 SEE ALSO
255              
256             L<Prereqs|Dist::Zilla::Plugin::Prereqs>, L<Perl::PrereqScanner>.
257              
258             =head1 CREDITS
259              
260             This plugin was originally contributed by Jerome Quelin.
261              
262             =head1 AUTHOR
263              
264             Ricardo SIGNES 😏 <cpan@semiotic.systems>
265              
266             =head1 COPYRIGHT AND LICENSE
267              
268             This software is copyright (c) 2022 by Ricardo SIGNES.
269              
270             This is free software; you can redistribute it and/or modify it under
271             the same terms as the Perl 5 programming language system itself.
272              
273             =cut