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

时间:2021-04-22 07:07:37

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). The 'standard' mini-cpan way of things relies on setting 'o conf urllist' with a file url in your CPAN/Config.pm

有没有办法使用特定于应用程序的迷你CPAN(以确保不同应用程序的特定模块版本,并使安装工作没有网络访问)。 '标准'mini-cpan方式依赖于在CPAN / Config.pm中使用文件URL设置'o conf urllist'

That's fine with one single mini-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就好了。但是,我需要为每个应用程序(应用程序本地)从不同目录自动安装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();

1 个解决方案

#1


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. I've been using it for several months, however, as part of my DPAN work.

此最新功能尚未包含在CPAN.pm发行版中,因为它是实验性的。然而,作为我的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. 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.pm should find that one first and use it. 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.

如果您不喜欢这些,您只需提供特定于应用程序的CPAN :: Config模块,Perl会在找到您的个人或站点范围版本之前找到它。将当前的CPAN / Config.pm复制到应用程序模块目录中,并确保该目录位于@INC中(可能使用PERL5LIB环境变量)。 CPAN.pm应首先找到它并使用它。它只使用它找到的第一个。这在配置修复时很方便,但由于您可以在模块中运行代码,因此它有点灵活。它的配置为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. 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 :: HandleConfig(),这样CPAN.pm就不会加载任何文件。然后,您自己设置值。当您有许多应用程序逻辑要解决以找出某些配置值时,这尤其方便。 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。

#1


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. I've been using it for several months, however, as part of my DPAN work.

此最新功能尚未包含在CPAN.pm发行版中,因为它是实验性的。然而,作为我的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. 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.pm should find that one first and use it. 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.

如果您不喜欢这些,您只需提供特定于应用程序的CPAN :: Config模块,Perl会在找到您的个人或站点范围版本之前找到它。将当前的CPAN / Config.pm复制到应用程序模块目录中,并确保该目录位于@INC中(可能使用PERL5LIB环境变量)。 CPAN.pm应首先找到它并使用它。它只使用它找到的第一个。这在配置修复时很方便,但由于您可以在模块中运行代码,因此它有点灵活。它的配置为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. 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 :: HandleConfig(),这样CPAN.pm就不会加载任何文件。然后,您自己设置值。当您有许多应用程序逻辑要解决以找出某些配置值时,这尤其方便。 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。