简体   繁体   English

使用Dist :: Zilla声明对特定版本的Perl模块的依赖性

[英]Declaring dependencies on specific versions of Perl modules using Dist::Zilla

I have been using Dist::Zilla for a project at work, and I've declared all my dependencies in the [Prereqs / Requires] section. 我一直在使用Dist :: Zilla进行工作,我已经在[Prereqs / Requires]部分声明了所有依赖项。 That's fine so far. 到目前为止这很好。

Now I found that the latest version of one of my dependencies breaks backwards compatibility, so I want to limit the range of versions that I depend on. 现在我发现我的一个依赖项的最新版本打破了向后兼容性,所以我想限制我依赖的版本范围。 Something like what cpanm supports: cpanm支持的东西:

# from perldoc cpanm
cpanm Plack~">= 1.0000, < 2.0000"  # latest of 1.xxxx
cpanm Plack@0.9990                 # specific version. same as Plack~"== 0.9990"

Or Module::Build : 或者Module::Build

'Other::Module' => '>= 1.2, != 1.5, < 2.0',

In general, how do I declare this type of dependency using Dist::Zilla? 一般来说,如何使用Dist :: Zilla声明这种类型的依赖?

Dist::Zilla::Prereqs uses CPAN::Meta::Spec to do the prereqs. Dist :: Zilla :: Prereqs使用CPAN :: Meta :: Spec来执行先决条件。 That doc describes the syntax in the Version Ranges chapter. 该文档描述了版本范围章节中的语法。

Some fields (prereq, optional_features) indicate the particular version(s) of some other module that may be required as a prerequisite. 某些字段(prereq,optional_features)表示可能需要作为先决条件的某些其他模块的特定版本。 This section details the Version Range type used to provide this information. 本节详细介绍用于提供此信息的版本范围类型。

The simplest format for a Version Range is just the version number itself, eg 2.4. 版本范围的最简单格式只是版本号本身,例如2.4。 This means that at least version 2.4 must be present. 这意味着至少必须存在版本2.4。 To indicate that any version of a prerequisite is okay, even if the prerequisite doesn't define a version at all, use the version 0. 要指示任何版本的先决条件都可以,即使先决条件根本没有定义版本,也请使用版本0。

Alternatively, a version range may use the operators < (less than), <= (less than or equal), > (greater than), >= (greater than or equal), == (equal), and != (not equal). 或者,版本范围可以使用运算符<(小于),<=(小于或等于),>(大于),> =(大于或等于),==(相等),和!=(不等于)。 For example, the specification < 2.0 means that any version of the prerequisite less than 2.0 is suitable. 例如,规范<2.0意味着小于2.0的任何先决条件版本都是合适的。

For more complicated situations, version specifications may be AND-ed together using commas. 对于更复杂的情况,可以使用逗号将版本规范一起进行AND编辑。 The specification >= 1.2, != 1.5, < 2.0 indicates a version that must be at least 1.2, less than 2.0, and not equal to 1.5. 规范> = 1.2,!= 1.5,<2.0表示版本必须至少为1.2,小于2.0,不等于1.5。

So your prereqs would become: 所以你的先决条件将成为:

[Prereqs]
Plack = >= 1.0000, < 2.0000
Plack = == 0.9990
Other::Module = >= 1.2, != 1.5, < 2.0

Note the single = that separates the module name (key) from the version or version range (value). 请注意,single =将模块名称(键)与版本或版本范围(值)分开。

Those versions mean: 这些版本意味着:

  • >= 1.0000, < 2.0000 > = 1.0000,<2.0000

    Larger or equal to 1.0000 and smaller than 2.0000 大于或等于1.0000且小于2.0000

  • == 0.9990 == 0.9990

    Exactly version 0.9990 完全版本0.9990

  • = 1.2, != 1.5, < 2.0 = 1.2,!= 1.5,<2.0

    Greater or equal to 12 and not 1.5 and smaller than 2.0 大于或等于12而不是1.5且小于2.0

As you can see, that's exactly the same as for the cpanfile or Module::Build. 如您所见,这与cpanfile或Module :: Build完全相同。

simbaque above was almost right, and Fabrice Gabolde had the rest (I don't know how to link names). 上面的simbaque几乎是正确的,Fabrice Gabolde有其余的(我不知道如何链接名字)。

The way to do this: 这样做的方法:

[Prereqs]
Plack = >= 1.000, < 2.000
Other::Module = == 1.0
Other::Other::Module = >= 1.2, != 1.5, < 2.0

ETA: simbaque has since corrected their answer; ETA:simbaque已经纠正了他们的答案; leaving this one for posterity. 留下这个为后代。

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

相关问题 是否可以使用Dist :: Zilla的可选依赖项? - Are optional dependencies with Dist::Zilla possible? 使用Dist :: Zilla从Perl模块版本中排除目录 - Exclude a directory from Perl module release using Dist::Zilla 如何使用 DIst::Zilla 构建 Perl 发行版并将 Carton 用于依赖项? - How can I build a Perl distribution with DIst::Zilla and use Carton for dependencies? 使用 Dist::Zilla dist.ini 如何设置备用依赖项? - Using Dist::Zilla dist.ini how can I set alternate dependencies? 如何在 dist.ini (Dist::Zilla) 中列出多个“.pm”模块 - How to list multiple “.pm” modules in dist.ini (Dist::Zilla) 如何让Dist :: zilla在YAML中指定最小Perl版本? - How to have Dist::zilla specifying min Perl version in YAML? 如何在Dist :: Zilla dist.ini中为我的发行版指定最低perl版本? - How do I specify a minimum perl version for my distribution in Dist::Zilla dist.ini? 如何使基于Dist :: Zilla的Perl模块(或应用程序)将文件安装到/ etc /? - How to make a Dist::Zilla based Perl module (or app) install files into /etc/? 由于Debian Wheezy上的Net :: SSLeay而未安装Perl Dist :: Zilla - Perl Dist::Zilla doesn't install because of Net::SSLeay on Debian Wheezy 使用 Dist::Zilla dist.ini 如何获得仅用于测试的文件? - Using Dist::Zilla dist.ini how can I have files that I only use for testing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM