How to tell CPAN.pm to use mini cpan for a specific application?

Is it possible to use mini-CPAN for specific applications (to provide specific versions of modules for different applications and perform installation without network access). The "standard" way of using mini cpan depends on the setting of "o conf urllist" with the file URL in your CPAN / Config.pm

This is great with one mini cpan. However, I need to automate the installation of CPAN from a different directory for each application (local application), since each application has different version requirements.

The following almost work, but then only have a partially working shell and are still retrieved from the Internet instead of using the mini cpan from $file_url location:

 use CPAN; use FindBin qw($Bin); my $file_url="file:///$Bin/../cpan"; CPAN::Shell->o(qw( conf urllist ),$file_url); CPAN::shell(); 
+4
source share
1 answer

You load a different configuration file for each application. The last cpan command has the -j switch to do just that:

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

This last feature is not yet included in the CPAN.pm schedule, as it is experimental. However, I have been using it for several months as part of my DPAN .

If you don't like this, you just need to provide your CPAN::Config module for the specific application where Perl will find it before it finds your personal or public version. Copy the current CPAN / Config.pm to the directory of your application modules and make sure that the directory is first in @INC (possibly using the PERL5LIB environment PERL5LIB ). CPAN.pm should find this first and use it. It uses only the first one found. This is convenient when the configuration is fixed, although it is a little flexible, since you can run the code in the module. It is configured as Perl code.

If this is not enough for you, you can override CPAN::HandleConfig() in your application so that CPAN.pm does not load files. Then you set the values ​​yourself. This is especially convenient when you have a lot of application logic to decide in order to determine some of the configuration values. The CPAN.pm configuration is only the %CPAN::Config hash, so you just need to set the correct values ​​for the corresponding keys.

In any case, you probably want to set the "connect_to_internet_ok" configuration to false and clear your "urllist" to only have local minipacks.

+5
source

All Articles