本文介绍了使用perlbrew和cpm安装模块-在docker构建期间perlbrew开关不会更改@INC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想在我的项目中使用快速的模块安装程序,而不是cpanm。

I'd like to use fast cpm module installer instead of cpanm in my projects.

我也使用安装目标perl版本。

Also I install target perl version using perlbrew.

根据 cpm -g 选项会将模块安装到当前的@INC

According documentation of cpm -g option will install modules into current @INC

如何在@INC中强制更改Perlbrew Dockerfile?

How to force perlbrew change @INC in Dockerfile ?

以下是我的Dockerfile的一部分

Below is part of my Dockerfile

RUN perl -le 'print for @INC' && \
    perlbrew switch perl-5.31.0 && \
    perl -le 'print for @INC' && \
    cpm install -gv CGI && \
    perlbrew list-modules

当我构建 perl -le'@INC的打印'相同:

/etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1
/usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22
/usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22
/usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base

但是如果我手动执行同样的操作,也可以:

But if I do same manually result is ok:

$ docker run -it pavelsr/xxxhub
root@1a34ea34a3fb:/# perl -le 'print for @INC'
/etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1
/usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22
/usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22
/usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base
.
root@1a34ea34a3fb:/# perlbrew switch perl-5.31.0

A sub-shell is launched with perl-5.31.0 as the activated perl. Run 'exit' to finish it.

root@1a34ea34a3fb:/# perl -le 'print for @INC'
/usr/local/perlbrew/perls/perl-5.31.0/lib/site_perl/5.31.0/x86_64-linux
/usr/local/perlbrew/perls/perl-5.31.0/lib/site_perl/5.31.0
/usr/local/perlbrew/perls/perl-5.31.0/lib/5.31.0/x86_64-linux
/usr/local/perlbrew/perls/perl-5.31.0/lib/5.31.0
root@1a34ea34a3fb:/# cpm install -g CGI
DONE install HTML-Tagset-3.20
DONE install HTML-Parser-3.72
DONE install CGI-4.44
3 distributions installed.
root@1a34ea34a3fb:/# perlbrew list-modules
CGI
HTML::Parser
HTML::Tagset
Perl


推荐答案

对于初学者, 使用...启动子外壳... 表示您设置的 perlbrew 错误。系统提示您将以下内容添加到Shell的启动脚本中:

For starters, "A sub-shell is launched with ..." indicates you have an incorrectly setup perlbrew. You were instructed to add the following to your shell's startup script:

source "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}"/etc/bashrc

否则,将使用后备机制来尝试提供所需的功能

Without this, a fallback mechanism is used to try to provide the desired functionality, but it's completely useless outside of interactive shells.

第二,这是对perlbrew的相当怀疑。如果您的docker脚本按预期工作,将产生深远的影响。那不是好事。您可以使用 perlbrew use ,但是可以直接使用

Secondly, this is a rather dubious use of perlbrew. If your docker script worked as intended, it would have far reaching consequences. That's not a good thing. You could use perlbrew use, but you could instead use the correct perl build directly using

RUN "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}"/perls/perl-5.31.0/bin/perl -S cpm install -gv CGI

在您的情况下,这应该解决为

In your case, this should resolve to

RUN /usr/local/perlbrew/perls/perl-5.31.0/bin/perl -S cpm install -gv CGI

为您服务。

这篇关于使用perlbrew和cpm安装模块-在docker构建期间perlbrew开关不会更改@INC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 16:47