File Coverage

blib/lib/Dist/Zilla/Plugin/Prereqs.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 18 20 90.0


line stmt bran cond sub pod time code
1             # ABSTRACT: list simple prerequisites
2              
3             use Moose;
4 9     9   7452 with 'Dist::Zilla::Role::PrereqSource';
  9         26  
  9         77  
5              
6             use Dist::Zilla::Pragmas;
7 9     9   63977  
  9         28  
  9         91  
8             use namespace::autoclean;
9 9     9   76  
  9         25  
  9         85  
10             #pod =head1 SYNOPSIS
11             #pod
12             #pod In your F<dist.ini>:
13             #pod
14             #pod [Prereqs]
15             #pod Foo::Bar = 1.002
16             #pod MRO::Compat = 10
17             #pod Sub::Exporter = 0
18             #pod
19             #pod You can specify requirements for different phases and relationships with:
20             #pod
21             #pod [Prereqs]
22             #pod -phase = test
23             #pod -relationship = recommends
24             #pod
25             #pod Fitz::Fotz = 1.23
26             #pod Text::SoundEx = 3
27             #pod
28             #pod Remember that if you load two Prereqs plugins, each will needs its own name,
29             #pod added like this:
30             #pod
31             #pod [Prereqs / PluginName]
32             #pod -phase = test
33             #pod -relationship = recommends
34             #pod
35             #pod Fitz::Fotz = 1.23
36             #pod Text::SoundEx = 3
37             #pod
38             #pod If the name is the CamelCase concatenation of a phase and relationship
39             #pod (or just a relationship), it will set those parameters implicitly. If
40             #pod you use a custom name, but it does not specify the relationship, and
41             #pod you didn't specify either C<-phase> or C<-relationship>, it throws the
42             #pod error C<No -phase or -relationship specified>. This is to prevent a
43             #pod typo that makes the name meaningless from slipping by unnoticed.
44             #pod
45             #pod The example below is equivalent to the example above, except for the name of
46             #pod the resulting plugin:
47             #pod
48             #pod [Prereqs / TestRecommends]
49             #pod Fitz::Fotz = 1.23
50             #pod Text::SoundEx = 3
51             #pod
52             #pod =head1 DESCRIPTION
53             #pod
54             #pod This module adds "fixed" prerequisites to your distribution. These are prereqs
55             #pod with a known, fixed minimum version that doesn't change based on platform or
56             #pod other conditions.
57             #pod
58             #pod You can specify prerequisites for different phases and kinds of relationships.
59             #pod In C<RuntimeRequires>, the phase is Runtime and the relationship is Requires.
60             #pod These are described in more detail in the L<CPAN::Meta
61             #pod specification|CPAN::Meta::Spec/PREREQUISITES>.
62             #pod
63             #pod The phases are:
64             #pod
65             #pod =for :list
66             #pod * configure
67             #pod * build
68             #pod * test
69             #pod * runtime
70             #pod * develop
71             #pod
72             #pod The relationship types are:
73             #pod
74             #pod =for :list
75             #pod * requires
76             #pod * recommends
77             #pod * suggests
78             #pod * conflicts
79             #pod
80             #pod If the phase is omitted, it will default to I<runtime>; thus, specifying
81             #pod "Prereqs / Recommends" in your dist.ini is equivalent to I<RuntimeRecommends>.
82             #pod
83             #pod Not all of these phases are useful for all tools, especially tools that only
84             #pod understand version 1.x CPAN::Meta files.
85             #pod
86             #pod =cut
87              
88             has prereq_phase => (
89             is => 'ro',
90             isa => 'Str',
91             lazy => 1,
92             init_arg => 'phase',
93             default => 'runtime',
94             );
95              
96             has prereq_type => (
97             is => 'ro',
98             isa => 'Str',
99             lazy => 1,
100             init_arg => 'type',
101             default => 'requires',
102             );
103              
104             around dump_config => sub {
105             my ($orig, $self) = @_;
106             my $config = $self->$orig;
107              
108             my $this_config = {
109             type => $self->prereq_type,
110             phase => $self->prereq_phase,
111             };
112              
113             $config->{'' . __PACKAGE__} = $this_config;
114              
115             return $config;
116             };
117              
118             has _prereq => (
119             is => 'ro',
120             isa => 'HashRef',
121             default => sub { {} },
122             );
123              
124              
125 161     161 0 24326 around BUILDARGS => sub {
126             my $orig = shift;
127             my ($class, @arg) = @_;
128              
129             my $args = $class->$orig(@arg);
130             my %copy = %{ $args };
131              
132             my $zilla = delete $copy{zilla};
133             my $name = delete $copy{plugin_name};
134              
135             my @dashed = grep { /^-/ } keys %copy;
136              
137             my %other;
138             for my $dkey (@dashed) {
139             my $key = $dkey =~ s/^-//r;
140              
141             $other{ $key } = delete $copy{ $dkey };
142             }
143              
144             confess "don't try to pass -_prereq as a build arg!" if $other{_prereq};
145              
146             # Handle magic plugin names:
147             unless (($other{phase} and $other{type})
148             # plugin comes from a bundle
149             or $name =~ m! (?: \A | / ) Prereqs? \z !x) {
150              
151             my ($phase, $type) = $name =~ /\A
152             (Build|Test|Runtime|Configure|Develop)?
153             (Requires|Recommends|Suggests|Conflicts)
154             \z/x;
155              
156             if ($type) {
157             $other{phase} ||= lc $phase if defined $phase;
158             $other{type} ||= lc $type;
159             } else {
160             $zilla->chrome->logger->log_fatal({ prefix => "[$name] " },
161             "No -phase or -relationship specified")
162             unless $other{phase} or $other{type};
163             }
164             }
165              
166             return {
167             zilla => $zilla,
168             plugin_name => $name,
169             _prereq => \%copy,
170             %other,
171             }
172             };
173              
174             my ($self) = @_;
175              
176             $self->zilla->register_prereqs(
177 152     152 0 448 {
178             type => $self->prereq_type,
179             phase => $self->prereq_phase,
180             },
181             %{ $self->_prereq },
182             );
183             }
184 152         5057  
  152         4343  
