File Coverage

blib/lib/Dist/Zilla/Plugin/MakeMaker/Fallback.pm
Criterion Covered Total %
statement 43 45 95.5
branch 7 8 87.5
condition 4 6 66.6
subroutine 10 11 90.9
pod 0 3 0.0
total 64 73 87.6


line stmt bran cond sub pod time code
1 5     5   12709212 use strict;
  5         13  
  5         169  
2 5     5   26 use warnings;
  5         12  
  5         319  
3             # vim: set ts=8 sts=2 sw=2 tw=115 et :
4             # ABSTRACT: Generate a Makefile.PL containing a warning for legacy users
5             # KEYWORDS: plugin installer MakeMaker Makefile.PL toolchain legacy ancient backcompat
6              
7             our $VERSION = '0.031';
8              
9             use Moose;
10 5     5   29 extends 'Dist::Zilla::Plugin::MakeMaker::Awesome' => { -version => '0.47' };
  5         10  
  5         43  
11             with 'Dist::Zilla::Role::AfterBuild' => { -excludes => [qw(dump_config mvp_multivalue_args mvp_aliases)] };
12              
13             use List::Keywords 0.03 qw(first any);
14 5     5   31028 use version;
  5         8316  
  5         21  
15 5     5   263 use Path::Tiny;
  5         12  
  5         34  
16 5     5   331 use namespace::autoclean;
  5         11  
  5         217  
17 5     5   26  
  5         9  
  5         60  
18             has skip_release_testing => (
19             is => 'ro',
20             isa => 'Bool',
21             );
22              
23             around dump_config => sub
24             {
25             my ($orig, $self) = @_;
26             my $config = $self->$orig;
27              
28             my $data = {
29             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
30             skip_release_testing => ($self->skip_release_testing ? 1 : 0),
31             };
32             $config->{+__PACKAGE__} = $data if keys %$data;
33              
34             return $config;
35             };
36              
37             {
38             my $self = shift;
39              
40 10     10 0 161737 # if Makefile.PL is missing, someone removed it (probably a bad thing)
41             my $makefile_pl = first { $_->name eq 'Makefile.PL' } @{ $self->zilla->files };
42             $self->log_fatal('No Makefile.PL found -- did you remove it!?') if not $makefile_pl;
43 10         23  
  24         918  
  10         311  
44 10 50       473 my $build_pl = first { $_->name eq 'Build.PL' } @{ $self->zilla->files };
45             $self->log_fatal('No Build.PL found to fall back from!') if not $build_pl;
46 10         26  
  29         963  
  10         278  
47 10 100       398 $self->log('share/ files present: did you forget to include [ShareDir]?')
48             if any { path('share')->subsumes($_->name) } @{ $self->zilla->files }
49             and not @{ $self->zilla->plugins_with(-ShareDir) };
50 28         3172 }
  9         213  
51 9 100 66     25  
  1         137  
