一个Perl脚本,可以安装自己的CPAN的依赖? [英] Can a Perl script install its own CPAN dependencies?

查看:230
本文介绍了一个Perl脚本,可以安装自己的CPAN的依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了存在于CPAN两个依赖的Perl脚本。我想要做的是的有脚本本身的提示用户安装必要的依赖这样的脚本将正常运行。如果用户需要某种身份验证,进入安装这很好的相关性:我想要避免如下流程:

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:

运行脚本 - >看着它失败 - > CPAN冲刷漫无目的地 - >林奇编剧

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

可以这样做?

推荐答案

每个标准构建范式都有自己指定的依赖方式。在所有这些情况下,构建过程将尝试在某些情况下自动安装你的依赖。

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.

的ExtUtils :: MakeMaker的 ,您通过在 preREQ_PM 字段设置为 WriteMakefile 散列引用:

# Makefile.PL for My::Module
use ExtUtils::MakeMaker;

WriteMakefile (
    NAME => 'My::Module',
    AUTHOR => ...,
    ...,
    PREREQ_PM => {
        'Some::Dependency' => 0,             # any version
        'Some::Other::Dependency' => 0.42,   # at least version 0.42
        ...
    },
    ...
 );

模块::建设 ,你传递一个hashref的 build_requires 字段:

In Module::Build, you pass a hashref to the build_requires field:

# Build.PL
use Module::Build;
...
my $builderclass = Module::Build->subclass( ... customizations ... );
my $builder = $builderclass->new(
    module_name => 'My::Module',
    ...,
    build_requires => {
        'Some::Dependency' => 0,
        'Some::Other::Dependency' => 0.42,
    },
    ...
);
$builderclass->create_build_script();

模块::安装 ,你执行一个或多个 要求 调用命令写Makefile文件之前,命令:

In Module::Install, you execute one or more requires commands before calling the command to write the Makefile:

# Makefile.PL
use inc::Module::Install;
...
requires 'Some::Dependency' => 0;
requires 'Some::Other::Dependency' => 0.42;
test_requires 'Test::More' => 0.89;
...
WriteAll;

这篇关于一个Perl脚本,可以安装自己的CPAN的依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