Fabrice Gabolde Fabrice Gabolde - 1 year ago 66
Perl Question

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. 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

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


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

In general, how do I declare this type of dependency using Dist::Zilla?

Answer Source

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:

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

As you can see, that's exactly the same as for the cpanfile or Module::Build.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download