简体   繁体   English

如何告诉CPAN.pm使用特定于应用程序的mini-cpan?

[英]How do I tell CPAN.pm to use an application-specific mini-cpan?

Is there a way to use app-specific mini-CPANs (to ensure specific module versions for different apps and make an install work without net access). 有没有办法使用特定于应用程序的迷你CPAN(以确保不同应用程序的特定模块版本,并使安装工作没有网络访问)。 The 'standard' mini-cpan way of things relies on setting 'o conf urllist' with a file url in your CPAN/Config.pm '标准'mini-cpan方式依赖于在CPAN / Config.pm中使用文件URL设置'o conf urllist'

That's fine with one single mini-cpan. 一个迷你cpan就好了。 However, I need to automate having a CPAN install from a different directory for each app (local to the app), as each app has different version requirements. 但是,我需要为每个应用程序(应用程序本地)从不同目录自动安装CPAN,因为每个应用程序都有不同的版本要求。

The following almost works, but then has only a partially working shell, and still fetches from the web instead of using the mini-cpan from $file_url location: 以下几乎可以工作,但之后只有一个部分工作的shell,仍然从网上取来而不是使用$file_url位置的mini-cpan:

use CPAN;
use FindBin qw($Bin);

my $file_url="file:///$Bin/../cpan";
CPAN::Shell->o(qw( conf urllist ),$file_url);

CPAN::shell();

You load a different configuration file for each application. 您为每个应用程序加载不同的配置文件。 The latest cpan command has a -j switch to do just that: 最新的cpan命令有一个-j开关来做到这一点:

$ cpan -j some/app/Config.pm -i Foo::Bar

This latest feature isn't included in the CPAN.pm distribution yet since it's experimental. 此最新功能尚未包含在CPAN.pm发行版中,因为它是实验性的。 I've been using it for several months, however, as part of my DPAN work. 然而,作为我的DPAN工作的一部分,我已经使用了几个月。

If you don't like any of that, you just have to provide your application-specific CPAN::Config module somewhere Perl will find it before it finds your personal or site-wide version. 如果您不喜欢这些,您只需提供特定于应用程序的CPAN::Config模块,Perl会在找到您的个人或站点范围版本之前找到它。 Copy your current CPAN/Config.pm into your application modules directory and ensure that the directory is first in @INC (perhaps using the PERL5LIB environment variable). 将当前的CPAN / Config.pm复制到应用程序模块目录中,并确保该目录位于@INC中(可能使用PERL5LIB环境变量)。 CPAN.pm should find that one first and use it. CPAN.pm应首先找到它并使用它。 It only uses the first one it finds. 它只使用它找到的第一个。 This is handy when the configuration is fixed, although it's a bit flexible since you can run code in the module. 这在配置修复时很方便,但由于您可以在模块中运行代码,因此它有点灵活。 It's configuration as Perl code. 它的配置为Perl代码。

If that is not good enough for you, you can override CPAN::HandleConfig() in your application so CPAN.pm doesn't load any files. 如果这对您来说不够好,您可以在应用程序中覆盖CPAN::HandleConfig() ,这样CPAN.pm就不会加载任何文件。 You then set the values yourself. 然后,您自己设置值。 This is especially handy when you have a lot of application logic to resolve to figure out some of the configurations values. 当您有许多应用程序逻辑要解决以找出某些配置值时,这尤其方便。 The CPAN.pm configuration is just the %CPAN::Config hash, so you just have to set the right values for the appropriate keys. CPAN.pm配置只是%CPAN::Config哈希,因此您只需为相应的键设置正确的值。

In any case, you probably want to set the "connect_to_internet_ok" configuration to a false value and clean out your "urllist" to have only the local minicpans. 在任何情况下,您可能希望将“connect_to_internet_ok”配置设置为false值并清除“urllist”以仅包含本地minicpans。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM