简体   繁体   English

如何在具有多个版本的 Perl 的 Perl 模块中处理安装脚本?

[英]How do I handle installing scripts in Perl modules with multiple versions of Perl?

I don't think that this is a duplicate question.我不认为这是一个重复的问题。 This is specifically about scripts that come with Perl modules.这专门针对 Perl 模块附带的脚本。

Typically, when installing multiple Perl versions, you can have the perl executable tagged with a version number ( perl5.32 ) so that they can all sit side by side in /whatever/bin .通常,在安装多个 Perl 版本时,您可以将 perl 可执行文件标记为版本号 ( perl5.32 ),以便它们可以并排放置在/whatever/bin中。 I need to do the same for scripts that come with modules.我需要对模块附带的脚本做同样的事情。 Example: perltidy .示例: perltidy So:所以:

Is there a setting I can throw on the config when I build perl that will automagically [sic] create 'versionated' script names?当我构建 perl 时,我可以在配置中添加一个设置,它会自动 [原文如此] 创建“版本化”脚本名称?

Or, is there something I can set when I call perl Makefile.PL or perl Build.PL when I am building the script to make 'versionated' script names?或者,当我在构建脚本以制作“版本化”脚本名称时调用perl Makefile.PLperl Build.PL时,我可以设置什么?

Yes, there are plenv and perlbrew , but I don't want to use those on the production side, yet there will be a period of time on my production machines when both versions will exist.是的,有plenvperlbrew ,但我不想在生产端使用它们,但是在我的生产机器上会有一段时间同时存在两个版本。 I will be migrating programs over time;我将随着时间的推移迁移程序; I will not be "big-banging" a cut over to a new version one night.一天晚上,我不会“大刀阔斧”地切换到新版本。

I wrote more about this in Make links to per-version tools .我在Make links to per-version tools中写了更多关于此的内容。

I have about 30 perls installed, and I install each manually:我安装了大约 30 个 perls,我手动安装了每个:

$ ./Configure -des -Dprefix=/usr/bin/perls/perl-5.x.y
$ make test install

Now there's something like /usr/bin/perls/perl-5.xy/bin/perl and so on.现在有类似/usr/bin/perls/perl-5.xy/bin/perl之类的东西。 If I want to install modules or scripts for that, I use that cpan :如果我想为此安装模块或脚本,我使用该cpan

$ /usr/bin/perls/perl-5.x.y/bin/cpan ...

When you install through the normal Perl toolchain, the shebang line to point to the perl that installed it (and see the recent Perl.com article Bang Bang for more on that): When you install through the normal Perl toolchain, the shebang line to point to the perl that installed it (and see the recent Perl.com article Bang Bang for more on that):

#!/usr/local/perls/perl-5.32.0/bin/perl
    eval 'exec /usr/local/perls/perl-5.32.0/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;
#!/usr/local/bin/perl

That sufficiently compartmentalizes the different programs from each other and each program knows which perl it should run.这充分区分了不同的程序,每个程序都知道它应该运行哪个perl

Of course, those long paths are too much to type, so I have a program that makes symlinks in ~/bin such that ~/bin/cpan-5.xy points into that.当然,那些长路径输入太多了,所以我有一个程序可以在~/bin中创建符号链接,以便~/bin/cpan-5.xy指向它。 The same program takes any programs it finds in /usr/bin/perls/perl-5.xy/bin and makes similar symlinks.相同的程序采用它在/usr/bin/perls/perl-5.xy/bin中找到的任何程序并创建类似的符号链接。

rhich is my own which -like program that takes a regex: rhich是我自己的which采用正则表达式的程序:

$ rhich 5.32.0 | head -4
/Users/brian/bin/perls/pod_cover5.32.0 → /usr/local/perls/perl-5.32.0/bin/pod_cover
/Users/brian/bin/perls/ppodchecker5.32.0 → /usr/local/perls/perl-5.32.0/bin/ppodchecker
/Users/brian/bin/perls/prove5.32.0 → /usr/local/perls/perl-5.32.0/bin/prove
/Users/brian/bin/perls/plackup5.32.0 → /usr/local/perls/perl-5.32.0/bin/plackup

