File Coverage

blib/lib/Dist/Zilla/Plugin/ModuleInstall.pm
Criterion Covered Total %
statement 93 100 93.0
branch 7 12 58.3
condition 1 2 50.0
subroutine 22 22 100.0
pod 2 2 100.0
total 125 138 90.5


line stmt bran cond sub pod time code
1 2     2   2220466 use 5.006; # our
  2         6  
2 2     2   11 use strict;
  2         3  
  2         47  
3 2     2   9 use warnings;
  2         11  
  2         143  
4              
5             package Dist::Zilla::Plugin::ModuleInstall;
6              
7             our $VERSION = '1.001002';
8              
9             # ABSTRACT: (DEPRECATED) Build Module::Install based Distributions with Dist::Zilla
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   681 use Moose qw( has with around );
  2         396605  
  2         15  
14 2     2   7695 use Config;
  2         3  
  2         75  
15 2     2   7 use Carp qw( carp croak );
  2         3  
  2         137  
16 2     2   1052 use Dist::Zilla::Plugin::MakeMaker::Runner;
  2         133624  
  2         122  
17 2     2   1347 use Dist::Zilla::File::FromCode;
  2         416472  
  2         247  
18              
19             has 'make_path' => (
20             isa => 'Str',
21             is => 'ro',
22             default => $Config{make} || 'make',
23             );
24              
25             has '_runner' => (
26             is => 'ro',
27             lazy => 1,
28             handles => [qw(build test)],
29             default => sub {
30             my ($self) = @_;
31             Dist::Zilla::Plugin::MakeMaker::Runner->new(
32             {
33             zilla => $self->zilla,
34             plugin_name => $self->plugin_name . '::Runner',
35             make_path => $self->make_path,
36             },
37             );
38             },
39             );
40              
41             with 'Dist::Zilla::Role::BuildRunner';
42             with 'Dist::Zilla::Role::InstallTool';
43             with 'Dist::Zilla::Role::TextTemplate';
44              
45             # no broken tempdir, keepalive_fail helper
46 2     2   994 use Dist::Zilla::Role::Tempdir 1.001000;
  2         457236  
  2         418  
47             with 'Dist::Zilla::Role::Tempdir';
48              
49             with 'Dist::Zilla::Role::PrereqSource';
50             with 'Dist::Zilla::Role::TestRunner';
51              
52             around dump_config => sub {
53             my ( $orig, $self, @args ) = @_;
54             my $config = $self->$orig(@args);
55             my $payload = $config->{ +__PACKAGE__ } = {};
56             $payload->{make_path} = $self->make_path;
57              
58             ## no critic (RequireInterpolationOfMetachars)
59             $payload->{ q[$] . __PACKAGE__ . q[::VERSION] } = $VERSION unless __PACKAGE__ eq ref $self;
60             $payload->{q[$Module::Install::VERSION]} = $Module::Install::VERSION if $INC{'Module/Install.pm'};
61             return $config;
62             };
63              
64             __PACKAGE__->meta->make_immutable;
65 2     2   19 no Moose;
  2         4  
  2         12  
66              
67 2     2   214 use Dist::Zilla::File::InMemory;
  2         4  
  2         53  
68              
69 2     2   8 use namespace::autoclean;
  2         4  
  2         9  
