| 1 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | package Dist::Zilla::Plugin::MakeMaker::Custom; | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # Copyright 2010 Christopher J. Madsen | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # Author: Christopher J. Madsen <perl@cjmweb.net> | ||||||||||||||||||||||||||||
| 7 | # Created: 11 Mar 2010 | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 10 | # it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the | ||||||||||||||||||||||||||||
| 15 | # GNU General Public License or the Artistic License for more details. | ||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||
| 17 | # ABSTRACT: Allow a dist to have a custom Makefile.PL | ||||||||||||||||||||||||||||
| 18 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | our $VERSION = '4.26'; | |||||||||||||||||||||||||||
| 21 | # This file is part of Dist-Zilla-Plugins-CJM 6.000 (December 17, 2017) | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Dist::Zilla::Plugin::MakeMaker 4.300009; # improved subclassing | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | extends 'Dist::Zilla::Plugin::MakeMaker'; | |||||||||||||||||||||||||||
| 27 | 2 | with qw(Dist::Zilla::Role::FilePruner | |||||||||||||||||||||||||||
| 28 | Dist::Zilla::Role::HashDumper); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use List::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # We're trying to make the template executable before it's filled in, | ||||||||||||||||||||||||||||
| 33 | # so we want delimiters that look like comments: | ||||||||||||||||||||||||||||
| 34 | has '+delim' => ( | ||||||||||||||||||||||||||||
| 35 | 3 | ▶ | default => sub { [ '##{', '##}' ] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Need to cache write_makefile_args for the get_default method | ||||||||||||||||||||||||||||
| 39 | 2 | has _mmc_write_makefile_args => ( | |||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 42 | lazy => 1, | ||||||||||||||||||||||||||||
| 43 | init_arg => undef, | ||||||||||||||||||||||||||||
| 44 | builder => 'write_makefile_args', | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Get rid of any META.yml we may have picked up from MakeMaker: | ||||||||||||||||||||||||||||
| 48 | sub prune_files | ||||||||||||||||||||||||||||
| 49 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prune_files: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | my $files = $self->zilla->files; | |||||||||||||||||||||||||||
| 53 | 3 | ▶ | @$files = grep { not($_->name =~ /^META\.(?:yml|json)$/ and | ||||||||||||||||||||||||||
|
Condition33%1/3
$_->name =~ /^META\.(?:yml|json)$/ && $_->isa('Dist::Zilla::File::OnDisk')
MC/DC0%0/2
$_->name =~ /^META\.(?:yml|json)$/ && $_->isa('Dist::Zilla::File::OnDisk')
$_->name =~ /^META\.(?:yml|json)$/
$_->isa('Dist::Zilla::File::OnDisk')
Truth table33%1/3
A && B
A= $_->name =~ /^META\.(?:yml|json)$/B= $_->isa('Dist::Zilla::File::OnDisk')
| |||||||||||||||||||||||||||||
| 54 | $_->isa('Dist::Zilla::File::OnDisk')) } @$files; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | return; | |||||||||||||||||||||||||||
| 57 | } # end prune_files | ||||||||||||||||||||||||||||
| 58 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub get_prereqs | ||||||||||||||||||||||||||||
| 62 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_prereqs: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 3 | my ($self, $api_version) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | if ($api_version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | $self->log_fatal("api_version $api_version is not supported") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | unless $api_version == 1; | ||||||||||||||||||||||||||||
| 68 | 1 | local $@; | |||||||||||||||||||||||||||
| 69 | $self->log(["WARNING: Dist::Zilla %s does not support api_version %d", | ||||||||||||||||||||||||||||
| 70 | Dist::Zilla->VERSION, $api_version ]) | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | unless eval { Dist::Zilla::Plugin::MakeMaker->VERSION( 4.300032 ) }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # Get the prerequisites as a hashref: | ||||||||||||||||||||||||||||
| 75 | 3 | my $prereqs = $self->extract_keys_as_hash( | |||||||||||||||||||||||||||
| 76 | WriteMakefile => $self->_mmc_write_makefile_args, | ||||||||||||||||||||||||||||
| 77 | qw(BUILD_REQUIRES CONFIGURE_REQUIRES PREREQ_PM TEST_REQUIRES) | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # If we have TEST_REQUIRES, but the template doesn't understand them, | ||||||||||||||||||||||||||||
| 81 | # merge them into BUILD_REQUIRES (if any) | ||||||||||||||||||||||||||||
| 82 | 3 | ▶ | if ($prereqs->{TEST_REQUIRES} and not $api_version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prereqs->{"TEST_REQUIRES"} and not $api_version
MC/DC50%1/2
$prereqs->{"TEST_REQUIRES"} and not $api_version
$prereqs->{"TEST_REQUIRES"}
not $api_version
Truth table66%2/3
A and not(B)
A= $prereqs->{"TEST_REQUIRES"}B= not $api_version
| |||||||||||||||||||||||||||||
| 83 | 2 | ▶ | if ($prereqs->{BUILD_REQUIRES}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | # have both BUILD_REQUIRES & TEST_REQUIRES, so merge them: | ||||||||||||||||||||||||||||
| 85 | 1 | require CPAN::Meta::Requirements; | |||||||||||||||||||||||||||
| 86 | 1 | CPAN::Meta::Requirements->VERSION(2.121); | |||||||||||||||||||||||||||
| 87 | my ($buildreq, $testreq) = map { | ||||||||||||||||||||||||||||
| 88 | 1 | CPAN::Meta::Requirements->from_string_hash( $prereqs->{$_} ) | |||||||||||||||||||||||||||
| 89 | } qw(BUILD_REQUIRES TEST_REQUIRES); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | $buildreq->add_requirements( $testreq ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | delete $prereqs->{TEST_REQUIRES}; | |||||||||||||||||||||||||||
| 94 | 1 | $prereqs->{BUILD_REQUIRES} = $buildreq->as_string_hash; | |||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||
| 96 | # no BUILD_REQUIRES, so we can just rename TEST_REQUIRES: | ||||||||||||||||||||||||||||
| 97 | 1 | $prereqs->{BUILD_REQUIRES} = delete $prereqs->{TEST_REQUIRES}; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } # end if TEST_REQUIRES and $api_version is 0 | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3 | $self->hash_as_string( $prereqs ); | |||||||||||||||||||||||||||
| 102 | } # end get_prereqs | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub get_default | ||||||||||||||||||||||||||||
| 108 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | return $self->extract_keys(WriteMakefile => $self->_mmc_write_makefile_args, | |||||||||||||||||||||||||||
| 112 | @_); | ||||||||||||||||||||||||||||
| 113 | } # end get_default | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | ▶ | sub add_file {} # Don't let parent class add any files | ||||||||||||||||||||||||||
|
Subroutine
add_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 118 | 3 | ▶ | around setup_installer => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||
| 119 | 3 | my $orig = shift; | |||||||||||||||||||||||||||
| 120 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 9 | ▶ | my $file = List::Util::first { $_->name eq 'Makefile.PL' } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 123 | 3 | ▶ | @{ $self->zilla->files } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | or $self->log_fatal("No Makefile.PL found in dist"); | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 3 | my $write_makefile_args = $self->_mmc_write_makefile_args; | |||||||||||||||||||||||||||
| 127 | 3 | my $perl_prereq = $write_makefile_args->{MIN_PERL_VERSION}; | |||||||||||||||||||||||||||
| 128 | 3 | my $share_dir_code = $self->share_dir_code; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Process Makefile.PL through Text::Template: | ||||||||||||||||||||||||||||
| 131 | my %data = ( | ||||||||||||||||||||||||||||
| 132 | dist => $self->zilla->name, | ||||||||||||||||||||||||||||
| 133 | meta => $self->zilla->distmeta, | ||||||||||||||||||||||||||||
| 134 | plugin => \$self, | ||||||||||||||||||||||||||||
| 135 | version => $self->zilla->version, | ||||||||||||||||||||||||||||
| 136 | zilla => \$self->zilla, | ||||||||||||||||||||||||||||
| 137 | default_args => $write_makefile_args, | ||||||||||||||||||||||||||||
| 138 | eumm_version => \($self->eumm_version), | ||||||||||||||||||||||||||||
| 139 | perl_prereq => \$perl_prereq, | ||||||||||||||||||||||||||||
| 140 | share_dir_code => $share_dir_code, | ||||||||||||||||||||||||||||
| 141 | # Recreate share_dir_block for backwards compatibility: | ||||||||||||||||||||||||||||
| 142 | share_dir_block => [ $share_dir_code->{preamble} || '', | ||||||||||||||||||||||||||||
| 143 | 3 | ▶ | $share_dir_code->{postamble} || '' ], | ||||||||||||||||||||||||||
|
Condition50%2/4
$share_dir_code->{'preamble'} || ''
$share_dir_code->{'postamble'} || ''
MC/DC0%0/1
$share_dir_code->{'preamble'} || ''
$share_dir_code->{'preamble'}
MC/DC0%0/1
$share_dir_code->{'postamble'} || ''
$share_dir_code->{'postamble'}
Truth table50%1/2
A
A= $share_dir_code->{'preamble'}
Truth table50%1/2
A
A= $share_dir_code->{'postamble'}
| |||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # The STRICT option hasn't been implemented in a released version of | ||||||||||||||||||||||||||||
| 147 | # Text::Template, but you can apply Template_strict.patch. Since | ||||||||||||||||||||||||||||
| 148 | # Text::Template ignores unknown options, this code will still work | ||||||||||||||||||||||||||||
| 149 | # even if you don't apply the patch; you just won't get strict checking. | ||||||||||||||||||||||||||||
| 150 | my %parms = ( | ||||||||||||||||||||||||||||
| 151 | STRICT => 1, | ||||||||||||||||||||||||||||
| 152 | 0 | ▶ | BROKEN => sub { $self->template_error(@_) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 153 | 3 | ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 3 | $self->log_debug("Processing Makefile.PL as template"); | |||||||||||||||||||||||||||
| 156 | 3 | $file->content($self->fill_in_string($file->content, \%data, \%parms)); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 3 | return; | |||||||||||||||||||||||||||
| 159 | 2 | }; # end setup_installer | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub template_error | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
template_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 0 | my ($self, %e) = @_; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # Put the filename into the error message: | ||||||||||||||||||||||||||||
| 166 | 0 | my $err = $e{error}; | |||||||||||||||||||||||||||
| 167 | 0 | $err =~ s/ at template line (?=\d)/ at Makefile.PL line /g; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | $self->log_fatal($err); | |||||||||||||||||||||||||||
| 170 | } # end template_error | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 173 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 174 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 175 | 2 | 1; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||