File Coverage

blib/lib/Dist/Zilla/Plugin/InstallGuide.pm
Criterion Covered Total %
statement 43 45 95.5
branch 6 10 60.0
condition n/a
subroutine 12 12 100.0
pod 2 2 100.0
total 63 69 91.3


line stmt bran cond sub pod time code
1 1     1   2692039 use 5.008;
  1         3  
2 1     1   6 use strict;
  1         2  
  1         25  
3 1     1   5 use warnings;
  1         2  
  1         67  
4              
5             package Dist::Zilla::Plugin::InstallGuide; # git description: v1.200013-7-g803cf68
6             # ABSTRACT: Build an INSTALL file
7              
8             our $VERSION = '1.200014';
9              
10 1     1   5 use Moose;
  1         2  
  1         6  
11             with 'Dist::Zilla::Role::FileGatherer';
12             with 'Dist::Zilla::Role::TextTemplate';
13             with 'Dist::Zilla::Role::FileMunger';
14             with 'Dist::Zilla::Role::ModuleMetadata';
15 1     1   5815 use List::Util 1.33 qw(first any);
  1         17  
  1         81  
16 1     1   7 use namespace::autoclean;
  1         2  
  1         9  
17              
18             #pod =head1 SYNOPSIS
19             #pod
20             #pod In C<dist.ini>:
21             #pod
22             #pod [InstallGuide]
23             #pod
24             #pod =begin :prelude
25             #pod
26             #pod =for test_synopsis BEGIN { die "SKIP: synopsis isn't perl code" }
27             #pod
28             #pod =end :prelude
29             #pod
30             #pod =head1 DESCRIPTION
31             #pod
32             #pod This plugin adds a very simple F<INSTALL> file to the distribution, telling
33             #pod the user how to install this distribution.
34             #pod
35             #pod You should use this plugin in your L<Dist::Zilla> configuration after
36             #pod C<[MakeMaker]> or C<[ModuleBuild]> so that it can determine what kind of
37             #pod distribution you are building and which installation instructions are
38             #pod appropriate.
39             #pod
40             #pod =head1 METHODS
41             #pod
42             #pod =cut
43              
44             has template => (is => 'ro', isa => 'Str', default => <<'END_TEXT');
45             This is the Perl distribution {{ $dist->name }}.
46              
47             Installing {{ $dist->name }} is straightforward.
48              
49             ## Installation with cpanm
50              
51             If you have cpanm, you only need one line:
52              
53             % cpanm {{ $package }}
54              
55             If it does not have permission to install modules to the current perl, cpanm
56             will automatically set up and install to a local::lib in your home directory.
57             See the local::lib documentation (https://metacpan.org/pod/local::lib) for
58             details on enabling it in your environment.
59              
60             ## Installing with the CPAN shell
61              
62             Alternatively, if your CPAN shell is set up, you should just be able to do:
63              
64             % cpan {{ $package }}
65              
66             ## Manual installation
67              
68             As a last resort, you can manually install it. If you have not already
69             downloaded the release tarball, you can find the download link on the module's
70             MetaCPAN page: https://metacpan.org/pod/{{ $package }}
71              
72             Untar the tarball, install configure prerequisites (see below), then build it:
73              
74             {{ $manual_installation }}
75             The prerequisites of this distribution will also have to be installed manually. The
76             prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated
77             by running the manual build process described above.
78              
79             ## Configure Prerequisites
80              
81             This distribution requires other modules to be installed before this
82             distribution's installer can be run. They can be found under the
83             {{ join(" or the\n",
84             $has_meta_yml ? '"configure_requires" key of META.yml' : '',
85             $has_meta_json ? '"{prereqs}{configure}{requires}" key of META.json' : '',
86             )}}.
87              
88             ## Other Prerequisites
89              
90             This distribution may require additional modules to be installed after running
91             {{ join(' or ', grep $installer{$_}, qw(Build.PL Makefile.PL)) }}.
92             Look for prerequisites in the following phases:
93              
94             * to run {{ join(' or ',
95             ($installer{'Build.PL'} ? './Build' : ()),
96             ($installer{'Makefile.PL'} ? 'make' : ())) }}, PHASE = build
97             * to use the module code itself, PHASE = runtime
98             * to run tests, PHASE = test
99              
100             They can all be found in the {{ join(" or the\n",
101             $has_meta_yml ? '"PHASE_requires" key of MYMETA.yml' : '',
102             $has_meta_json ? '"{prereqs}{PHASE}{requires}" key of MYMETA.json' : '',
103             )}}.
104              
105             ## Documentation
106              
107             {{ $dist->name }} documentation is available as POD.
108             You can run `perldoc` from a shell to read the documentation:
109              
110             % perldoc {{ $package }}
111              
112             For more information on installing Perl modules via CPAN, please see:
113             https://www.cpan.org/modules/INSTALL.html
114             END_TEXT
115              
116             has makemaker_manual_installation => (
117             is => 'ro', isa => 'Str',
118             default => <<'END_TEXT',
119             % perl Makefile.PL
120             % make && make test
121              
122             Then install it:
123              
124             % make install
125              
126             On Windows platforms, you should use `dmake` or `nmake`, instead of `make`.
127              
128             If your perl is system-managed, you can create a local::lib in your home
129             directory to install modules to. For details, see the local::lib documentation:
130             https://metacpan.org/pod/local::lib
131             END_TEXT
132             );
133              
134             has module_build_manual_installation => (
135             is => 'ro', isa => 'Str',
136             default => <<'END_TEXT',
137             % perl Build.PL
138             % ./Build && ./Build test
139              
140             Then install it:
141              
142             % ./Build install
143              
144             Or the more portable variation:
145              
146             % perl Build.PL
147             % perl Build
148             % perl Build test
149             % perl Build install
150              
151             If your perl is system-managed, you can create a local::lib in your home
152             directory to install modules to. For details, see the local::lib documentation:
153             https://metacpan.org/pod/local::lib
154             END_TEXT
155             );
156              
157             #pod =head2 gather_files
158             #pod
159             #pod Creates the F<INSTALL> file.
160             #pod
161             #pod =cut
162              
163             sub gather_files {
164 1     1 1 65882 my $self = shift;
165              
166 1         6 require Dist::Zilla::File::InMemory;
167 1         31 $self->add_file(Dist::Zilla::File::InMemory->new({
168             name => 'INSTALL',
169             content => $self->template,
170             }));
171              
172 1         770 return;
173             }
174              
175             #pod =head2 munge_files
176             #pod
177             #pod Inserts the appropriate installation instructions into F<INSTALL>.
178             #pod
179             #pod =cut
180              
181             sub munge_files {
182 1     1 1 3688 my $self = shift;
183              
184 1         27 my $zilla = $self->zilla;
185              
186 1         7 my $manual_installation = '';
187              
188             my %installer = (
189             map +(
190             $_->isa('Dist::Zilla::Plugin::MakeMaker') ? ( 'Makefile.PL' => 1 ) : (),
191             $_->does('Dist::Zilla::Role::BuildPL') ? ( 'Build.PL' => 1 ) : (),
192 1 100       2 ), @{ $zilla->plugins }
  1 50       19  
193             );
194              
195 1 50       831 if ($installer{'Build.PL'}) {
    50          
196 0         0 $manual_installation .= $self->module_build_manual_installation;
197             }
198             elsif ($installer{'Makefile.PL'}) {
199 1         36 $manual_installation .= $self->makemaker_manual_installation;
200             }
201 1 50       4 unless ($manual_installation) {
202 0         0 $self->log_fatal('neither Makefile.PL nor Build.PL is present, aborting');
203             }
204              
205 1         27 my $main_package = $self->module_metadata_for_file($zilla->main_module, collect_pod => 0)->name;
206              
207 1     4   4525 my $file = first { $_->name eq 'INSTALL' } @{ $zilla->files };
  4         129  
  1         26  
208              
209             my $content = $self->fill_in_string(
210             $file->content,
211             { dist => \$zilla,
212             package => $main_package,
213             manual_installation => $manual_installation,
214 4     4   118 has_meta_yml => (any { $_->name eq 'META.yml' } @{ $zilla->files }),
  1         108  
215 1     4   41 has_meta_json => (any { $_->name eq 'META.json' } @{ $zilla->files }),
  4         113  
  1         54  
216             installer => \%installer,
217             }
218             );
219              
220 1         2970 $file->content($content);
221 1         228 return;
222             }
223              
224             __PACKAGE__->meta->make_immutable;
225 1     1   511 no Moose;
  1         3  
  1         5  
226             1;
227              
228             __END__
229              
230             =pod
231              
232             =encoding UTF-8
233              
234             =head1 NAME
235              
236             Dist::Zilla::Plugin::InstallGuide - Build an INSTALL file
237              
238             =head1 VERSION
239              
240             version 1.200014
241              
242             =for test_synopsis BEGIN { die "SKIP: synopsis isn't perl code" }
243              
244             =head1 SYNOPSIS
245              
246             In C<dist.ini>:
247              
248             [InstallGuide]
249              
250             =head1 DESCRIPTION
251              
252             This plugin adds a very simple F<INSTALL> file to the distribution, telling
253             the user how to install this distribution.
254              
255             You should use this plugin in your L<Dist::Zilla> configuration after
256             C<[MakeMaker]> or C<[ModuleBuild]> so that it can determine what kind of
257             distribution you are building and which installation instructions are
258             appropriate.
259              
260             =head1 METHODS
261              
262             =head2 gather_files
263              
264             Creates the F<INSTALL> file.
265              
266             =head2 munge_files
267              
268             Inserts the appropriate installation instructions into F<INSTALL>.
269              
270             =head1 SUPPORT
271              
272             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-InstallGuide>
273             (or L<bug-Dist-Zilla-Plugin-InstallGuide@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-InstallGuide@rt.cpan.org>).
274              
275             There is also a mailing list available for users of this distribution, at
276             L<http://dzil.org/#mailing-list>.
277              
278             There is also an irc channel available for users of this distribution, at
279             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
280              
281             =head1 AUTHORS
282              
283             =over 4
284              
285             =item *
286              
287             Marcel Grünauer <marcel@cpan.org>
288              
289             =item *
290              
291             Mike Doherty <doherty@cpan.org>
292              
293             =back
294              
295             =head1 CONTRIBUTORS
296              
297             =for stopwords Karen Etheridge Mike Doherty Marcel Gruenauer jonasbn Dan Book Apocalypse Dave Rolsky
298              
299             =over 4
300              
301             =item *
302              
303             Karen Etheridge <ether@cpan.org>
304              
305             =item *
306              
307             Mike Doherty <mike@mikedoherty.ca>
308              
309             =item *
310              
311             Marcel Gruenauer <hanekomu@gmail.com>
312              
313             =item *
314              
315             jonasbn <jonasbn@gmail.com>
316              
317             =item *
318              
319             Mike Doherty <doherty@cs.dal.ca>
320              
321             =item *
322              
323             Dan Book <grinnz@gmail.com>
324              
325             =item *
326              
327             Apocalypse <APOCAL@cpan.org>
328              
329             =item *
330              
331             Dan Book <grinnz@grinnz.com>
332              
333             =item *
334              
335             Dave Rolsky <autarch@urth.org>
336              
337             =back
338              
339             =head1 COPYRIGHT AND LICENSE
340              
341             This software is copyright (c) 2010 by Marcel Grünauer <marcel@cpan.org>.
342              
343             This is free software; you can redistribute it and/or modify it under
344             the same terms as the Perl 5 programming language system itself.
345              
346             =cut