How do I automate the initial CPAN configuration?
Here How do I automate CPAN configuration? I've found some answers which led to some questions. I tried cpan -j config.pm, but as far as I can see it is meant for per installation usage, not for changing the config-file permanently.
With the $CPAN::Config-method the force CPAN::FirstTime to not default to manual-part didn't work here so I tried without it:
#!/usr/bin/perl
use strict;
use warnings;
use Config;
use CPAN;
use CPAN::FirstTime;
$ENV{PERL_MM_USE_DEFAULT}=1;
$ENV{PERL_MM_NONINTERACTIVE}=1;
$E开发者_运维问答NV{AUTOMATED_TESTING}=1;
my $cpan_home = '/home/me/.cpan';
mkdir $cpan_home or die $! if not -d $cpan_home;
mkdir "$cpan_home/CPAN" or die $! if not -d "$cpan_home/CPAN";
CPAN::FirstTime::init( "$cpan_home/CPAN/MyConfig.pm" );
delete $CPAN::Config->{links};
$CPAN::Config->{applypatch} = '';
# ...
$CPAN::Config->{build_dir} = "$cpan_home/build";
$CPAN::Config->{cpan_home} = $cpan_home;
$CPAN::Config->{histfile} = "$cpan_home/histfile";
$CP$CPAN::Config->{keep_source_where} = "$cpan_home/sources";
$CPAN::Config->{make_install_make_command} = 'sudo make';
$CPAN::Config->{mbuild_install_build_command} = 'sudo ./Build';
$CPAN::Config->{prefs_dir} = "$cpan_home/prefs";
# ...
$CPAN::Config->{yaml_module} = 'YAML';
CPAN::HandleConfig->commit("$cpan_home/CPAN/MyConfig.pm");
CPAN::install('Bundle::CPAN');
# ...
# etc.
exit 0;
Is this OK? The only bad thing that I have noticed so far is the waiting, until the cpan-mirror-urls are found. And what is the delete $CPAN::Config->{links}; for?
It looks like you are doing a lot of work. What are you trying to accomplish?
If you want to change the configuration file permanently, just change the configuration file. It's Perl code, so I think you can do everything you need, such as setting the root directory, right in the config file without having to deal with CPAN.pm.
精彩评论