Subject: | Module::Build can use the wrong Perl and install the module in the wrong location |
Assuming the goal of Module::Build's find_perl_interpreter method is to determine the full path to the Perl interpreter that is currently running, then it gets it wrong. It relies heavily on $Config{perlpath} being correct, but there's no guarantee of that and it's often wrong in many common cases. One such case is if you install a version of Perl, say 5.6.1, and, then some number of months later, you install a new version of Perl, say 5.8.0, in the same directory, say /usr/local/. Your /usr/local/bin will have the following Perl executables: perl5.6.1, perl5.8.0, and perl, which perl being a hard link to perl5.8.0. Now let's say you have some application which works only with perl5.6.1 but not perl5.8.0. Perhaps there's a bug in perl5.8.0 or whatever. Now suppose this 5.6.1-only application needs some module that utilizes Module::Build installation. When the user invokes "perl5.6.1 Build.PL", Module::Build actually ends up using perl5.8.0 and installing the module in the 5.8.0 directory instead of the 5.6.1 directory that the user wanted. The workaround is to invoke it as "/usr/local/bin/perl5.6.1 Build.PL" instead, but, for someone who has been using MakeMaker to install modules for many years, this will come as a big surprise when you find out you've installed the module in the wrong location. ExtUtils::MM's init_PERL method (see also EU::MM's find_perl) gets it right, and I think in your attempt to simplify the implementation for Module::Build you may have oversimplified. If you want to keep things simple, File::Spec->canonpath($^X) works better if you require a recent enough version of File::Spec (doesn't work with the version of File::Spec that ships with 5.6.1, for example). In any event, please consider incorporating EU::MM's init_PERL algorithm for determining the full path to the currently running Perl into Module::Build.
% perl5.6.1 -MModule::Build -e 'print Module::Build->new('dist_name' => 'foo', 'dist_version' => 1.0)->find_perl_interpreter,"\n"'
/usr/local/bin/perl <-- actually perl5.8.0!!!
% /usr/local/bin/perl5.6.1 -MModule::Build -e 'print Module::Build->new('dist_name' => 'foo', 'dist_version' => 1.0)->find_perl_interpreter,"\n"'
/usr/local/bin/perl5.6.1
Compare this with the result you get from ExtUtils::MM:
% perl5.6.1 -MExtUtils::MM -e 'print ExtUtils::MM->new({ 'NAME' => 'foo' })->{PERL},"\n"'
/usr/local/bin/perl5.6.1