我打算创建一个空的本地 CPAN 目录,然后使用正确的版本号注入我需要的模块。
因此,我使用 CPAN::Mini 创建了一个 CPAN 结构,如下所示:
my $local = '/tmp/CPAN';
my $minicpan = CPAN::Mini->new(
remote => "http://mirrors4.kernel.org/cpan/",
local => $local,
passive => 'yes',
dirmode => 0755,
repository => $local,
module_filters => [ sub { $_[0] !~ m/No::Giro/i } ], #Thus us just to fetch this module only
trace => 1
);
mkdir($local."/authors") or die("Could not create authors folder");
mkdir($local."/modules") or die("Could not create modules folder");
my @files = ('authors/01mailrc.txt.gz', 'modules/02packages.details.txt.gz', 'modules/03modlist.data.gz');
foreach my $file (@files){
print "Creating file $local/$file \n";
open(FILE, "+> $local/$file") or die("Could not create $local/$file");;
close (FILE);
}
然后我尝试使用 CPAN::Mini::Inject 注入一个模块:
use strict;
use warnings;
use Getopt::Long;
use CPAN::Mini::Inject;
my $module = undef;
my $authorid = undef;
my $version = undef;
my $file = undef;
GetOptions(
"module=s" => \$module,
"authorid=s" => \$authorid,
"version=s" => \$version,
"file=s" => \$file,
);
die ("--module not provided") if(!defined($module) || $module eq '');
die ("--authorid not provided") if(!defined($authorid) || $authorid eq '');
die ("--version not provided") if(!defined($version) || $version eq '');
die ("--file not provided") if(!defined($file) || $file eq '');
die("File $file does not exists") unless ((-e $file) || (-f $file) );
my $mcpi = CPAN::Mini::Inject->new;
$mcpi->loadcfg('/tmp/minicpan.conf');
$mcpi->parsecfg();
$mcpi->readlist();
$mcpi->add(
module => $module,
authorid => $authorid,
version => $version,
file => $file );
$mcpi->inject(1);
$mcpi->writelist();
exit(0);
但是 03modlist.data.gz 文件没有得到更新(所以它是空的),所以当我尝试将 cpan 与本地存储库一起使用时,我得到与该文件相关的错误。有谁知道如何生成有效的 modlist 文件?或者如何让 CPAN::Mini 或 CPAN::Mini::Inject 为你做这件事?
此致