From 0fc2b360259de3520fb9960564556a62dced18af Mon Sep 17 00:00:00 2001 From: XuehaiPan Date: Tue, 29 Dec 2020 22:11:30 +0800 Subject: [PATCH] Add help for CPAN --- help/_posts/2020-12-29-CPAN.md | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 help/_posts/2020-12-29-CPAN.md diff --git a/help/_posts/2020-12-29-CPAN.md b/help/_posts/2020-12-29-CPAN.md new file mode 100644 index 0000000..08bb404 --- /dev/null +++ b/help/_posts/2020-12-29-CPAN.md @@ -0,0 +1,63 @@ +--- +category: help +layout: help +mirrorid: CPAN +--- + +CPAN 镜像使用帮助 +=================== + +[CPAN](https://www.cpan.org/) (The Comprehensive Perl Archive Network) 镜像源的配置文件为 `MyConfig.pm`(一般位于 `~/.cpan/CPAN/MyConfig.pm`),可使用包管理脚本 `cpan` 进行修改。 + +首先需确保 MyConfig.pm 配置文件存在,在命令行中执行: + +```bash +# 确保 MyConfig.pm 配置文件存在,如不存在则自动生成 +PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'mkmyconfig' + +# 不使用默认配置,手动确认各个配置选项 +perl -MCPAN -e 'mkmyconfig' +``` + +### 在 CPAN Shell 中手动设置镜像 + +在命令行中执行 `cpan` 进入 cpan shell: + +``` +cpan shell -- CPAN exploration and modules installation +Enter 'h' for help. + +# 列出当前的镜像设置 +cpan[1]> o conf urllist + +# 将本站镜像加入镜像列表顶部 +cpan[2]> o conf urllist unshift https://{{ site.hostname }}/CPAN/ + +# 或替换镜像列表,仅保留本站 +cpan[3]> o conf urllist https://{{ site.hostname }}/CPAN/ + +# 保存配置至 MyConfig.pm +cpan[4]> o conf commit + +# 退出 cpan shell +cpan[5]> quit +``` + +将本镜像加入到镜像列表的顶部 + +### 自动设置 + +在命令行中执行: + +```bash +# 若本站不在镜像列表中则将其加入列表顶部 +if ! ( + perl -MCPAN -e 'CPAN::HandleConfig->load();' \ + -e 'CPAN::HandleConfig->prettyprint("urllist")' | + grep -qF 'https://{{ site.hostname }}/CPAN/' +); then + perl -MCPAN -e 'CPAN::HandleConfig->load();' \ + -e 'CPAN::HandleConfig->edit("urllist", "unshift", "https://{{ site.hostname }}/CPAN/");' \ + -e 'CPAN::HandleConfig->commit()' +fi +```