[英]Install cpan modules through perl script?
我想要一个运行perl脚本时会自动安装所有cpan模块的perl脚本。能帮上忙吗?
The CPAN
client is just a Perl module which is wrapped by the command line tool. CPAN
客户端只是由命令行工具包装的Perl模块 。 You therefore directly invoke it from a Perl script. 因此,您可以直接从Perl脚本中调用它。
However, you may require system administrator priveleges to install new modules. 但是,您可能需要系统管理员特权才能安装新模块。 One way to circumvent that is to use local::lib
, or to ask the user for the necessary privileges. 规避该问题的一种方法是使用local::lib
或向用户询问必要的特权。 On Unixes, you could refuse to run your script if not run as root. 在Unixes上,如果不以root用户身份运行,则可以拒绝运行脚本。 However, that opens up many security issues and should be avoided if possible. 但是,这带来了许多安全问题,如果可能应避免使用。
A fairly sane solution would be to require your users to install the cpanm
client , and specify your dependencies in a cpanfile
. 一个相当合理的解决方案是要求您的用户安装cpanm
客户端 ,并在cpanfile
指定您的依赖cpanfile
。 Your users then just have to do cpanm --installdeps /dir/of/your/script
. 然后,您的用户只需执行cpanm --installdeps /dir/of/your/script
。
But if we are already going through all that trouble, you might as well make a proper CPAN distribution. 但是,如果我们已经遇到了所有麻烦,那么您不妨进行适当的CPAN分发。 You don't have to upload it to CPAN, but you can distribute the tarball, and have your users install that. 您不必将其上传到CPAN,但是您可以分发tarball,并让您的用户安装它。 This has many advantages: Mature toolchains, automated testing, and wonderful helpers like Dist::Zilla
that make creating a distribution a breeze. 这具有许多优点:成熟的工具链,自动化测试以及Dist::Zilla
等出色的助手,使创建发行版变得轻而易举。
从文档中使用CPAN :: Shell :
CPAN::Shell->install("Acme::Meta");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.