70              
71             require inc::Module::Install;
72              
73             sub _doc_template {
74 3     3   9 my ( $self, $args ) = @_;
75 3         6 my $package = __PACKAGE__;
76 3   50     53 my $version = ( __PACKAGE__->VERSION() || 'undefined ( self-build? )' );
77              
78 3         18 my $t = <<"EOF";
79             use strict;
80             use warnings;
81             use lib './'; # Required for -Ddefault_inc_excludes_dot
82             # Warning: This code was generated by ${package} Version ${version}
83             # As part of Dist::Zilla's build generation.
84             # Do not modify this file, instead, modify the dist.ini that configures its generation.
85             use inc::Module::Install {{ \$miver }};
86             {{ \$headings }}
87             {{ \$requires }}
88             {{ \$feet }}
89             WriteAll();
90             EOF
91 3         12 return $self->fill_in_string( $t, $args );
92             }
93              
94             sub _label_value_template {
95 3     3   122 my ( $self, $args ) = @_;
96 3         7 my $t = <<"EOF";
97             {{ \$label }} '{{ \$value }}';
98             EOF
99 3         16 return $self->fill_in_string( $t, $args );
100             }
101              
102             sub _label_string_template {
103 12     12   9158 my ( $self, $args ) = @_;
104 12         18 my $t = <<"EOF";
105             {{ \$label }} "{{ quotemeta( \$string ) }}";
106             EOF
107 12         40 return $self->fill_in_string( $t, $args );
108             }
109              
110             sub _label_string_string_template {
111 6     6   11 my ( $self, $args ) = @_;
112 6         9 my $t = <<"EOF";
113             {{ \$label }} "{{ quotemeta(\$stringa) }}" => "{{ quotemeta(\$stringb) }}";
114             EOF
115 6         22 return $self->fill_in_string( $t, $args );
116             }
117              
118             sub _generate_makefile_pl {
119 3     3   7 my ($self) = @_;
120 3         4 my ( @headings, @requires, @feet );
121              
122 3         100 push @headings, _label_value_template( $self, { label => 'name', value => $self->zilla->name } ),
123             _label_string_template( $self, { label => 'abstract', string => $self->zilla->abstract } ),
124             _label_string_template( $self, { label => 'author', string => $self->zilla->authors->[0] } ),
125             _label_string_template( $self, { label => 'version', string => $self->zilla->version } ),
126             _label_string_template( $self, { label => 'license', string => $self->zilla->license->meta_yml_name } );
127              
128 3         1936 my $prereqs = $self->zilla->prereqs;
129              
130             my $doreq = sub {
131 15     15   31 my ( $key, $target ) = @_;
132 15         60 push @requires, qq{\n# @$key => $target};
133 15         17 my $hash = $prereqs->requirements_for( @{$key} )->as_string_hash;
  15         66  
134 15         1733 for ( sort keys %{$hash} ) {
  15         56  
135 6 50       20 if ( 'perl' eq $_ ) {
136 0         0 push @requires, _label_string_template( $self, { label => 'perl_version', string => $hash->{$_} } );
137 0         0 next;
138             }
139             push @requires,
140             $self->_label_string_string_template(
141             {
142             label => $target,
143             stringa => $_,
144 6         40 stringb => $hash->{$_},
145             },
146             );
147             }
148 3         157 };
149              
150 3         15 $doreq->( [qw(configure requires)], 'configure_requires' );
151 3         2168 $doreq->( [qw(build requires)], 'requires' );
152 3         2185 $doreq->( [qw(runtime requires)], 'requires' );
153 3         15 $doreq->( [qw(runtime recommends)], 'recommends' );
154 3         15 $doreq->( [qw(test requires)], 'test_requires' );
155              
156 3         8 push @feet, qq{\n# :ExecFiles};
157 3         5 my @found_files = @{ $self->zilla->find_files(':ExecFiles') };
  3         125  
158 3         2861 for my $execfile ( map { $_->name } @found_files ) {
  0         0  
159 0         0 push @feet, _label_string_template( $self, $execfile );
160             }
161 3         43 my $content = _doc_template(
162             $self,
163             {
164             miver => "$Module::Install::VERSION",
165             headings => join( qq{\n}, @headings ),
166             requires => join( qq{\n}, @requires ),
167             feet => join( qq{\n}, @feet ),
168             },
169             );
170 3         2996 return $content;
171             }
172              
173              
174              
175              
176              
177              
178              
179             sub register_prereqs {
180 1     1 1 56355 my ($self) = @_;
181 1         30 $self->zilla->register_prereqs( { phase => 'configure' }, 'ExtUtils::MakeMaker' => 6.42 );
182 1         516 $self->zilla->register_prereqs( { phase => 'build' }, 'ExtUtils::MakeMaker' => 6.42 );
183 1         157 return;
184             }
185              
186              
187              
188              
189              
190              
191              
192              
193             my $error_load = 'Error running Makefile.PL for Module::Install. ';
194             my $no_keepalive = $error_load . 'Set MI_KEEPALIVE=1 if you want to retain the directory for analysis';
195             my $keepalive = $error_load . 'Inspect the temporary directory to determine cause';
196              
197             sub setup_installer {
198 1     1 1 30875 my ( $self, ) = @_;
199              
200 1     3   41 my $file = Dist::Zilla::File::FromCode->new( { name => 'Makefile.PL', code => sub { _generate_makefile_pl($self) }, } );
  3         11551  
201              
202 1         184 $self->add_file($file);
203              
204             my $code = sub {
205 1     1   575 my ($dir) = @_;
206 1 50       329895 system $^X, 'Makefile.PL' and do {
207              
208 0 0       0 croak($no_keepalive) unless $ENV{MI_KEEPALIVE};
209              
210 0         0 $dir->keepalive_fail($keepalive);
211             };
212 1         658 };
213              
214 1         7 my (@generated) = $self->capture_tempdir($code);
215              
216 1         32686 for (@generated) {
217 14 100       603 if ( $_->is_new ) {
218 12         544 $self->log( 'ModuleInstall created: ' . $_->name );
219 12 100       4803 if ( $_->name =~ /\Ainc\/Module\/Install/msx ) {
220 8         809 $self->log( 'ModuleInstall added : ' . $_->name );
221 8         3168 $self->add_file( $_->file );
222             }
223             }
224 14 50       5708 if ( $_->is_modified ) {
225 0         0 $self->log( 'ModuleInstall modified: ' . $_->name );
226             }
227             }
228 1         86 return;
229             }
230              
231             1;
232              
233             __END__
234              
235             =pod
236              
237             =encoding UTF-8
238              
239             =head1 NAME
240              
241             Dist::Zilla::Plugin::ModuleInstall - (DEPRECATED) Build Module::Install based Distributions with Dist::Zilla
242              
243             =head1 VERSION
244              
245             version 1.001002
246              
247             =head1 SYNOPSIS
248              
249             dist.ini
250              
251             [ModuleInstall]
252              
253             =head1 DESCRIPTION
254              
255             This module will create a F<Makefile.PL> for installing the dist using L<< C<Module::Install>|Module::Install >>.
256              
257             It is at present a very minimal feature set, but it works.
258              
259             =head1 METHODS
260              
261             =head2 register_prereqs
262              
263             Tells Dist::Zilla about our needs to have EU::MM larger than 6.42
264              
265             =head2 setup_installer
266              
267             Generates the Makefile.PL, and runs it in a tmpdir, and then harvests the output and stores
268             it in the dist selectively.
269              
270             =head1 DEPRECATED
271              
272             This module is now officially deprecated.
273              
274             It was never really recommended, or supported, and it always existed as a gap filler for people
275             who were migrating from Module::Install and had yet to understand certain design elements of C<Dist::Zilla>
276             made using Module::Install effectively redundant.
277              
278             In short, it was an excuse, a foot-gun for the person who needed holes in their feet.
279              
280             I will not actively prevent this module from doing anything it didn't use to do, but its use
281             should be considered officially discouraged.
282              
283             =head1 AUTHOR
284              
285             Kent Fredric <kentnl@cpan.org>
286              
287             =head1 COPYRIGHT AND LICENSE
288              
289             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
290              
291             This is free software; you can redistribute it and/or modify it under
292             the same terms as the Perl 5 programming language system itself.
293              
294             =cut