试图强制 CPAN 安装在 Strawberry Perl 的特定目录中

Trying to force CPAN to install in specific directory for Strawberry Perl

我在 windows 生产箱上安装了 strawberry perl (v. 5.16.3)。我假设很多个月前,有人将它安装在 C: 驱动器上,然后将它移动到 D:。我不知道,我不在那里,但是它工作正常,除非我尝试安装模块。使用 cpanm 只会将模块扔到 C: 驱动器上。不好。 @INC 不会去那里,管理员也不希望那里有任何东西。我需要在 D:.

上使用 Perl

所以,我尝试使用 cpan 并更改目录:

cpan> o conf mbuildpl_arg "--install_base D:/strawberry/perl"
    mbuildpl_arg       [--install_base D:strawberryperl]
commit: wrote 'D:\strawberry\perl\lib/CPAN/Config.pm'

cpan> o conf makepl_arg "PREFIX=D:/strawberry/perl"
    makepl_arg         [PREFIX=D:/strawberry/perl]
commit: wrote 'D:\strawberry\perl\lib/CPAN/Config.pm'

cpan> install Email::Simple

它在 D:/strawberry/perl/lib 中安装了 Email Simple - 不完美,但可以用。伟大的!其他一些人也经历了同样的事情。去安装Module::Runtime

cpan> install Module::Runtime

在 D:/strawberry/perl/lib/perl5 中。嗯?好的,不完美,但我的@INC 包括 D:/strawberry/perl/lib 所以这应该不是问题,对吧?去安装MooX::Types::MooseLike::Base

cpan> install MooX::Types::MooseLike::Base

不会安装。这是 cpan 吐出的结果:

cpan> install MooX::Types::MooseLike::Base
Running install for module 'MooX::Types::MooseLike::Base'
Running make for M/MA/MATEU/MooX-Types-MooseLike-0.29.tar.gz
Checksum for D:\strawberry\cpan\sources\authors\id\M\MA\MATEU\MooX-Types-MooseLike-0.29.tar.gz ok

  CPAN.pm: Building M/MA/MATEU/MooX-Types-MooseLike-0.29.tar.gz

Checking if your kit is complete...
Looks good
Warning: prerequisite Module::Runtime 0.014 not found.
... Detected uninstalled Perl.  Trying to continue.
Have \strawb~1\perl\lib
Want \strawberry\perl\lib
Writing Makefile for MooX::Types::MooseLike
Writing MYMETA.yml and MYMETA.json
---- Unsatisfied dependencies detected during ----
----  MATEU/MooX-Types-MooseLike-0.29.tar.gz  ----
    Module::Runtime [requires]
Running make test
  Delayed until after prerequisites
Running make install
  Delayed until after prerequisites
Running install for module 'Module::Runtime'
Running Build for Z/ZE/ZEFRAM/Module-Runtime-0.014.tar.gz
  Has already been unwrapped into directory D:\strawberry\cpan\build\Module-Runtime-0.014-yHdcFp
  Has already been made
Running Build test
  Has already been tested successfully
Running Build install
  Already done
Running make for M/MA/MATEU/MooX-Types-MooseLike-0.29.tar.gz
  Has already been unwrapped into directory D:\strawberry\cpan\build\MooX-Types-MooseLike-0.29-UaWuDZ

  CPAN.pm: Building M/MA/MATEU/MooX-Types-MooseLike-0.29.tar.gz

Warning: Prerequisite 'Module::Runtime => 0.014' for 'MATEU/MooX-Types-MooseLike-0.29.tar.gz' already built but the resu
lt looks suspicious. Skipping another build attempt, to prevent looping endlessly.
cp lib/MooX/Types/MooseLike.pm blib\lib\MooX\Types\MooseLike.pm
cp lib/MooX/Types/MooseLike/Base.pm blib\lib\MooX\Types\MooseLike\Base.pm
  MATEU/MooX-Types-MooseLike-0.29.tar.gz
  D:\strawberry\c\bin\dmake.exe -- OK
