为 CPAN(和 CorporatePAN)打包 perl 脚本的推荐方法是什么?
最近我看了CPAN上的一个模块,它带有一个要安装的脚本 这让我想知道。将脚本包含在包中的推荐方法是什么 应该最终出现在公共 CPAN 上,如果有任何不同的建议 将在内部 CPAN 服务器上发布的软件包?
脚本是这样开始的:
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
两个问题
我是否正确理解了 eval 部分是不必要的? 这将在安装过程中由 CPAN 客户端嵌入,并且它 在 Windows 上安装时会有很大不同。
推荐的 sh-bang 线是什么? 那可以
#!/usr/bin/env perl
代替上面的吗?
Recently I looked at a module on CPAN that comes with a script to be installed
which made me wonder. What is the recommended way to include a script in a package
that should end up on the public CPAN and if there is any different recommendation for
packages that would be released on an in-house CPAN server?
The script starts like this:
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
Two questions
Do I understand correctly the eval part is unnecessary?
That will be embedded by the CPAN client during installation and it
will be very different when installing on Windows.
What is the recommended sh-bang line?
Would that be
#!/usr/bin/env perl
instead of the above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需使用
(或者,可选地,无论您的开发计算机上的
perl
路径如何。)当 Module::Build 或 MakeMaker 安装您的脚本时,它将更改
#!
行以匹配正在安装模块的perl
。它还将添加“eval exec”行,但在 Windows 下除外,它将创建一个.bat
文件。 (CPAN 客户端与此无关。)如果您使用
,安装程序将不会意识到这是一个 Perl 脚本,并且不会修改
#!
行。Just use
(Or, optionally, whatever the path to
perl
is on your development machine.)When Module::Build or MakeMaker installs your script, it will change the
#!
line to match theperl
that is installing the module. It will also add the "eval exec" lines, except under Windows, where it will create a.bat
file instead. (The CPAN client has nothing to do with this.)If you use
then the installers won't realize that's a Perl script, and will not modify the
#!
line.安装发行版时,它是针对某些特定的 perl 安装的,并且应该显式设置 #!使用该 perl(如
$Config{startperl}
中给出)。据我所知,所有模块安装程序都会为您执行此操作。 (更新:正如 cjm 所指出的,只有当分布式的 #! 运行 perl,而不是 env 时。)传统上包含 eval 的东西是为了自动使用 perl,即使使用
sh scriptname
调用脚本也是如此。这是无害的。When the distribution is being installed, it is being installed for some particular perl, and should explicitly set the #! to use that perl (as given in
$Config{startperl}
). As far as I know all the module installers do this for you. (Update: as noted by cjm, only if the #! as distributed runs perl, not env.)The eval stuff is traditionally included to automatically use perl even if a script is invoked with
sh scriptname
. It's harmless.