185             __PACKAGE__->meta->make_immutable;
186             1;
187              
188             #pod =head1 SEE ALSO
189             #pod
190             #pod =over 4
191             #pod
192             #pod =item *
193             #pod
194             #pod Core Dist::Zilla plugins:
195             #pod L<@Basic|Dist::Zilla::PluginBundle::Basic>,
196             #pod L<AutoPrereqs|Dist::Zilla::Plugin::AutoPrereqs>.
197             #pod
198             #pod =item *
199             #pod
200             #pod The CPAN Meta specification: L<CPAN::Meta/PREREQUISITES>.
201             #pod
202             #pod =back
203             #pod
204             #pod =cut
205              
206              
207             =pod
208              
209             =encoding UTF-8
210              
211             =head1 NAME
212              
213             Dist::Zilla::Plugin::Prereqs - list simple prerequisites
214              
215             =head1 VERSION
216              
217             version 6.028
218              
219             =head1 SYNOPSIS
220              
221             In your F<dist.ini>:
222              
223             [Prereqs]
224             Foo::Bar = 1.002
225             MRO::Compat = 10
226             Sub::Exporter = 0
227              
228             You can specify requirements for different phases and relationships with:
229              
230             [Prereqs]
231             -phase = test
232             -relationship = recommends
233              
234             Fitz::Fotz = 1.23
235             Text::SoundEx = 3
236              
237             Remember that if you load two Prereqs plugins, each will needs its own name,
238             added like this:
239              
240             [Prereqs / PluginName]
241             -phase = test
242             -relationship = recommends
243              
244             Fitz::Fotz = 1.23
245             Text::SoundEx = 3
246              
247             If the name is the CamelCase concatenation of a phase and relationship
248             (or just a relationship), it will set those parameters implicitly. If
249             you use a custom name, but it does not specify the relationship, and
250             you didn't specify either C<-phase> or C<-relationship>, it throws the
251             error C<No -phase or -relationship specified>. This is to prevent a
252             typo that makes the name meaningless from slipping by unnoticed.
253              
254             The example below is equivalent to the example above, except for the name of
255             the resulting plugin:
256              
257             [Prereqs / TestRecommends]
258             Fitz::Fotz = 1.23
259             Text::SoundEx = 3
260              
261             =head1 DESCRIPTION
262              
263             This module adds "fixed" prerequisites to your distribution. These are prereqs
264             with a known, fixed minimum version that doesn't change based on platform or
265             other conditions.
266              
267             You can specify prerequisites for different phases and kinds of relationships.
268             In C<RuntimeRequires>, the phase is Runtime and the relationship is Requires.
269             These are described in more detail in the L<CPAN::Meta
270             specification|CPAN::Meta::Spec/PREREQUISITES>.
271              
272             The phases are:
273              
274             =over 4
275              
276             =item *
277              
278             configure
279              
280             =item *
281              
282             build
283              
284             =item *
285              
286             test
287              
288             =item *
289              
290             runtime
291              
292             =item *
293              
294             develop
295              
296             =back
297              
298             The relationship types are:
299              
300             =over 4
301              
302             =item *
303              
304             requires
305              
306             =item *
307              
308             recommends
309              
310             =item *
311              
312             suggests
313              
314             =item *
315              
316             conflicts
317              
318             =back
319              
320             If the phase is omitted, it will default to I<runtime>; thus, specifying
321             "Prereqs / Recommends" in your dist.ini is equivalent to I<RuntimeRecommends>.
322              
323             Not all of these phases are useful for all tools, especially tools that only
324             understand version 1.x CPAN::Meta files.
325              
326             =head1 PERL VERSION
327              
328             This module should work on any version of perl still receiving updates from
329             the Perl 5 Porters. This means it should work on any version of perl released
330             in the last two to three years. (That is, if the most recently released
331             version is v5.40, then this module should work on both v5.40 and v5.38.)
332              
333             Although it may work on older versions of perl, no guarantee is made that the
334             minimum required version will not be increased. The version may be increased
335             for any reason, and there is no promise that patches will be accepted to lower
336             the minimum required perl.
337              
338             =head1 SEE ALSO
339              
340             =over 4
341              
342             =item *
343              
344             Core Dist::Zilla plugins:
345             L<@Basic|Dist::Zilla::PluginBundle::Basic>,
346             L<AutoPrereqs|Dist::Zilla::Plugin::AutoPrereqs>.
347              
348             =item *
349              
350             The CPAN Meta specification: L<CPAN::Meta/PREREQUISITES>.
351              
352             =back
353              
354             =head1 AUTHOR
355              
356             Ricardo SIGNES 😏 <cpan@semiotic.systems>
357              
358             =head1 COPYRIGHT AND LICENSE
359              
360             This software is copyright (c) 2022 by Ricardo SIGNES.
361              
362             This is free software; you can redistribute it and/or modify it under
363             the same terms as the Perl 5 programming language system itself.
364              
365             =cut