File Coverage

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   513650 use 5.006; # our
  2         5  
2 2     2   9 use strict;
  2         3  
  2         51  
3 2     2   9 use warnings;
  2         7  
  2         115  
4              
5             package Dist::Zilla::Plugin::ModuleInstall;
6              
7             our $VERSION = '1.001001';
8              
9             # ABSTRACT: (DEPRECATED) Build Module::Install based Distributions with Dist::Zilla
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   454 use Moose qw( has with around );
  2         303612  
  2         13  
14 2     2   7810 use Config;
  2         2  
  2         74  
15 2     2   6 use Carp qw( carp croak );
  2         3  
  2         139  
16 2     2   1098 use Dist::Zilla::Plugin::MakeMaker::Runner;
  2         107797  
  2         69  
17 2     2   1137 use Dist::Zilla::File::FromCode;
  2         269959  
  2         279  
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   1241 use Dist::Zilla::Role::Tempdir 1.001000;
  2         446541  
  2         293  
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   16 no Moose;
  2         2  
  2         10  
66              
67 2     2   158 use Dist::Zilla::File::InMemory;
  2         3  
  2         42  
68              
69 2     2   7 use namespace::autoclean;
  2         1  
  2         7  
70              
71             require inc::Module::Install;
72              
73             sub _doc_template {
74 3     3   5 my ( $self, $args ) = @_;
75 3         5 my $package = __PACKAGE__;
76 3   50     45 my $version = ( __PACKAGE__->VERSION() || 'undefined ( self-build? )' );
77              
78 3         13 my $t = <<"EOF";
79             use strict;
80             use warnings;
81             # Warning: This code was generated by ${package} Version ${version}
82             # As part of Dist::Zilla's build generation.
83             # Do not modify this file, instead, modify the dist.ini that configures its generation.
84             use inc::Module::Install {{ \$miver }};
85             {{ \$headings }}
86             {{ \$requires }}
87             {{ \$feet }}
88             WriteAll();
89             EOF
90 3         10 return $self->fill_in_string( $t, $args );
91             }
92              
93             sub _label_value_template {
94 3     3   96 my ( $self, $args ) = @_;
95 3         7 my $t = <<"EOF";
96             {{ \$label }} '{{ \$value }}';
97             EOF
98 3         19 return $self->fill_in_string( $t, $args );
99             }
100              
101             sub _label_string_template {
102 12     12   6180 my ( $self, $args ) = @_;
103 12         16 my $t = <<"EOF";
104             {{ \$label }} "{{ quotemeta( \$string ) }}";
105             EOF
106 12         27 return $self->fill_in_string( $t, $args );
107             }
108              
109             sub _label_string_string_template {
110 6     6   8 my ( $self, $args ) = @_;
111 6         7 my $t = <<"EOF";
112             {{ \$label }} "{{ quotemeta(\$stringa) }}" => "{{ quotemeta(\$stringb) }}";
113             EOF
114 6         15 return $self->fill_in_string( $t, $args );
115             }
116              
117             sub _generate_makefile_pl {
118 3     3   8 my ($self) = @_;
119 3         5 my ( @headings, @requires, @feet );
120              
121 3         73 push @headings, _label_value_template( $self, { label => 'name', value => $self->zilla->name } ),
122             _label_string_template( $self, { label => 'abstract', string => $self->zilla->abstract } ),
123             _label_string_template( $self, { label => 'author', string => $self->zilla->authors->[0] } ),
124             _label_string_template( $self, { label => 'version', string => $self->zilla->version } ),
125             _label_string_template( $self, { label => 'license', string => $self->zilla->license->meta_yml_name } );
126              
127 3         1232 my $prereqs = $self->zilla->prereqs;
128              
129             my $doreq = sub {
130 15     15   19 my ( $key, $target ) = @_;
131 15         46 push @requires, qq{\n# @$key => $target};
132 15         16 my $hash = $prereqs->requirements_for( @{$key} )->as_string_hash;
  15         46  
133 15         1144 for ( sort keys %{$hash} ) {
  15         43  
134 6 50       16 if ( 'perl' eq $_ ) {
135 0         0 push @requires, _label_string_template( $self, { label => 'perl_version', string => $hash->{$_} } );
136 0         0 next;
137             }
138             push @requires,
139             $self->_label_string_string_template(
140             {
141             label => $target,
142             stringa => $_,
143 6         30 stringb => $hash->{$_},
144             },
145             );
146             }
147 3         109 };
148              
149 3         13 $doreq->( [qw(configure requires)], 'configure_requires' );
150 3         1333 $doreq->( [qw(build requires)], 'requires' );
151 3         1332 $doreq->( [qw(runtime requires)], 'requires' );
152 3         11 $doreq->( [qw(runtime recommends)], 'recommends' );
153 3         13 $doreq->( [qw(test requires)], 'test_requires' );
154              
155 3         8 push @feet, qq{\n# :ExecFiles};
156 3         5 my @found_files = @{ $self->zilla->find_files(':ExecFiles') };
  3         72  
157 3         2264 for my $execfile ( map { $_->name } @found_files ) {
  0         0  
158 0         0 push @feet, _label_string_template( $self, $execfile );
159             }
160 3         34 my $content = _doc_template(
161             $self,
162             {
163             miver => "$Module::Install::VERSION",
164             headings => join( qq{\n}, @headings ),
165             requires => join( qq{\n}, @requires ),
166             feet => join( qq{\n}, @feet ),
167             },
168             );
169 3         1860 return $content;
170             }
171              
172              
173              
174              
175              
176              
177              
178             sub register_prereqs {
179 1     1 1 45053 my ($self) = @_;
180 1         27 $self->zilla->register_prereqs( { phase => 'configure' }, 'ExtUtils::MakeMaker' => 6.42 );
181 1         513 $self->zilla->register_prereqs( { phase => 'build' }, 'ExtUtils::MakeMaker' => 6.42 );
182 1         164 return;
183             }
184              
185              
186              
187              
188              
189              
190              
191              
192             my $error_load = 'Error running Makefile.PL for Module::Install. ';
193             my $no_keepalive = $error_load . 'Set MI_KEEPALIVE=1 if you want to retain the directory for analysis';
194             my $keepalive = $error_load . 'Inspect the temporary directory to determine cause';
195              
196             sub setup_installer {
197 1     1 1 19567 my ( $self, ) = @_;
198              
199 1     3   41 my $file = Dist::Zilla::File::FromCode->new( { name => 'Makefile.PL', code => sub { _generate_makefile_pl($self) }, } );
  3         233440  
200              
201 1         192 $self->add_file($file);
202              
203             my $code = sub {
204 1     1   947 my ($dir) = @_;
205 1 50       233786 system $^X, 'Makefile.PL' and do {
206              
207 0 0       0 croak($no_keepalive) unless $ENV{MI_KEEPALIVE};
208              
209 0         0 $dir->keepalive_fail($keepalive);
210             };
211 1         632 };
212              
213 1         8 my (@generated) = $self->capture_tempdir($code);
214              
215 1         21735 for (@generated) {
216 14 100       401 if ( $_->is_new ) {
217 12         387 $self->log( 'ModuleInstall created: ' . $_->name );
218 12 100       3340 if ( $_->name =~ /\Ainc\/Module\/Install/msx ) {
219 8         602 $self->log( 'ModuleInstall added : ' . $_->name );
220 8         2162 $self->add_file( $_->file );
221             }
222             }
223 14 50       3869 if ( $_->is_modified ) {
224 0         0 $self->log( 'ModuleInstall modified: ' . $_->name );
225             }
226             }
227 1         62 return;
228             }
229              
230             1;
231              
232             __END__
233              
234             =pod
235              
236             =encoding UTF-8
237              
238             =head1 NAME
239              
240             Dist::Zilla::Plugin::ModuleInstall - (DEPRECATED) Build Module::Install based Distributions with Dist::Zilla
241              
242             =head1 VERSION
243              
244             version 1.001001
245              
246             =head1 SYNOPSIS
247              
248             dist.ini
249              
250             [ModuleInstall]
251              
252             =head1 DESCRIPTION
253              
254             This module will create a F<Makefile.PL> for installing the dist using L<< C<Module::Install>|Module::Install >>.
255              
256             It is at present a very minimal feature set, but it works.
257              
258             =head1 METHODS
259              
260             =head2 register_prereqs
261              
262             Tells Dist::Zilla about our needs to have EU::MM larger than 6.42
263              
264             =head2 setup_installer
265              
266             Generates the Makefile.PL, and runs it in a tmpdir, and then harvests the output and stores
267             it in the dist selectively.
268              
269             =head1 DEPRECATED
270              
271             This module is now officially deprecated.
272              
273             It was never really recommended, or supported, and it always existed as a gap filler for people
274             who were migrating from Module::Install and had yet to understand certain design elements of C<Dist::Zilla>
275             made using Module::Install effectively redundant.
276              
277             In short, it was an excuse, a foot-gun for the person who needed holes in their feet.
278              
279             I will not actively prevent this module from doing anything it didn't use to do, but its use
280             should be considered officially discouraged.
281              
282             =head1 AUTHOR
283              
284             Kent Fredric <kentnl@cpan.org>
285              
286             =head1 COPYRIGHT AND LICENSE
287              
288             This software is copyright (c) 2016 by Kent Fredric <kentfredric@gmail.com>.
289              
290             This is free software; you can redistribute it and/or modify it under
291             the same terms as the Perl 5 programming language system itself.
292              
293             =cut