1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
# copied/adapted from Package::Stash
package inc::MakeMaker;
use Moose;
extends 'Dist::Zilla::Plugin::MakeMaker::Awesome';
with 'Dist::Zilla::Role::MetaProvider';
# XXX: this is pretty gross, it should be possible to clean this up later
around _build_MakeFile_PL_template => sub {
my $orig = shift;
my $self = shift;
# can_run and can_cc copied from M::I
my $helpers = <<'HELPERS';
use Config ();
use File::Spec ();
use Text::ParseWords ();
# check if we can run some command
sub can_run {
my ($cmd) = @_;
my $_cmd = $cmd;
return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
next if $dir eq '';
my $abs = File::Spec->catfile($dir, $_[0]);
return $abs if (-x $abs or $abs = MM->maybe_command($abs));
}
return;
}
# can we locate a (the) C compiler
sub can_cc {
my @chunks = split(/ /, $Config::Config{cc}) or return;
# $Config{cc} may contain args; try to find out the program part
while (@chunks) {
return can_run("@chunks") || (pop(@chunks), next);
}
return;
}
# XXX this is gross, but apparently it's the least gross option?
sub parse_args {
my $tmp = {};
# copied from EUMM
ExtUtils::MakeMaker::parse_args(
$tmp,
Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
@ARGV,
);
return $tmp->{ARGS} || {};
}
HELPERS
my $fixup_prereqs = <<PREREQS;
if ( \$] < 5.010 ) {
if ( !parse_args()->{PUREPERL_ONLY} && can_cc() ) {
\$WriteMakefileArgs{PREREQ_PM}{'Digest::SHA'} = 0;
}
else {
\$WriteMakefileArgs{PREREQ_PM}{'Digest::SHA::PurePerl'} = 0;
}
}
PREREQS
my $template = $self->$orig(@_);
$template =~ s/(WriteMakefile\()/$fixup_prereqs\n$1/;
$template .= $helpers;
return $template;
};
after register_prereqs => sub {
my $self = shift;
$self->zilla->register_prereqs(
{ phase => 'configure' },
'Config' => 0,
'File::Spec' => 0,
'Text::ParseWords' => 0,
);
};
sub metadata { return +{ dynamic_config => 1 } }
__PACKAGE__->meta->make_immutable;
no Moose;
1;
|