File Coverage

blib/lib/Dist/Zilla/Plugin/Author/Plicease/MakeMaker.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 2 100.0
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 37 39 94.8


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::Plicease::MakeMaker 2.74 {
2              
3 2     2   3214010 use 5.020;
  2         10  
4 2     2   16 use Moose;
  2         6  
  2         20  
5 2     2   14168 use namespace::autoclean;
  2         5  
  2         45  
6 2     2   2624 use Perl::Tidy ();
  2         690655  
  2         83  
7 2     2   443 use Dist::Zilla::Plugin::Author::Plicease ();
  2         5  
  2         81  
8 2     2   14 use List::Util qw( first );
  2         4  
  2         164  
9 2     2   13 use experimental qw( postderef );
  2         6  
  2         20  
10              
11             # ABSTRACT: munge the AUTHOR section
12              
13              
14             extends 'Dist::Zilla::Plugin::MakeMaker';
15              
16             with 'Dist::Zilla::Role::MetaProvider';
17              
18             around write_makefile_args => sub {
19             my($orig, $self, @args) = @_;
20             my $h = $self->$orig(@args);
21              
22             # to prevent any non .pm/.pod files from being installed in lib
23             # because shit like this is stuff we ought to have to customize.
24             my %PM = map {; "lib/$_" => "\$(INST_LIB)/$_" }
25             map { s/^lib\///r }
26             grep /^lib\/.*\.p(od|m)$/,
27             map { $_->name }
28             $self->zilla->files->@*;
29             $h->{PM} = \%PM;
30              
31             $h;
32             };
33              
34             around setup_installer => sub {
35             my($orig, $self, @args) = @_;
36              
37             $self->$orig(@args);
38              
39             my $file = first { $_->name eq 'Makefile.PL' } $self->zilla->files->@*;
40             my $mod = first { $_->name eq 'inc/mymm.pl' } $self->zilla->files->@*;
41             my $config = first { $_->name eq 'inc/mymm-config.pl' } $self->zilla->files->@*;
42             my $build = first { $_->name eq 'inc/mymm-build.pl' } $self->zilla->files->@*;
43             my $test = first { $_->name eq 'inc/mymm-test.pl' } $self->zilla->files->@*;
44             my $clean = first { $_->name eq 'inc/mymm-clean.pl' } $self->zilla->files->@*;
45              
46             my @content = do {
47             my $in = $file->content;
48             my $out = '';
49             my $err = '';
50             local @ARGV = ();
51             my $error = Perl::Tidy::perltidy(
52             source => \$in,
53             destination => \$out,
54             stderr => \$err,
55             perltidyrc => Dist::Zilla::Plugin::Author::Plicease->dist_dir->child('perltidyrc')->stringify,
56             );
57             $self->log("perltidy: $_") for split /\n/, $err;
58             $self->log_fatal("perltidy failed!") if $error;
59             split /\n/, $out;
60             };
61              
62             # pet-peve1: remove blank lines between use
63             {
64             my $i = 0;
65             while($i<$#content)
66             {
67             if($content[$i] =~ /^(use|#)/)
68             { $i++ }
69             elsif($content[$i] =~ /^\s*$/)
70             { @content = @content[0..($i-1),($i+1)..$#content] }
71             else
72             {
73             my @extra = ('');
74              
75             if($mod)
76             {
77             unshift @extra, 'require "./inc/mymm.pl";';
78             }
79              
80             @content = (
81             @content[0..($i-1)],
82             @extra,
83             @content[($i)..$#content]
84             );
85             last;
86             }
87             }
88             }
89              
90             # pet-peve2: squeeze multiple blank lines
91             {
92             my @new;
93             my $last_empty = 0;
94             foreach my $line (@content)
95             {
96             if($line =~ /^\s*$/)
97             {
98             if($last_empty)
99             { next }
100             else
101             {
102             $last_empty = 1;
103             }
104             }
105             else
106             {
107             $last_empty = 0;
108             }
109              
110             push @new, $line;
111             }
112             @content = @new;
113             }
114              
115             if($mod || $test)
116             {
117             my @extra;
118              
119             # This is cray-cray.
120             while(defined $content[-1] && $content[-1] !~ /^WriteMakefile\(/)
121             {
122             unshift @extra, pop @content;
123             }
124              
125             my $last = pop @content;
126              
127             if($last =~ /^WriteMakefile\(/)
128             {
129             my @new;
130             while(defined $content[0] && $content[0] !~ /\%FallbackPrereqs/)
131             {
132             my $line = shift @content;
133              
134             if($test)
135             {
136             # TODO: not exactly sure when the test order was fixed in EUMM.
137             # research and correct.
138             $line =~ s/use ExtUtils::MakeMaker;/use ExtUtils::MakeMaker 7.1001;/;
139             }
140             else
141             {
142             $line =~ s/use ExtUtils::MakeMaker;/use ExtUtils::MakeMaker 6.64;/;
143             }
144              
145             push @new, $line;
146             }
147              
148       0     eval $mod->content; ## no critic (BuiltinFunctions::ProhibitStringyEval)
149             $self->log_fatal("unable to eval inc/mymm.pl: $@") if $@;
150              
151             if(mymm->can('myWriteMakefile'))
152             {
153             $last = "mymm::my$last";
154             }
155              
156             @content = ( @new, $last, @extra );
157             }
158             else
159             {
160             $self->log_fatal("unable to find WriteMakefile in Makefile.PL");
161             }
162             }
163              
164              
165             if($config || $build || $test || $clean)
166             {
167             push @content, "{ package";
168             push @content, " MY;";
169             push @content, " sub postamble {";
170             push @content, " my \$postamble = '';";
171             push @content, '';
172             if($config)
173             {
174             push @content, " \$postamble .=";
175             push @content, " \"config :: _mm/config\\n\" .";
176             push @content, " \"mymm-config _mm/config:\\n\" .";
177             push @content, " \"\\t\\\$(FULLPERL) inc/mymm-config.pl\\n\" .";
178             push @content, " \"\\t\\\$(NOECHO)\\\$(MKPATH) _mm\\n\" .";
179             push @content, " \"\\t\\\$(NOECHO)\\\$(TOUCH) _mm/config\\n\\n\";";
180             push @content, '';
181             }
182             if($build)
183             {
184             push @content, " \$postamble .=";
185             push @content, " \"pure_all :: mymm-build\\n\" .";
186             push @content, " \"mymm-build :@{[ $config ? ' _mm/config' : '' ]}\\n\" .";
187             push @content, " \"\\t\\\$(FULLPERL) inc/mymm-build.pl\\n\\n\";";
188             push @content, '';
189             }
190             if($test)
191             {
192             push @content, " \$postamble .=";
193             push @content, " \"subdirs-test_dynamic subdirs-test_static subdirs-test :: mymm-test\\n\" .";
194             push @content, " \"mymm-test :\\n\" .";
195             push @content, " \"\\t\\\$(FULLPERL) inc/mymm-test.pl\\n\\n\";";
196             push @content, '';
197             }
198             if($clean)
199             {
200             push @content, " \$postamble .=";
201             push @content, " \"clean :: mymm-clean\\n\" .";
202             push @content, " \"mymm-clean :\\n\" .";
203             push @content, " \"\\t\\\$(FULLPERL) inc/mymm-clean.pl\\n\" .";
204             push @content, " \"\\t\\\$(RM_RF) _mm\\n\\n\";";
205             push @content, '';
206             }
207             push @content, " \$postamble;";
208             push @content, " }";
209              
210             push @content, " sub special_targets {";
211             push @content, " my(\$self, \@therest) = \@_;";
212             push @content, " my \$st = \$self->SUPER::special_targets(\@therest);";
213             push @content, " \$st .= \"\\n.PHONY:";
214             $content[-1] .= " mymm-config" if $config;
215             $content[-1] .= " mymm-build" if $build;
216             $content[-1] .= " mymm-test" if $test;
217             $content[-1] .= " mymm-clean" if $clean;
218             $content[-1] .= "\\n\";";
219             push @content, " \$st;";
220             push @content, " }";
221             push @content, "}";
222             }
223              
224             $file->content(join "\n", @content);
225              
226             return;
227             };
228              
229             around register_prereqs => sub {
230             my($orig, $self, @args) = @_;
231             my $h = $self->$orig(@args);
232              
233             my $mod = first { $_->name eq 'inc/mymm.pl' } $self->zilla->files->@*;
234             if($mod)
235             {
236             $self->zilla->register_prereqs(
237             { phase => 'configure' },
238             'ExtUtils::MakeMaker' => '6.64'
239             );
240             }
241              
242             my $test = first { $_->name eq 'inc/mymm-test.pl' } $self->zilla->files->@*;
243             if($test)
244             {
245             $self->zilla->register_prereqs(
246             { phase => 'configure' },
247             'ExtUtils::MakeMaker' => '7.1001'
248             );
249             }
250              
251             return;
252             };
253              
254             sub metadata
255             {
256 2     2 0 6908 my($self) = @_;
257              
258 2         6 my %meta;
259              
260 2     7   76 my $mod = first { $_->name eq 'inc/mymm.pl' } $self->zilla->files->@*;
  7         371  
261              
262 2 100       102 $meta{dynamic_config} = 1 if $mod;
263              
264 2         13 \%meta;
265             }
266              
267             __PACKAGE__->meta->make_immutable;
268             }
269              
270             1;
271              
272             __END__
273              
274             =pod
275              
276             =encoding UTF-8
277              
278             =head1 NAME
279              
280             Dist::Zilla::Plugin::Author::Plicease::MakeMaker - munge the AUTHOR section
281              
282             =head1 VERSION
283              
284             version 2.74
285              
286             =head1 SYNOPSIS
287              
288             [Author::Plicease::MakeMaker]
289              
290             =head1 DESCRIPTION
291              
292             My personal customization of the L<Dist::Zilla::Plugin::MakeMaker>. You are unlikely to
293             need or want to use this.
294              
295             =head1 SEE ALSO
296              
297             L<Dist::Zilla::PluginBundle::Author::Plicease>
298              
299             =head1 AUTHOR
300              
301             Graham Ollis <plicease@cpan.org>
302              
303             =head1 COPYRIGHT AND LICENSE
304              
305             This software is copyright (c) 2012-2022 by Graham Ollis.
306              
307             This is free software; you can redistribute it and/or modify it under
308             the same terms as the Perl 5 programming language system itself.
309              
310             =cut