File Coverage

blib/lib/Dist/Zilla/Plugin/Author/Plicease/SpecialPrereqs.pm
Criterion Covered Total %
statement 17 79 21.5
branch 0 24 0.0
condition n/a
subroutine 6 10 60.0
pod 0 4 0.0
total 23 117 19.6


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::Plicease::SpecialPrereqs 2.73 {
2              
3 1     1   972 use 5.020;
  1         5  
4 1     1   12 use Moose;
  1         2  
  1         8  
5 1     1   6885 use experimental qw( postderef );
  1         4  
  1         23  
6 1     1   208 use Dist::Zilla::Plugin::Author::Plicease;
  1         3  
  1         40  
7 1     1   655 use Config::INI::Reader;
  1         5466  
  1         37  
8 1     1   545 use Dist::Zilla::Util::AuthorDeps;
  1         6156  
  1         1911  
9              
10             # ABSTRACT: Special prereq handling
11              
12              
13             with 'Dist::Zilla::Role::BeforeRelease';
14             with 'Dist::Zilla::Role::PrereqSource';
15             with 'Dist::Zilla::Role::InstallTool';
16              
17 0     0 0   sub mvp_multivalue_args { qw( upgrade preamble ) }
18              
19             has preamble => (
20             is => 'ro',
21             default => sub { [] },
22             );
23              
24             has upgrade => (
25             is => 'ro',
26             default => sub { [] },
27             );
28              
29             has win32 => (
30             is => 'ro',
31             default => 0,
32             );
33              
34             has git => (
35             is => 'ro',
36             default => 0,
37             );
38              
39             sub register_prereqs
40             {
41 0     0 0   my($self) = @_;
42              
43 0           my $prereqs = $self->zilla->prereqs->as_string_hash;
44              
45 0           my %upgrades = qw(
46             Moo 2.0
47             PerlX::Maybe 0.003
48             AnyEvent::Open3::Simple 0.83
49             Path::Class 0.26
50             Mojolicious 4.31
51             Role::Tiny 1.003001
52             Test::More 0.98
53             Test::Exit 0.11
54             Clustericious 1.20
55             Test::Clustericious::Cluster 0.31
56             ExtUtils::ParseXS 3.30
57             );
58              
59 0           $upgrades{$_} = '1.302015' for (
60 0           (map { "Test2::$_" } qw( API Event Formatter Formatter::TAP Hub IPC Util )),
61 0           (map { "Test2::API::$_" } qw( Breakage Context Instance Stack )),
62 0           (map { "Test2::Event::$_" } qw( Bail Diag Exception Note Ok Plan Skp Subtest Waiting )),
63 0           (map { "Test2::Hub::$_" } qw( Interceptor Interceptor::Terminator Subtest )),
64 0           (map { "Test2::IPC::$_" } qw( Driver Driver::Files )),
65 0           (map { "Test2::Util::$_" } qw( ExternalMeta HashBase Trace )),
66             'Test2',
67             );
68              
69 0           $upgrades{$_} = '0.000121' for qw(
70             Test2::V0
71             Test2::Bundle
72             Test2::Bundle::Extended
73             Test2::Bundle::More
74             Test2::Bundle::Simple
75             Test2::Compare
76             Test2::Compare::Array
77             Test2::Compare::Base
78             Test2::Compare::Custom
79             Test2::Compare::Delta
80             Test2::Compare::Event
81             Test2::Compare::EventMeta
82             Test2::Compare::Hash
83             Test2::Compare::Meta
84             Test2::Compare::Number
85             Test2::Compare::Object
86             Test2::Compare::OrderedSubset
87             Test2::Compare::Pattern
88             Test2::Compare::Ref
89             Test2::Compare::Regex
90             Test2::Compare::Scalar
91             Test2::Compare::Set
92             Test2::Compare::String
93             Test2::Compare::Undef
94             Test2::Compare::Wildcard
95             Test2::Mock
96             Test2::Plugin
97             Test2::Plugin::BailOnFail
98             Test2::Plugin::DieOnFail
99             Test2::Plugin::ExitSummary
100             Test2::Plugin::SRand
101             Test2::Plugin::UTF8
102             Test2::Require
103             Test2::Require::AuthorTesting
104             Test2::Require::EnvVar
105             Test2::Require::Fork
106             Test2::Require::Module
107             Test2::Require::Perl
108             Test2::Require::RealFork
109             Test2::Require::Threads
110             Test2::Suite
111             Test2::Todo
112             Test2::Tools
113             Test2::Tools::Basic
114             Test2::Tools::Class
115             Test2::Tools::ClassicCompare
116             Test2::Tools::Compare
117             Test2::Tools::Defer
118             Test2::Tools::Encoding
119             Test2::Tools::Event
120             Test2::Tools::Exception
121             Test2::Tools::Exports
122             Test2::Tools::Grab
123             Test2::Tools::Mock
124             Test2::Tools::Ref
125             Test2::Tools::Subtest
126             Test2::Tools::Target
127             Test2::Tools::Warnings
128             Test2::Util::Grabber
129             Test2::Util::Ref
130             Test2::Util::Stash
131             Test2::Util::Sub
132             Test2::Util::Table
133             Test2::Util::Table::LineBreak
134             );
135              
136 0           foreach my $upgrade ($self->upgrade->@*)
137             {
138 0 0         if($upgrade =~ /^\s*(\S+)\s*=\s*(\S+)\s*$/)
139             {
140 0           $upgrades{$1} = $2;
141             }
142             else
143             {
144 0           $self->log_fatal("upgrade failed: $upgrade");
145             }
146             }
147              
148 0           foreach my $phase (keys %$prereqs)
149             {
150 0           foreach my $type (keys $prereqs->{$phase}->%*)
151             {
152 0           foreach my $module (sort keys $prereqs->{$phase}->{$type}->%*)
153             {
154 0           my $value = $prereqs->{$phase}->{$type}->{$module};
155 0 0         next unless $value == 0;
156 0 0         if($upgrades{$module})
157             {
158             $self->zilla->register_prereqs({
159             type => $type,
160             phase => $phase,
161 0           }, $module => $upgrades{$module} );
162             }
163             }
164             }
165             }
166              
167 0           foreach my $phase (keys %$prereqs)
168             {
169 0           foreach my $type (keys $prereqs->{$phase}->%*)
170             {
171 0           foreach my $module (keys $prereqs->{$phase}->{$type}->%*)
172             {
173 0 0         if($module =~ /^(JSON|PerlX::Maybe)$/)
174             {
175 0           $self->zilla->register_prereqs({
176             type => 'recommends',
177             phase => $phase,
178             }, join('::', $module, 'XS') => 0 );
179             }
180 0 0         if($module eq 'JSON::MaybeXS')
181             {
182 0           $self->zilla->register_prereqs({
183             type => 'recommends',
184             phase => $phase,
185             }, "Cpanel::JSON::XS" => 0);
186             }
187 0           my($first) = split /::/, $module;
188 0 0         if($first =~ /^(AnyEvent|Mojo|Mojolicious)$/)
189             {
190 0           $self->zilla->register_prereqs({
191             type => 'recommends',
192             phase => $phase,
193             }, EV => 0);
194             }
195             }
196             }
197             }
198              
199 0 0         if(my($perlcritic_file) = grep { $_->name eq 'perlcriticrc' } $self->zilla->files->@*)
  0            
200             {
201 0           foreach my $policy (grep { $_ ne '_' } sort keys Config::INI::Reader->read_string($perlcritic_file->content)->%*)
  0            
202             {
203 0 0         next if $policy =~ /^-/;
204 0           $self->zilla->register_prereqs({
205             type => 'recommends',
206             phase => 'develop',
207             }, "Perl::Critic::Policy::$policy" => 0);
208             }
209             }
210              
211 0           foreach my $pairs (Dist::Zilla::Util::AuthorDeps::extract_author_deps('.',0)->@*)
212             {
213 0           foreach my $module (sort keys $pairs->%*)
214             {
215 0           my $version = $pairs->{$module};
216 0           $self->zilla->register_prereqs({
217             type => 'recommends',
218             phase => 'develop',
219             }, $module => $version);
220             }
221             }
222              
223             }
224              
225             sub before_release
226             {
227 0     0 0   my $self = shift;
228              
229 0 0         if($self->win32)
230             {
231 0 0         if($^O ne 'MSWin32')
232             {
233 0           $self->log_fatal("This dist must be released on MSWin32");
234             }
235             }
236             else
237             {
238 0 0         if($^O eq 'MSWin32')
239             {
240 0           $self->log_fatal("This dist is not releasable on MSWin32");
241             }
242             }
243              
244 0 0         unless(Dist::Zilla::Plugin::Author::Plicease->git)
245             {
246 0           $self->log_fatal("release requires git and Dist::Zilla::Plugin::Git to be installed");
247             }
248              
249 0           $self->log("Okay to release this dist on $^O");
250             }
251              
252             sub setup_installer
253             {
254 0     0 0   my($self) = @_;
255              
256 0           my $prereqs = $self->zilla->prereqs->as_string_hash;
257              
258 0           my $perl_version = $prereqs->{runtime}->{requires}->{perl};
259              
260 0           $self->log("perl version required = $perl_version");
261              
262 0           foreach my $file (grep { $_->name =~ /^(Makefile\.PL|Build\.PL)$/ } $self->zilla->files->@*)
  0            
263             {
264 0           my $content = $file->content;
265             $content = join "\n",
266             "BEGIN {",
267             " use strict; use warnings;",
268 0           (map { s/^\| / /r } $self->preamble->@*),
  0            
269             " unless(eval q{ use $perl_version; 1}) {",
270             " print \"Perl $perl_version or better required\\n\";",
271             " exit;",
272             " }",
273             "}",
274             $content;
275 0           $file->content($content);
276             }
277             }
278              
279             __PACKAGE__->meta->make_immutable;
280             }
281              
282             1;
283              
284             __END__
285              
286             =pod
287              
288             =encoding UTF-8
289              
290             =head1 NAME
291              
292             Dist::Zilla::Plugin::Author::Plicease::SpecialPrereqs - Special prereq handling
293              
294             =head1 VERSION
295              
296             version 2.73
297              
298             =head1 SYNOPSIS
299              
300             [Author::Plicease::SpecialPrereqs]
301              
302             =head1 DESCRIPTION
303              
304             Some older versions of modules have problematic for various
305             reasons (at least in the context of how I use them). This
306             plugin will upgrade those prereqs to appropriate version
307             if they are C<0>, meaning any version.
308              
309             Some modules are recommended if certain modules are already
310             prerequisites. For example, XS modules may be recommended if
311             otherwise pure perl modules will optionally use them.
312              
313             This plugin also enforces that releases are done on MSWin32
314             for pure-C<Win32::> type modules and on a Unixy platform
315             if they are not.
316              
317             This plugin also adds a preface to your C<Makefile.PL> or C<Build.PL> to
318             test the Perl version in a way that will not throw an exception,
319             instead calling exit, so that they will not be reported on
320             cpantesters as failures. This plugin should be the last
321             L<Dist::Zilla::Role::InstallTool> plugin in your C<dist.ini>.
322              
323             =over 4
324              
325             =item Moo
326              
327             Require 2.x as this fixes the bug where fatal warnings was
328             enabled.
329              
330             =item PerlX::Maybe
331              
332             Require 0.003
333              
334             =item AnyEvent::Open3::Simple
335              
336             Require 0.76 for new stdin style
337             Require 0.83 for deprecation removals
338              
339             =item Path::Class
340              
341             Require 0.26 for spew
342              
343             =item Mojolicious
344              
345             Require 4.31
346              
347             =item Role::Tiny
348              
349             Require 1.003001. See rt#83248
350              
351             =item JSON::XS
352              
353             Recommended if JSON is required.
354              
355             =item PerlX::Maybe::XS
356              
357             Recommended if PerlX::Maybe is required.
358              
359             =item EV
360              
361             Recommended if Mojolicious or AnyEvent modules are required.
362              
363             =item Test::Exit
364              
365             Require 0.11 for dealing with C<exit> inside and C<eval>.
366              
367             =back
368              
369             =head1 OPTIONS
370              
371             =head2 preamble
372              
373             ...
374              
375             =head2 upgrade
376              
377             Upgrade additional prereqs. This takes a key=value pair, so something like
378              
379             [Author::Plicease::SpecialPrereqs]
380             upgrade = Foo::Bar = 0.02
381              
382             =head2 win32
383              
384             If set to true, then the dist MUST be released on MSWin32. This is
385             useful for C<Win32::> type dists that aren't testable on Unixy platforms.
386              
387             If set to false, then the dist MUST NOT be released on MSWin32. This
388             is a personal preference; I prefer not to release on non-Unixy platforms.
389              
390             =head1 SEE ALSO
391              
392             =over 4
393              
394             =item L<Dist::Zilla>
395              
396             =item L<Dist::Zilla::PluginBundle::Author::Plicease>
397              
398             =back
399              
400             =head1 AUTHOR
401              
402             Graham Ollis <plicease@cpan.org>
403              
404             =head1 COPYRIGHT AND LICENSE
405              
406             This software is copyright (c) 2012-2022 by Graham Ollis.
407              
408             This is free software; you can redistribute it and/or modify it under
409             the same terms as the Perl 5 programming language system itself.
410              
411             =cut