52             around _build_WriteMakefile_args => sub
53             {
54             my $orig = shift;
55             my $self = shift;
56             my $WriteMakefile_args = $self->$orig(@_);
57              
58             return +{
59             PL_FILES => {}, # to avoid Build.PL from slipping in on EUMM < 6.25
60             %$WriteMakefile_args,
61             };
62             };
63              
64             {
65             # this module file gets passed through a template itself at build time, so
66             # we need to escape these template markers so they survive
67              
68             my $code = <<"CODE"
69             BEGIN {
70             my %configure_requires = (
71 10     10   783 \x7b\x7b # look, it's a template inside a template!
72             CODE
73             . <<'CODE'
74             my $configure_requires = $dist->prereqs->as_string_hash->{configure}{requires};
75             delete $configure_requires->{perl};
76              
77             # prereq specifications don't always provide exact versions - we just weed
78             # those out for now, as this shouldn't occur that frequently. There is no
79             # point in using CPAN::Meta, as that wasn't in core in the range of perl
80             # versions that is likely to not have satisfied these prereqs.
81             delete @{$configure_requires}{ grep !version::is_strict($configure_requires->{$_}), keys %$configure_requires };
82             join('', map
83             " '$_' => '$configure_requires->{$_}',\n",
84             sort keys %$configure_requires)
85             CODE
86             . "\x7d\x7d);\n" . <<'CODE'
87              
88             my %errors = map {
89             eval "require $_; $_->VERSION($configure_requires{$_}); 1";
90             $_ => $@,
91             } keys %configure_requires;
92              
93             if (grep $_, values %errors)
94             {
95             warn "Errors from configure prereqs:\n"
96             . do {
97             require Data::Dumper; Data::Dumper->new([ \%errors ])->Indent(2)->Terse(1)->Sortkeys(1)->Dump;
98             };
99             }
100              
101             if (not $ENV{PERL_MM_FALLBACK_SILENCE_WARNING})
102             {
103             warn <<'EOW';
104             CODE
105             . join('', <DATA>)
106             . <<'CODE';
107             EOW
108             sleep 10 if -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT));
109             }
110             } # end BEGIN
111             CODE
112             }
113              
114             around _build_MakeFile_PL_template => sub
115             {
116             my $orig = shift;
117             my $self = shift;
118              
119             my $string = $self->$orig(@_);
120              
121             # strip out the hard VERSION requirement - be gentle to users that failed
122             # to satisfy configure_requires
123             $string =~ s/^use ExtUtils::MakeMaker\K[^;]+;$/;/m;
124              
125             # splice in our stuff after the preamble bits
126             $self->log_fatal('failed to find position in Makefile.PL to munge!')
127             if $string !~ m/\{\{ \$header \}\}\n/g;
128              
129             return substr($string, 0, pos($string)) . $self->__preamble . substr($string, pos($string));
130             };
131              
132             my $self = shift;
133             $self->log_debug('doing nothing during build...');
134             }
135              
136 0     0 0 0 {
137 0         0 my $self = shift;
138              
139             if ($ENV{RELEASE_TESTING} and not $self->skip_release_testing)
140             {
141             # we are either performing a 'dzil test' with RELEASE_TESTING set, or
142 2     2 0 2867 # a 'dzil release' -- the Build.PL plugin will run tests with extra
143             # variables set, so as an extra check, we will perform them without.
144 2 100 66     84  
145             local $ENV{RELEASE_TESTING};
146             local $ENV{AUTHOR_TESTING};
147             local $ENV{PERL_MM_FALLBACK_SILENCE_WARNING} = 1;
148             $self->log_debug('performing test with RELEASE_TESTING, AUTHOR_TESTING unset');
149             return $self->next::method(@_);
150 1         15 }
151 1         11 else
152 1         12 {
153 1         8 $self->log_debug('doing nothing during test...');
154 1         339 }
155             }
156              
157             __PACKAGE__->meta->make_immutable;
158 1         11  
159             #pod =pod
160             #pod
161             #pod =for Pod::Coverage after_build build test
162             #pod
163             #pod =head1 SYNOPSIS
164             #pod
165             #pod In your F<dist.ini>, when you want to ship a F<Build.PL> as well as a fallback
166             #pod F<Makefile.PL> in case the user's C<cpan> client is so old it doesn't recognize
167             #pod C<configure_requires>:
168             #pod
169             #pod [ModuleBuildTiny]
170             #pod [MakeMaker::Fallback]
171             #pod
172             #pod =head1 DESCRIPTION
173             #pod
174             #pod This plugin is a derivative of C<[MakeMaker]>, generating a F<Makefile.PL> in
175             #pod your distribution, with an added preamble that is printed when it is run:
176             #pod
177             #pod =for stopwords cpanminus mb
178             #pod
179             #pod =for comment This section was inserted from the DATA section at build time
180             #pod
181             #pod =begin :verbatim
182             #pod
183             #pod *** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***
184             #pod
185             #pod If you're seeing this warning, your toolchain is really, really old* and
186             #pod you'll almost certainly have problems installing CPAN modules from this
187             #pod century. But never fear, dear user, for we have the technology to fix this!
188             #pod
189             #pod If you're using CPAN.pm to install things, then you can upgrade it using:
190             #pod
191             #pod cpan CPAN
192             #pod
193             #pod If you're using CPANPLUS to install things, then you can upgrade it using:
194             #pod
195             #pod cpanp CPANPLUS
196             #pod
197             #pod If you're using cpanminus, you shouldn't be seeing this message in the first
198             #pod place, so please file an issue on github.
199             #pod
200             #pod If you're using a packaging tool through a unix distribution, this issue
201             #pod should be reported to the package manager.
202             #pod
203             #pod If you're installing manually, please retrain your fingers to run Build.PL
204             #pod when present instead of Makefile.PL.
205             #pod
206             #pod This public service announcement was brought to you by the Perl Toolchain
207             #pod Gang, the irc.perl.org #toolchain IRC channel, and the number 42.
208             #pod
209             #pod ----
210             #pod
211             #pod * Alternatively, you are doing something overly clever, in which case you
212             #pod should consider setting the 'prefer_installer' config option in CPAN.pm, or
213             #pod 'prefer_makefile' in CPANPLUS, to 'mb" and '0' respectively.
214             #pod
215             #pod You can also silence this warning for future installations by setting the
216             #pod PERL_MM_FALLBACK_SILENCE_WARNING environment variable.
217             #pod
218             #pod
219             #pod =end :verbatim
220             #pod
221             #pod =for stopwords ModuleBuildTiny
222             #pod
223             #pod Additionally, any errors resulting from loading configure-require prerequisites are captured and printed, which
224             #pod indicates a failure of the user or the tools to read and understand F<META.yml> or F<META.json>.
225             #pod
226             #pod It is a fatal error to use this plugin when there is not also another
227             #pod plugin enabled that generates a F<Build.PL> (such as
228             #pod L<[ModuleBuildTiny]|Dist::Zilla::Plugin::ModuleBuildTiny>).
229             #pod
230             #pod On top of the regular testing that is provided via the F<Build.PL>-producing
231             #pod plugin, C<dzil test --release> or C<dzil release> will run tests with extra
232             #pod testing variables B<unset> (C<AUTHOR_TESTING>, C<RELEASE_TESTING>). This is to
233             #pod weed out test issues that only manifest under these conditions (for example:
234             #pod bad test count, conditional module loading).
235             #pod You can prevent this extra testing from happening by setting C<skip_release_testing = 1>
236             #pod in your configuration or F<dist.ini>.
237             #pod
238             #pod =head1 ACKNOWLEDGEMENTS
239             #pod
240             #pod =for stopwords Peter Rabbitson ribasushi Matt Trout mst
241             #pod
242             #pod Peter Rabbitson (ribasushi), whose concerns that low-level utility modules
243             #pod were shipping with install tools that did not work out of the box with perls
244             #pod 5.6 and 5.8 inspired the creation of this module.
245             #pod
246             #pod Matt Trout (mst), for realizing a simple warning would be sufficient, rather
247             #pod than a complicated detection heuristic, as well as the text of the warning
248             #pod (but it turns out that we still need a I<simple> detection heuristic, so -0.5
249             #pod for that...)
250             #pod
251             #pod =head1 SEE ALSO
252             #pod
253             #pod =for :list
254             #pod * L<Dist::Zilla::Plugin::MakeMaker>
255             #pod * L<Dist::Zilla::Plugin::ModuleBuildTiny>
256             #pod * L<Dist::Zilla::Plugin::ModuleBuildTiny::Fallback>
257             #pod
258             #pod =cut
259              
260             =pod
261              
262             =encoding UTF-8
263              
264             =head1 NAME
265              
266             Dist::Zilla::Plugin::MakeMaker::Fallback - Generate a Makefile.PL containing a warning for legacy users
267              
268             =head1 VERSION
269              
270             version 0.031
271              
272             =head1 SYNOPSIS
273              
274             In your F<dist.ini>, when you want to ship a F<Build.PL> as well as a fallback
275             F<Makefile.PL> in case the user's C<cpan> client is so old it doesn't recognize
276             C<configure_requires>:
277              
278             [ModuleBuildTiny]
279             [MakeMaker::Fallback]
280              
281             =head1 DESCRIPTION
282              
283             This plugin is a derivative of C<[MakeMaker]>, generating a F<Makefile.PL> in
284             your distribution, with an added preamble that is printed when it is run:
285              
286             =for Pod::Coverage after_build build test
287              
288             =for stopwords cpanminus mb
289              
290             =for comment This section was inserted from the DATA section at build time
291              
292             *** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***
293              
294             If you're seeing this warning, your toolchain is really, really old* and
295             you'll almost certainly have problems installing CPAN modules from this
296             century. But never fear, dear user, for we have the technology to fix this!
297              
298             If you're using CPAN.pm to install things, then you can upgrade it using:
299              
300             cpan CPAN
301              
302             If you're using CPANPLUS to install things, then you can upgrade it using:
303              
304             cpanp CPANPLUS
305              
306             If you're using cpanminus, you shouldn't be seeing this message in the first
307             place, so please file an issue on github.
308              
309             If you're using a packaging tool through a unix distribution, this issue
310             should be reported to the package manager.
311              
312             If you're installing manually, please retrain your fingers to run Build.PL
313             when present instead of Makefile.PL.
314              
315             This public service announcement was brought to you by the Perl Toolchain
316             Gang, the irc.perl.org #toolchain IRC channel, and the number 42.
317              
318             ----
319              
320             * Alternatively, you are doing something overly clever, in which case you
321             should consider setting the 'prefer_installer' config option in CPAN.pm, or
322             'prefer_makefile' in CPANPLUS, to 'mb" and '0' respectively.
323              
324             You can also silence this warning for future installations by setting the
325             PERL_MM_FALLBACK_SILENCE_WARNING environment variable.
326              
327             =for stopwords ModuleBuildTiny
328              
329             Additionally, any errors resulting from loading configure-require prerequisites are captured and printed, which
330             indicates a failure of the user or the tools to read and understand F<META.yml> or F<META.json>.
331              
332             It is a fatal error to use this plugin when there is not also another
333             plugin enabled that generates a F<Build.PL> (such as
334             L<[ModuleBuildTiny]|Dist::Zilla::Plugin::ModuleBuildTiny>).
335              
336             On top of the regular testing that is provided via the F<Build.PL>-producing
337             plugin, C<dzil test --release> or C<dzil release> will run tests with extra
338             testing variables B<unset> (C<AUTHOR_TESTING>, C<RELEASE_TESTING>). This is to
339             weed out test issues that only manifest under these conditions (for example:
340             bad test count, conditional module loading).
341             You can prevent this extra testing from happening by setting C<skip_release_testing = 1>
342             in your configuration or F<dist.ini>.
343              
344             =head1 ACKNOWLEDGEMENTS
345              
346             =for stopwords Peter Rabbitson ribasushi Matt Trout mst
347              
348             Peter Rabbitson (ribasushi), whose concerns that low-level utility modules
349             were shipping with install tools that did not work out of the box with perls
350             5.6 and 5.8 inspired the creation of this module.
351              
352             Matt Trout (mst), for realizing a simple warning would be sufficient, rather
353             than a complicated detection heuristic, as well as the text of the warning
354             (but it turns out that we still need a I<simple> detection heuristic, so -0.5
355             for that...)
356              
357             =head1 SEE ALSO
358              
359             =over 4
360              
361             =item *
362              
363             L<Dist::Zilla::Plugin::MakeMaker>
364              
365             =item *
366              
367             L<Dist::Zilla::Plugin::ModuleBuildTiny>
368              
369             =item *
370              
371             L<Dist::Zilla::Plugin::ModuleBuildTiny::Fallback>
372              
373             =back
374              
375             =head1 SUPPORT
376              
377             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-MakeMaker-Fallback>
378             (or L<bug-Dist-Zilla-Plugin-MakeMaker-Fallback@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-MakeMaker-Fallback@rt.cpan.org>).
379              
380             There is also a mailing list available for users of this distribution, at
381             L<http://dzil.org/#mailing-list>.
382              
383             There is also an irc channel available for users of this distribution, at
384             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
385              
386             I am also usually active on irc, as 'ether' at C<irc.perl.org> and C<irc.libera.chat>.
387              
388             =head1 AUTHOR
389              
390             Karen Etheridge <ether@cpan.org>
391              
392             =head1 COPYRIGHT AND LICENCE
393              
394             This software is copyright (c) 2013 by Karen Etheridge.
395              
396             This is free software; you can redistribute it and/or modify it under
397             the same terms as the Perl 5 programming language system itself.
398              
399             =cut
400              
401             *** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***
402              
403             If you're seeing this warning, your toolchain is really, really old* and
404             you'll almost certainly have problems installing CPAN modules from this
405             century. But never fear, dear user, for we have the technology to fix this!
406              
407             If you're using CPAN.pm to install things, then you can upgrade it using:
408              
409             cpan CPAN
410              
411             If you're using CPANPLUS to install things, then you can upgrade it using:
412              
413             cpanp CPANPLUS
414              
415             If you're using cpanminus, you shouldn't be seeing this message in the first
416             place, so please file an issue on github.
417              
418             If you're using a packaging tool through a unix distribution, this issue
419             should be reported to the package manager.
420              
421             If you're installing manually, please retrain your fingers to run Build.PL
422             when present instead of Makefile.PL.
423              
424             This public service announcement was brought to you by the Perl Toolchain
425             Gang, the irc.perl.org #toolchain IRC channel, and the number 42.
426              
427             ----
428              
429             * Alternatively, you are doing something overly clever, in which case you
430             should consider setting the 'prefer_installer' config option in CPAN.pm, or
431             'prefer_makefile' in CPANPLUS, to 'mb" and '0' respectively.
432              
433             You can also silence this warning for future installations by setting the
434             PERL_MM_FALLBACK_SILENCE_WARNING environment variable.