Along with this, it makes links that use -latest instead of the version so I don't have to remember what I have:除此之外,它还创建了使用-latest而不是版本的链接,因此我不必记住我拥有的内容:

$ rhich latest | head -5
/Users/brian/bin/latest_sha1.pl
/Users/brian/bin/perls/perl-latest → /usr/local/perls/perl-5.32.0/bin/perl
/Users/brian/bin/perls/ptar-latest → /usr/local/perls/perl-5.32.0/bin/ptar
/Users/brian/bin/perls/ttree-latest → /usr/local/perls/perl-5.30.1/bin/ttree
/Users/brian/bin/perls/dprofpp-latest → /usr/local/perls/perl-5.14.4/bin/dprofpp

And somewhere in there, I also just make the bare command name point to whatever is the latest, which is what I want most of the time:在那里的某个地方,我也只是让裸命令名指向最新的,这是我大部分时间想要的:

/Users/brian/bin/perls/perl → /Users/brian/bin/perls/perl-latest

perltidy错误的

And, here's all my perltidy installations:而且,这是我所有的perltidy安装:

$ rhich perltidy
/Users/brian/bin/perls/perltidy5.30.1 → /usr/local/perls/perl-5.30.1/bin/perltidy
/Users/brian/bin/perls/perltidy5.30.0 → /usr/local/perls/perl-5.30.0/bin/perltidy
/Users/brian/bin/perls/perltidy-latest → /usr/local/perls/perl-5.32.0/bin/perltidy
/Users/brian/bin/perls/perltidy5.28.0 → /usr/local/perls/perl-5.28.0/bin/perltidy
/Users/brian/bin/perls/perltidy5.26.1 → /usr/local/perls/perl-5.26.1/bin/perltidy
/Users/brian/bin/perls/perltidy5.30.2 → /usr/local/perls/perl-5.30.2/bin/perltidy
/Users/brian/bin/perls/perltidy5.32.0 → /usr/local/perls/perl-5.32.0/bin/perltidy
/Users/brian/bin/perls/perltidy → /Users/brian/bin/perls/perltidy-latest

Update: having re-read your question, I think I mis-read it the first time.更新:重新阅读您的问题后,我想我第一次读错了。 I will include my first interpretation at the end, as it may be useful.我将在最后包括我的第一个解释,因为它可能有用。

So as I understand it, you wish to install /usr/bin/yourapp-1.1 and then later when people upgrade, you wish to install /usr/bin/yourapp-1.2 ?据我了解,您希望安装/usr/bin/yourapp-1.1 ,然后当人们升级时,您希望安装/usr/bin/yourapp-1.2

Firstly, this seems like a badly thought out idea.首先,这似乎是一个经过深思熟虑的想法。 If your script relies on Your::Module, then as per normal Perl module installations, Your::Module 1.2 will replace Your::Module 1.1 on the system, so if /usr/bin/yourapp-1.1 gets run, it will be running using Your::Module 1.2.如果您的脚本依赖于 Your::Module,那么按照正常的 Perl 模块安装,Your::Module 1.2 将替换系统上的 Your::Module 1.1,因此如果/usr/bin/yourapp-1.1运行,它将是使用 Your::Module 1.2 运行。 (Unless you fatpack it, I guess.) (除非你把它打包,我猜。)

But it certainly is possible.但这当然是可能的。

Simple way is to just use File::Copy in Makefile.PL to copy the unversioned script to a new filename containing the version number, before letting MakeMaker do its thing.简单的方法是使用 Makefile.PL 中的 File::Copy 将未版本控制的脚本复制到包含版本号的新文件名,然后让 MakeMaker 执行其操作。


Earlier Answer较早的答案

If your scripts include a shebang like this:如果您的脚本包含这样的 shebang:

#!perl

Then ExtUtils::MakeMaker will automatically rewrite it to point to the current version of Perl at the time the distribution is being built.然后 ExtUtils::MakeMaker 将自动重写它以指向当前版本的 Perl 在构建分发时。

If your scripts include:如果您的脚本包括:

#!/usr/bin/env perl

Then it won't be rewritten, and the script will be run against whatever version of perl is found in the $PATH environment variable at runtime, which is probably not what you want.然后它不会被重写,并且脚本将针对运行时在 $PATH 环境变量中找到的任何版本的 perl 运行,这可能不是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM