this is only going to work on 5.14
[gitmo/Package-Stash.git] / inc / MMPackageStash.pm
index b29aa5e..d471114 100644 (file)
@@ -22,7 +22,7 @@ sub can_run {
 
         for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
                 next if $dir eq '';
-                my $abs = File::Spec->catfile($dir, $_[1]);
+                my $abs = File::Spec->catfile($dir, $_[0]);
                 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
         }
 
@@ -42,54 +42,13 @@ sub can_cc {
 }
 CAN_CC
 
-    # copied out of moose
-    my $check_conflicts = <<'CHECK_CONFLICTS';
-sub check_conflicts {
-    my %conflicts = (
-        'Class::MOP'                    => '1.08',
-        'MooseX::Role::WithOverloading' => '0.08',
-        'namespace::clean'              => '0.18',
-    );
-    my $found = 0;
-    for my $mod ( sort keys %conflicts ) {
-        eval "require $mod";
-        next if $@;
-
-        my $installed = $mod->VERSION();
-        if ( $installed le $conflicts{$mod} ) {
-
-            print <<"EOF";
-
-***
-    This version of Package::Stash conflicts with the version of
-    $mod ($installed) you have installed.
-
-    You will need to upgrade $mod after installing
-    this version of Package::Stash.
-***
-
-EOF
-
-            $found = 1;
-        }
-    }
-
-    return unless $found;
-
-    # More or less copied from Module::Build
-    return if  $ENV{PERL_MM_USE_DEFAULT};
-    return unless -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT));
-
-    sleep 4;
-}
-CHECK_CONFLICTS
-
     my $template = $self->$orig(@_);
 
-    $template =~ s/(use ExtUtils::MakeMaker.*)/$1\n\ncheck_conflicts();/;
-    $template =~ s/(WriteMakefile\()/delete \$WriteMakefileArgs{PREREQ_PM}{'Package::Stash::XS'}\n  unless can_cc();\n\n$1/;
+    my $xs_version = $self->zilla->prereqs->requirements_for('runtime', 'recommends')->as_string_hash->{'Package::Stash::XS'};
+
+    $template =~ s/(WriteMakefile\()/\$WriteMakefileArgs{PREREQ_PM}{'Package::Stash::XS'} = $xs_version\n  if can_cc();\n\n$1/;
 
-    return $template . $can_cc . $check_conflicts;
+    return $template . $can_cc;
 };
 
 __PACKAGE__->meta->make_immutable;