| 1 | #--------------------------------------------------------------------- | ||||||||||||||||||||
| 2 | package Dist::Zilla::Plugin::ModuleBuild::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 Build.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 | extends 'Dist::Zilla::Plugin::ModuleBuild'; | |||||||||||||||||||
| 26 | 2 | with qw(Dist::Zilla::Role::FilePruner | |||||||||||||||||||
| 27 | Dist::Zilla::Role::HashDumper); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2 | ▶ | use List::Util (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # We're trying to make the template executable before it's filled in, | ||||||||||||||||||||
| 32 | # so we want delimiters that look like comments: | ||||||||||||||||||||
| 33 | has '+delim' => ( | ||||||||||||||||||||
| 34 | 3 | ▶ | default => sub { [ '##{', '##}' ] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 2 | ); | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 2 | has distmeta1 => ( | |||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||
| 39 | isa => 'HashRef', | ||||||||||||||||||||
| 40 | init_arg => undef, | ||||||||||||||||||||
| 41 | lazy => 1, | ||||||||||||||||||||
| 42 | builder => '_build_distmeta1', | ||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | sub _build_distmeta1 | ||||||||||||||||||||
| 46 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
_build_distmeta1: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 47 | 3 | my $self = shift; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 3 | require CPAN::Meta::Converter; | |||||||||||||||||||
| 50 | 3 | CPAN::Meta::Converter->VERSION(2.101550); # improved downconversion | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 3 | my $converter = CPAN::Meta::Converter->new($self->zilla->distmeta); | |||||||||||||||||||
| 53 | 3 | return $converter->convert(version => '1.4'); | |||||||||||||||||||
| 54 | } # end _build_distmeta1 | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | # Get rid of any META.yml we may have picked up from Module::Build: | ||||||||||||||||||||
| 57 | 3 | ▶ | sub prune_files { | ||||||||||||||||||
|
Subroutine
prune_files: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||
| 58 | 3 | my ($self) = @_; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 3 | my $files = $self->zilla->files; | |||||||||||||||||||
| 61 | 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')
| |||||||||||||||||||||
| 62 | $_->isa('Dist::Zilla::File::OnDisk')) } @$files; | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 3 | return; | |||||||||||||||||||
| 65 | } # end prune_files | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | sub get_meta | ||||||||||||||||||||
| 69 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_meta: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 70 | 2 | my $self = shift; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | # Extract the wanted keys from distmeta: | ||||||||||||||||||||
| 73 | 2 | return $self->extract_keys(distmeta1 => $self->distmeta1, @_); | |||||||||||||||||||
| 74 | } # end get_meta | ||||||||||||||||||||
| 75 | #--------------------------------------------------------------------- | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | sub get_prereqs | ||||||||||||||||||||
| 79 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_prereqs: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 80 | 3 | my ($self, $api_version) = @_; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 3 | ▶ | if ($api_version) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 1 | ▶ | $self->log_fatal("api_version $api_version is not supported") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | unless $api_version == 1; | ||||||||||||||||||||
| 85 | 1 | local $@; | |||||||||||||||||||
| 86 | $self->log(["WARNING: Dist::Zilla %s does not support api_version %d", | ||||||||||||||||||||
| 87 | Dist::Zilla->VERSION, $api_version ]) | ||||||||||||||||||||
| 88 | 1 | ▶ | unless eval { Dist::Zilla::Plugin::ModuleBuild->VERSION( 4.300032 ) }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 1 | return $self->get_default(qw(build_requires configure_requires requires | |||||||||||||||||||
| 91 | test_requires recommends conflicts)); | ||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 2 | $self->get_meta(qw(build_requires configure_requires requires recommends | |||||||||||||||||||
| 95 | conflicts)); | ||||||||||||||||||||
| 96 | } # end get_prereqs | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | #--------------------------------------------------------------------- | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 2 | has _default_mb_args => ( | |||||||||||||||||||
| 102 | is => 'ro', | ||||||||||||||||||||
| 103 | isa => 'HashRef', | ||||||||||||||||||||
| 104 | init_arg => undef, | ||||||||||||||||||||
| 105 | lazy => 1, | ||||||||||||||||||||
| 106 | builder => 'module_build_args', | ||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | sub get_default | ||||||||||||||||||||
| 110 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 111 | 1 | my $self = shift; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 1 | return $self->extract_keys(module_build => $self->_default_mb_args, @_); | |||||||||||||||||||
| 114 | } # end get_default | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 3 | ▶ | sub add_file {} # Don't let parent class add any files | ||||||||||||||||||
|
Subroutine
add_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | #--------------------------------------------------------------------- | ||||||||||||||||||||
| 119 | sub setup_installer | ||||||||||||||||||||
| 120 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
setup_installer: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 121 | 3 | my $self = shift; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 8 | ▶ | my $file = List::Util::first { $_->name eq 'Build.PL' } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 124 | 3 | ▶ | @{ $self->zilla->files } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | or $self->log_fatal("No Build.PL found in dist"); | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | # Process Build.PL through Text::Template: | ||||||||||||||||||||
| 128 | 3 | my %data = ( | |||||||||||||||||||
| 129 | dist => $self->zilla->name, | ||||||||||||||||||||
| 130 | meta => $self->distmeta1, | ||||||||||||||||||||
| 131 | meta2 => $self->zilla->distmeta, | ||||||||||||||||||||
| 132 | plugin => \$self, | ||||||||||||||||||||
| 133 | version => $self->zilla->version, | ||||||||||||||||||||
| 134 | zilla => \$self->zilla, | ||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | # The STRICT option hasn't been implemented in a released version of | ||||||||||||||||||||
| 138 | # Text::Template, but you can apply Template_strict.patch. Since | ||||||||||||||||||||
| 139 | # Text::Template ignores unknown options, this code will still work | ||||||||||||||||||||
| 140 | # even if you don't apply the patch; you just won't get strict checking. | ||||||||||||||||||||
| 141 | my %parms = ( | ||||||||||||||||||||
| 142 | STRICT => 1, | ||||||||||||||||||||
| 143 | 0 | ▶ | BROKEN => sub { $self->template_error(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 144 | 3 | ); | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 3 | $self->log_debug("Processing Build.PL as template"); | |||||||||||||||||||
| 147 | 3 | $file->content($self->fill_in_string($file->content, \%data, \%parms)); | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 3 | return; | |||||||||||||||||||
| 150 | } # end setup_installer | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | sub template_error | ||||||||||||||||||||
| 153 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
template_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 154 | 0 | my ($self, %e) = @_; | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | # Put the filename into the error message: | ||||||||||||||||||||
| 157 | 0 | my $err = $e{error}; | |||||||||||||||||||
| 158 | 0 | $err =~ s/ at template line (?=\d)/ at Build.PL line /g; | |||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 0 | $self->log_fatal($err); | |||||||||||||||||||
| 161 | } # end template_error | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | #--------------------------------------------------------------------- | ||||||||||||||||||||
| 164 | 2 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 165 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 166 | 2 | 1; | |||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | __END__ | ||||||||||||||||||||