How do I tell CPAN to install all dependencies?
I tried setting these in cpan
:
cpan> o conf prerequisites_policy follow
cpan> o co
Maybe it's related to ExtUtils::AutoInstall or Module::AutoInstall being used. Try setting the PERL_AUTOINSTALL environment variable. (Cf. the documentation of those modules.)
I'm writing this for benefit of people who may have come to this page searching for a way to install all module dependencies needed by a particular perl script. I wrote a script for that:
It should be run as ./installdep.pl yourscript.pl
#!/usr/bin/perl
`sudo apt install cpanminus`;
while (<>) {
if (/USE /i)
{
my $line=$_;
$line=~ s/\s//g;
$line=~ /^(.*)\./;
$line=~ s/\;//;
$line=~s/^USE//i;
$line=~s/lib.*//i;
$line=~s/feature.*//i;
$line=~s/strict//i;
$line=~s/warnings//i;
$line =~ s/^(.*)\(.*/$1/;
unless ($line eq '') {
my $cmd='sudo cpanm '.$line;
print "Installing $line \n";
open my $cmd_fh, "$cmd |";
while (<$cmd_fh>) {
print "$_";
}
close $cmd_fh;
print "\n";
}
}
}
This will use cpanminus to install all module dependencies required by your script. If cpanm isnt installed, it will install it.
Changing the following parameter on top of prerequisites_policy follows.
cpan> o conf prerequisites_policy 'follow'
cpan> o conf build_requires_install_policy yes
cpan> o conf commit
This will change it from "ask/yes" to "yes" and stop it asking you.
Try setting PERL_MM_USE_DEFAULT like so:
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install My::Module'
It should make CPAN answer the default to all prompts.
I found this to be, by far, the quickest and most reliable way to install CPAN modules:
yes | perl -MCPAN -e "CPAN::Shell->notest(qw!install Your::Module!)"
Set
prerequisites_policy
in the configuration.
See Config Variables.