X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=inc%2FMMPackageStash.pm;h=de68a0387fb6da3eb1f352f9a36da3fd162fd7f6;hb=1de0245b552a791eca039472a61b8b8493626805;hp=cab44dcb5c7c9c685976f6e8a39830978517f484;hpb=67b1704808e62f27210fe992df9c45b232fe9d5b;p=gitmo%2FPackage-Stash.git diff --git a/inc/MMPackageStash.pm b/inc/MMPackageStash.pm index cab44dc..de68a03 100644 --- a/inc/MMPackageStash.pm +++ b/inc/MMPackageStash.pm @@ -7,51 +7,48 @@ extends 'Dist::Zilla::Plugin::MakeMaker::Awesome'; around _build_MakeFile_PL_template => sub { my $orig = shift; my $self = shift; - my $template = $self->$orig(@_); - - $template =~ s/(use ExtUtils::MakeMaker.*)/$1\n\ncheck_conflicts();/; - $template .= <<'CHECK_CONFLICTS'; -sub check_conflicts { - my %conflicts = ( - # 'Class::MOP' => '1.08', - # 'MooseX::Role::WithOverloading' => '0.08', - ); - my $found = 0; - for my $mod ( sort keys %conflicts ) { - eval "require $mod"; - next if $@; + # copied from M::I + my $can_cc = <<'CAN_CC'; +use Config (); +use File::Spec (); - my $installed = $mod->VERSION(); - if ( $installed le $conflicts{$mod} ) { +# check if we can run some command +sub can_run { + my ($cmd) = @_; - print <<"EOF"; + my $_cmd = $cmd; + return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); -*** - This version of Package::Stash conflicts with the version of - $mod ($installed) you have installed. + for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { + next if $dir eq ''; + my $abs = File::Spec->catfile($dir, $_[1]); + return $abs if (-x $abs or $abs = MM->maybe_command($abs)); + } - You will need to upgrade $mod after installing - this version of Package::Stash. -*** + return; +} -EOF +# can we locate a (the) C compiler +sub can_cc { + my @chunks = split(/ /, $Config::Config{cc}) or return; - $found = 1; + # $Config{cc} may contain args; try to find out the program part + while (@chunks) { + return can_run("@chunks") || (pop(@chunks), next); } - } - return unless $found; + return; +} +CAN_CC + + my $template = $self->$orig(@_); - # More or less copied from Module::Build - return if $ENV{PERL_MM_USE_DEFAULT}; - return unless -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)); + my $xs_version = $self->zilla->prereqs->requirements_for('runtime', 'recommends')->as_string_hash->{'Package::Stash::XS'}; - sleep 4; -} -CHECK_CONFLICTS + $template =~ s/(WriteMakefile\()/\$WriteMakefileArgs{PREREQ_PM}{'Package::Stash::XS'} = $xs_version\n if can_cc();\n\n$1/; - return $template; + return $template . $can_cc; }; __PACKAGE__->meta->make_immutable;