| 1 | 1 | ▶ | use 5.008; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | package Dist::Zilla::Plugin::InstallGuide; # git description: v1.200013-7-g803cf68 | ||||||||||||||
| 6 | # ABSTRACT: Build an INSTALL file | ||||||||||||||
| 7 | |||||||||||||||
| 8 | 1 | our $VERSION = '1.200014'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | with 'Dist::Zilla::Role::FileGatherer'; | |||||||||||||
| 12 | 1 | with 'Dist::Zilla::Role::TextTemplate'; | |||||||||||||
| 13 | 1 | with 'Dist::Zilla::Role::FileMunger'; | |||||||||||||
| 14 | 1 | with 'Dist::Zilla::Role::ModuleMetadata'; | |||||||||||||
| 15 | 1 | ▶ | use List::Util 1.33 qw(first any); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 1 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 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 | 1 | 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 | 1 | 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 | 1 | 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 | 1 | ▶ | sub gather_files { | ||||||||||||
|
Subroutine
gather_files: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 164 | 1 | my $self = shift; | |||||||||||||
| 165 | |||||||||||||||
| 166 | 1 | require Dist::Zilla::File::InMemory; | |||||||||||||
| 167 | 1 | $self->add_file(Dist::Zilla::File::InMemory->new({ | |||||||||||||
| 168 | name => 'INSTALL', | ||||||||||||||
| 169 | content => $self->template, | ||||||||||||||
| 170 | })); | ||||||||||||||
| 171 | |||||||||||||||
| 172 | 1 | 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 | 1 | ▶ | sub munge_files { | ||||||||||||
|
Subroutine
munge_files: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||
| 182 | 1 | my $self = shift; | |||||||||||||
| 183 | |||||||||||||||
| 184 | 1 | my $zilla = $self->zilla; | |||||||||||||
| 185 | |||||||||||||||
| 186 | 1 | 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 | ▶ | ), @{ $zilla->plugins } | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 193 | ); | ||||||||||||||
| 194 | |||||||||||||||
| 195 | 1 | ▶ | if ($installer{'Build.PL'}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 196 | 0 | $manual_installation .= $self->module_build_manual_installation; | |||||||||||||
| 197 | } | ||||||||||||||
| 198 | elsif ($installer{'Makefile.PL'}) { | ||||||||||||||
| 199 | 1 | $manual_installation .= $self->makemaker_manual_installation; | |||||||||||||
| 200 | } | ||||||||||||||
| 201 | 1 | ▶ | unless ($manual_installation) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 202 | 0 | $self->log_fatal('neither Makefile.PL nor Build.PL is present, aborting'); | |||||||||||||
| 203 | } | ||||||||||||||
| 204 | |||||||||||||||
| 205 | 1 | my $main_package = $self->module_metadata_for_file($zilla->main_module, collect_pod => 0)->name; | |||||||||||||
| 206 | |||||||||||||||
| 207 | 1 | ▶ | my $file = first { $_->name eq 'INSTALL' } @{ $zilla->files }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 208 | |||||||||||||||
| 209 | my $content = $self->fill_in_string( | ||||||||||||||
| 210 | $file->content, | ||||||||||||||
| 211 | { dist => \$zilla, | ||||||||||||||
| 212 | package => $main_package, | ||||||||||||||
| 213 | manual_installation => $manual_installation, | ||||||||||||||
| 214 | 1 | ▶ | has_meta_yml => (any { $_->name eq 'META.yml' } @{ $zilla->files }), | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 215 | 1 | ▶ | has_meta_json => (any { $_->name eq 'META.json' } @{ $zilla->files }), | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 216 | installer => \%installer, | ||||||||||||||
| 217 | } | ||||||||||||||
| 218 | ); | ||||||||||||||
| 219 | |||||||||||||||
| 220 | 1 | $file->content($content); | |||||||||||||
| 221 | 1 | return; | |||||||||||||
| 222 | } | ||||||||||||||
| 223 | |||||||||||||||
| 224 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 225 | 1 | ▶ | no Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 226 | 1 | 1; | |||||||||||||
| 227 | |||||||||||||||
| 228 | __END__ | ||||||||||||||