[英]Perlbrew libs management
I have installed perlbrew and installed two Perls with it.我已经安装了 perlbrew 并安装了两个 Perls。 Now I am trying to separate libraries for modules I install with cpanm.
现在,我正在尝试为使用 cpanm 安装的模块分离库。
I want (if possible) to switch to one Perl (within Perlbrew) (for example: 5.22.4) and once I call cpanm install Some::Module
the module will be installed in the separate library, related only to this Perl.我想(如果可能的话)切换到一个 Perl(在 Perlbrew 中)(例如:5.22.4),一旦我调用
cpanm install Some::Module
,模块将安装在单独的库中,仅与这个 Perl 相关。
Then, in the script, I would like to have like the example below:然后,在脚本中,我想像下面的例子一样:
#!/usr/bin/env perl
use strict;
use Some::Module;
print "Content-type:text/html\n\n";
print "Works!";
and that's it.就是这样。 No any other
use lib 'path';
没有任何其他
use lib 'path';
or so.或者。 I tried to use
perlbrew lib create perl-5.22.4@somename
and then switch to it.我尝试使用
perlbrew lib create perl-5.22.4@somename
然后切换到它。
Then call cpanm install Some::Module
and I see the result at the location ~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm
, but when I call my script from a browser I see Error 500
and the logs say "missing module Some::Module, check @INC etc..."
然后调用
cpanm install Some::Module
,我在~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm
位置看到结果,但是当我从浏览器调用我的脚本时,我看到Error 500
和日志显示"missing module Some::Module, check @INC etc..."
What I also found that if I move the ~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm
to ~/perl5/perlbrew/perls/perl-5.22.4/lib/5.22.4/Some/Module.pm
or to /home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux/Some/Module.pm
then the script works.我还发现,如果我将
~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm
移动到~/perl5/perlbrew/perls/perl-5.22.4/lib/5.22.4/Some/Module.pm
或/home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux/Some/Module.pm
然后脚本工作。 And Perl 5.22.4 (in our example) has its own library without need to use use lib 'path';
而 Perl 5.22.4(在我们的示例中)有自己的库,无需使用
use lib 'path';
But, how to set up Perlbrew to switch cpanm automatically to this directory?但是,如何设置 Perlbrew 自动将 cpanm 切换到这个目录?
What I was also trying: cpanm install -l /home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux Some::Module
to specify the target lib dir, but it creates the next tree under /home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux
instead:我也在尝试:
cpanm install -l /home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux Some::Module
指定目标库目录,但是它会在/home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux
下创建下一棵树:
and, sadly, the script throws Error 500
.遗憾的是,脚本抛出
Error 500
。
So, is there a possibility to omit use lib 'path';
那么,是否有可能省略
use lib 'path';
in the script, switching between multiple Perl versions in Perlbrew?在脚本中,在 Perlbrew 中的多个 Perl 版本之间切换?
This all happens on Ubuntu 22.04.这一切都发生在 Ubuntu 22.04。
Update :更新:
When switching to perl-5.22.4@somename and installing Some::Module via cpanm the module appears under the ~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm
as mentioned above, but the CGI script fails with Error 500.当切换到 perl-5.22.4@somename 并通过 cpanm 安装 Some::Module 时,模块出现在
~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm
下,如上所述,但是CGI 脚本失败并出现错误 500。
However, when I execute the next command: perlbrew list-modules
it shows Some::Module as installed under the current Perl (which I am switched to).但是,当我执行下一个命令时:
perlbrew list-modules
它显示 Some::Module 安装在当前 Perl(我切换到)下。 So, this is a dissonance: Perlbrew "sees" the module under the specific Perl, but the CGI script cannot "see" this module under the same Perl.所以,这是一个不和谐:Perlbrew“看到”特定 Perl 下的模块,但 CGI 脚本不能“看到”同一个 Perl 下的这个模块。
Update 2 :更新 2 :
here is the output of the perlbrew info:
这是 perlbrew
perlbrew info:
Current perl:
Name: perl-5.22.4@somename
Path: /home/username/perl5/perlbrew/perls/perl-5.22.4/bin/perl
Config: -de -Dprefix=/home/username/perl5/perlbrew/perls/perl-5.22.4 -Dusesitecustomize -Aeval:scriptdir=/home/username/perl5/perlbrew/perls/perl-5.22.4/bin
Compiled at: Nov 10 2022 23:26:53
perlbrew:
version: 0.96
ENV:
PERLBREW_ROOT: /home/username/perl5/perlbrew
PERLBREW_HOME: /home/username/.perlbrew
PERLBREW_PATH: /home/username/.perlbrew/libs/perl-5.22.4@somename/bin:/home/username/perl5/perlbrew/bin:/home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/bin
PERLBREW_MANPATH: /home/username/.perlbrew/libs/perl-5.22.4@somename/man:/home/username/perl5/perlbrew/perls/perl-5.22.4/man
Update 3 :更新 3 :
The dirs permissions for the libs:库的目录权限:
and
和
@terry0its
is the name of the library (in the example I called it @somename
. @terry0its
是库的名称(在示例中我称之为@somename
。
Update 4:更新 4:
Printing vars:打印变量:
PERL_MB_OPT
PERL_MM_OPT
PERL5LIB
PATH
PERL_LOCAL_LIB_ROOT
with the script:使用脚本:
#!/usr/bin/env perl
print "Content-type:text/html\n\n";
print <<HTML;
Vars:<br>
PERL_MB_OPT = @{[$ENV{"PERL_MB_OPT"}]}<br>
PERL_MM_OPT = @{[$ENV{"PERL_MM_OPT"}]}<br>
PERL5LIB = @{[$ENV{"PERL5LIB"}]}<br>
PATH = @{[$ENV{"PATH"}]}<br>
PERL_LOCAL_LIB_ROOT = @{[$ENV{"PERL_LOCAL_LIB_ROOT"}]}<br>
HTML
Vars :变量:
PERL_MB_OPT
= PERL_MB_OPT
=
PERL_MM_OPT
= PERL_MM_OPT
=
PERL5LIB
= PERL5LIB
=
PATH
= /home/username/.perlbrew/libs/perl-5.22.4@terry0its/bin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/home/username/anaconda3/condabin:/root/Komodo IDE/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts PATH
= /home/username/.perlbrew/libs/perl-5.22.4@terry0its/bin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/ bin:/root/Komodo IDE/bin:/home/username/anaconda3/condabin:/root/Komodo IDE/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local /sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home /用户名/.local/share/JetBrains/Toolbox/scripts
PERL_LOCAL_LIB_ROOT
= PERL_LOCAL_LIB_ROOT
=
Content-type:text/html
内容类型:文本/html
Vars:
变量:
PERL_MB_OPT
= --install_base /home/username/.perlbrew/libs/perl-5.22.4@terry0itsPERL_MB_OPT
= --install_base /home/username/.perlbrew/libs/perl-5.22.4@terry0its
PERL_MM_OPT
= INSTALL_BASE=/home/username/.perlbrew/libs/perl-5.22.4@terry0itsPERL_MM_OPT
= INSTALL_BASE=/home/username/.perlbrew/libs/perl-5.22.4@terry0its
PERL5LIB
= /home/username/.perlbrew/libs/perl-5.22.4@terry0its/lib/perl5PERL5LIB
= /home/用户名/.perlbrew/libs/perl-5.22.4@terry0its/lib/perl5
PATH
= /home/username/.perlbrew/libs/perl-5.22.4@terry0its/bin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/home/username/anaconda3/condabin:/root/Komodo IDE/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scriptsPATH
= /home/username/.perlbrew/libs/perl-5.22.4@terry0its/bin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/ bin:/root/Komodo IDE/bin:/home/username/anaconda3/condabin:/root/Komodo IDE/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local /sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home /用户名/.local/share/JetBrains/Toolbox/scripts
PERL_LOCAL_LIB_ROOT
= /home/username/.perlbrew/libs/perl-5.22.4@terry0itsPERL_LOCAL_LIB_ROOT
= /home/username/.perlbrew/libs/perl-5.22.4@terry0its
Update 5 :更新 5 :
When I switch to a pure perl-5.22.4 (without external lib, like @terry0its) I see the next output for the same scripts (after the restart of the server):当我切换到纯 perl-5.22.4(没有外部库,如 @terry0its)时,我看到相同脚本的下一个 output(在服务器重新启动后):
Vars :变量:
PERL_MB_OPT
= PERL_MB_OPT
=
PERL_MM_OPT
= PERL_MM_OPT
=
PERL5LIB
= PERL5LIB
=
PATH
= /home/username/anaconda3/condabin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/home/arseniigorkin/perl5/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts PATH
= /home/username/anaconda3/condabin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/ home/arseniigorkin/perl5/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin :/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/用户名/.local/share/JetBrains/Toolbox/scripts
PERL_LOCAL_LIB_ROOT
= PERL_LOCAL_LIB_ROOT
=
Content-type:text/html
内容类型:文本/html
Vars:
变量:
PERL_MB_OPT
--install_base "/home/username/perl5"PERL_MB_OPT
--install_base "/home/username/perl5"
PERL_MM_OPT
= INSTALL_BASE=/home/username/perl5PERL_MM_OPT
= INSTALL_BASE=/home/用户名/perl5
PERL5LIB
=PERL5LIB
=
PATH
= /home/username/anaconda3/condabin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/home/username/perl5/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scriptsPATH
= /home/username/anaconda3/condabin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/家/用户名/perl5/bin:/home/用户名/pycharm/bin:/home/用户名/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin :/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/用户名/.local/share/JetBrains/Toolbox/scripts
PERL_LOCAL_LIB_ROOT
= /home/username/perl5PERL_LOCAL_LIB_ROOT
= /home/用户名/perl5
The issue was related to Apache2 server-specific behavior with ENV variables.该问题与带有 ENV 变量的Apache2服务器特定行为有关。
It strips off some environment variables so they are undefined in your CGI scripts.它去除了一些环境变量,因此它们在您的 CGI 脚本中是未定义的。
To have them in the CGI script you simply have to add PassEnv PERL5LIB
into your host conf file and restart the server.要将它们包含在 CGI 脚本中,您只需将
PassEnv PERL5LIB
添加到您的主机配置文件中并重新启动服务器。 Then, voila - you have PERL5LIB
showing correctly in the output of $ENV{PERL5LIB}
all across your site.然后,瞧 - 您的
PERL5LIB
正确显示在整个站点的$ENV{PERL5LIB}
的 output 中。
The example code:示例代码:
<Directory "/home/user/someproject/server/www/public_html/cgi-bin">
AllowOverride All
Options None
Require all granted
Options +ExecCGI
PassEnv PERL5LIB
AddHandler cgi-script .cgi .pl
</Directory>
So, to use Perlbrew and easily switching between Perls and to have automatically handling all your libs (incl. externally created with perlbrew create lib somename
) you have to PASS the PERl5LIB
environment to your CGI scripts explicitly in the Apache configuration file for your host.因此,要使用 Perlbrew 并在 Perls 之间轻松切换并自动处理所有库(包括使用
perlbrew create lib somename
在外部创建),您必须在PERl5LIB
环境传递给 CGI 脚本。
Do not forget to check if your mod_env is enabled in the httpd.conf (main Apache configuration file) as LoadModule env_module modules/mod_env.so
(it must be uncommented).不要忘记检查您的 mod_env 是否在 httpd.conf(主 Apache 配置文件)中启用为
LoadModule env_module modules/mod_env.so
(必须取消注释)。
I hope it will help others to handle easily their Perl libraries of perlbrew with Apache2 server.我希望它能帮助其他人使用 Apache2 服务器轻松处理他们的 Perl perlbrew 库。
Also, the module mod_env allows us to add custom environment variables, that we will be able to use all across the host or a server (it depends on where you put it in - inside the main conf file, your host file , or just into .htaccess
for a particular dir(s) or even page(s)).此外,模块mod_env允许我们添加自定义环境变量,我们将能够在主机或服务器上使用所有这些变量(这取决于你把它放在哪里 - 在主 conf文件中,你的主机文件中,或者只是进入
.htaccess
对于特定的目录甚至页面)。
perlbrew
does two things: perlbrew
做了两件事:
The CGI script isn't launched by a shell. CGI 脚本不是由 shell 启动的。
First, you shouldn't be using PERL5LIB
.首先,您不应该使用
PERL5LIB
。 Why install a custom perl
using perlbrew
and then try to cause it to use modules installed by another perl
?为什么使用
perlbrew
安装自定义perl
然后尝试使其使用另一个perl
安装的模块? This is nothing but bad.这不过是不好的。 Unset
PERL5LIB
.取消
PERL5LIB
。
And with PERL5LIB
unset, you shouldn't be using PERL_MB_OPT
and PERL_MM_OPT
either.在未设置
PERL5LIB
的情况下,您也不应使用PERL_MB_OPT
和PERL_MM_OPT
。 You need to let the modules get installed where perl
will find them.您需要让模块安装在
perl
可以找到它们的位置。
So start by cleaning out the mess.所以从清理混乱开始。 Make sure
PERL5LIB
, PERL_MB_OPT
and PERL_MM_OPT
aren't set anywhere.确保没有在任何地方设置
PERL5LIB
、 PERL_MB_OPT
和PERL_MM_OPT
。 You may to need reinstall the modules if they were installed in a weird place.如果模块安装在奇怪的地方,您可能需要重新安装这些模块。
Now, using the correct perl
will load the modules installed by that perl
.现在,使用正确的
perl
将加载由该perl
安装的模块。
So what left is ensuring that we're using the correct perl
.所以剩下的就是确保我们使用正确的
perl
。 You use /usr/bin/env
to locate perl
.您使用
/usr/bin/env
来定位perl
。 Does it makes sense for Apache's PATH to control which perl
your application uses? Apache 的 PATH 控制您的应用程序使用哪个
perl
是否有意义? Probably not.可能不会。
What I would do is create an alias in perlbrew for your project.我要做的是在 perlbrew 中为您的项目创建一个别名。
perlbrew alias create perl-5.22.4@somename myproject
Then use the following shebang line:然后使用以下 shebang 行:
#!/home/username/perl5/perlbrew/perls/myproject/bin/perl
That will allow you use to control which build of perl
your project uses using这将允许您使用来控制项目使用的
perl
的哪个版本
perlbrew alias create -f ... myproject
This works using symlinks, not PATH manipulation, so it works from anywhere, not just shells using perlbrew
.这适用于符号链接,而不是 PATH 操作,因此它适用于任何地方,而不仅仅是使用
perlbrew
的 shell。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.