Perl 脚本可以安装自己的 CPAN 依赖项吗?
我有一个 Perl 脚本,它有两个存在于 CPAN 中的依赖项。我想做的是让脚本本身提示用户安装必要的依赖项,以便脚本能够正常运行。如果用户需要输入某种身份验证来安装依赖项,那没问题:我试图避免的是以下工作流程:
运行脚本->看着它失败->漫无目的地搜索CPAN ->编剧林奇
相反,我希望得到类似的东西:
运行脚本->自动下载脚本依赖项(根据需要进行身份验证)->脚本成功->给编剧买瓶啤酒
这可以吗?
I have a Perl script that has two dependencies that exist in CPAN. What I'd like to do is have the script itself prompt the user to install the necessary dependencies so the script will run properly. If the user needs to enter in some kind of authentication to install the dependencies that's fine: what I'm trying to avoid is the following workflow:
Run script -> Watch it fail -> Scour CPAN aimlessly -> Lynch the script writer
Instead I'm hoping for something like:
Run script -> Auto-download script dependencies (authenticating as necessary) -> Script succeeds -> Buy the script writer a beer
Can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个标准构建范例都有自己的指定依赖关系的方式。在所有这些情况下,构建过程将尝试在某些上下文中自动安装您的依赖项。
在
ExtUtils::MakeMaker
中,您在PREREQ_PM
字段到WriteMakefile
:在
Module::Build
,将 hashref 传递给build_requires
字段:在
Module::Install
,你执行一个或多个需要
命令才能调用命令来写入Makefile:Each of the standard build paradigms has their own way of specifying dependencies. In all of these cases, the build process will attempt to install your dependencies, automatically in some contexts.
In
ExtUtils::MakeMaker
, you pass a hash reference in thePREREQ_PM
field toWriteMakefile
:In
Module::Build
, you pass a hashref to thebuild_requires
field:In
Module::Install
, you execute one or morerequires
commands before calling the command to write the Makefile:您可能可以从脚本内部执行此操作。
perl -MCPAN -e '安装 MyModule::MyDepends'
You can probably just execute this from inside your script.
perl -MCPAN -e 'install MyModule::MyDepends'