I have been using Dist::Zilla for a project at work, and I've declared all my dependencies in the [Prereqs / Requires]
section. 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:
# from perldoc cpanm
cpanm Plack~">= 1.0000, < 2.0000" # latest of 1.xxxx
cpanm [email protected] # specific version. same as Plack~"== 0.9990"
Or 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::Prereqs uses CPAN::Meta::Spec to do the prereqs. 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. 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, e.g. 2.4. This means that at least version 2.4 must be present. 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.
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.
For more complicated situations, version specifications may be AND-ed together using commas. 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.
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).
Those versions mean:
>= 1.0000, < 2.0000
Larger or equal to 1.0000 and smaller than 2.0000
== 0.9990
Exactly version 0.9990
= 1.2, != 1.5, < 2.0
Greater or equal to 12 and not 1.5 and smaller than 2.0
As you can see, that's exactly the same as for the cpanfile or Module::Build.
simbaque above was almost right, and Fabrice Gabolde had the rest (I don't know how to link names).
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; leaving this one for posterity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With