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