Running make test
D:\strawberry\perl\bin\perl.exe "-ID:/strawberry/perl/lib" "-ID:/strawberry/perl/lib" "-MExtUtils::Command::MM" "-e" "te
st_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/basic.t ........................ Can't locate Module/Runtime.pm in @INC (@INC contains: D:\strawberry\cpan\build\MooX-
Types-MooseLike-0.29-UaWuDZ\blib\lib D:\strawberry\cpan\build\MooX-Types-MooseLike-0.29-UaWuDZ\blib\arch D:/strawberry/p
erl/lib D:/strawberry/perl/site/lib/MSWin32-x86-multi-thread D:/strawberry/perl/site/lib D:/strawberry/perl/vendor/lib D
:/strawberry/perl/lib .) at D:/strawberry/perl/lib/Moo/_Utils.pm line 23.
BEGIN failed--compilation aborted at D:/strawberry/perl/lib/Moo/_Utils.pm line 23.
Compilation failed in require at D:/strawberry/perl/lib/Moo.pm line 13.
BEGIN failed--compilation aborted at D:/strawberry/perl/lib/Moo.pm line 13.
Compilation failed in require at t/basic.t line 4.
BEGIN failed--compilation aborted at t/basic.t line 4.
t/basic.t ........................ Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t/builder.t ...................... Can't locate Module/Runtime.pm in @INC (@INC contains: D:\strawberry\cpan\build\MooX-
Types-MooseLike-0.29-UaWuDZ\blib\lib D:\strawberry\cpan\build\MooX-Types-MooseLike-0.29-UaWuDZ\blib\arch D:/strawberry/perl/lib D:/strawberry/perl/site/lib/MSWin32-x86-multi-thread D:/strawberry/perl/site/lib D:/strawberry/perl/vendor/lib 

而且这个错误重复了几次,所有的测试都失败了等等

Files=14, Tests=0,  1 wallclock secs ( 0.06 usr +  0.03 sys =  0.09 CPU)
Result: FAIL
Failed 14/14 test programs. 0/0 subtests failed.
dmake.exe:  Error code 130, while making 'test_dynamic'
  MATEU/MooX-Types-MooseLike-0.29.tar.gz
one dependency not OK (Module::Runtime); additionally test harness failed
  D:\strawberry\c\bin\dmake.exe test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
  reports MATEU/MooX-Types-MooseLike-0.29.tar.gz
Running make install
  make test had returned bad status, won't install without force
Stopping: 'install' failed for 'M/MA/MATEU/MooX-Types-MooseLike-0.29.tar.gz'.
Failed during this command:
 MATEU/MooX-Types-MooseLike-0.29.tar.gz       : make_test NO one dependency not OK (Module::Runtime); additionally test
harness failed

那么,问题....

(1) 我需要做什么才能将 Module::Runtime 放在正确的位置?我之前更改目录的尝试对某些人有效,但对这个无效。我更喜欢 D:\strawberry\perl\site\lib - 因为 cpanm 似乎会把它的模块放在那里,但 D:\strawberry\perl\lib 也可以正常工作。

如果我们确定数字 (1) 这没关系,但我很好奇是否有人有答案:

(2) 为什么 cpan 在@INC 的子目录之一中找不到 Module::Runtime?

所以我知道一个答案是在正确的位置重新安装 strawberry,但这是一个具有恒定 运行 Perl 脚本且没有停机时间的生产箱,所以不,这不是一个选项。无论如何,他们不会允许我这样做的。

在此先感谢您的帮助。

您为使用 ExtUtils::MakeMaker 作为安装程序的模块提供的参数与您为使用 Module::Build 作为安装程序的模块提供的参数不一致。选择一个方案并始终如一地使用它。

o conf makepl_arg "INSTALL_BASE=D:/strawberry/perl_modules"
o conf mbuildpl_arg "--install_base D:/strawberry/perl_modules"

不要忘记告诉 Perl 去哪里寻找模块。

set PERL5LIB=D:/strawberry/perl_modules/lib/perl5

虽然这解决了您眼前的问题,但您解决根本问题的方法并不是最好的。只需清除这些值,模块就会安装在正确的位置。

o conf makepl_arg ""
o conf mbuildpl_arg ""
set PERL5LIB=

还要确保您没有覆盖环境变量中的安装位置。

set PERL_MM_OPT=
set PERL_MB_OPT=

最后,您可能需要检查 Config.pmConfig_heavy.pl 是否需要将 C: 更改为 D: