如果没有人工干预,cpan / cpanm本地安装的CPAN模块将无法使用

时间:2014-07-13 10:24:06

标签: perl cpan locallib cpanm

我已将我的应用程序打包为Perl模块,无法使用cpancpanm命令进行安装。问题是这些命令 - 当不以root身份运行时 - 将必备模块安装到〜/ perl5目录中。但是,我的〜/ perl5目录不包含在@INC

这导致cpanm的以下令人困惑的输出:

$ cpanm --installdeps .
--> Working on .
Configuring my-module-0.001 ... OK
==> Found dependencies: Image::Size
--> Working on Image::Size
Fetching http://www.cpan.org/authors/id/R/RJ/RJRAY/Image-Size-3.232.tar.gz ... OK
Configuring Image-Size-3.232 ... OK
Building and testing Image-Size-3.232 ... OK
Successfully installed Image-Size-3.232
! Installing the dependencies failed: Module 'Image::Size' is not installed
! Bailing out the installation for my-module-0.001.
1 distribution installed

如您所见,它成功下载,测试和安装Image :: Size模块,但随后尝试使用它并失败。

我知道我可以通过将环境变量$ PERL5LIB设置为“〜/ perl5 / lib / perl5”并将“〜/ perl5 / bin”添加到我的$ PATH来修复此问题,但我真的很喜欢要知道这种情况是如何产生的。我想尽可能简化我的应用程序用户的安装说明,并且我不打算手动修改环境变量。

2 个答案:

答案 0 :(得分:0)

这是我自己解决问题的方法。我切换到Dist::Zilla并为我的用户提出了以下安装说明:

Installation instructions
=========================

To install this program you need Dist::Zilla, which can be installed
by running the following command as root:

    cpan Dist::Zilla

After that, make sure you're in directory where this INSTALL file is,
and run the following command as root:

    dzil install

答案 1 :(得分:0)

如果你正在使用bash,你可以在你的.bashrc文件中安装local :: lib添加这样的东西

# adds $HOME/perl5/bin to PATH
[ $SHLVL -eq 1 ] && eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"

那应该可以解决你的问题。问题在于您的本地系统的配置方式,因此请调整而不是将Dist :: Zilla放入混合中,而不需要它。