简体   繁体   中英

Using Dist::Zilla dist.ini how can I set alternate dependencies?

I am building a module that could work with Mojo::SQLite or Mojo::Pg indifferently. How do I handle the dependencies? I've checked Mojo::DB::Results::Role::Struct which works in the same way, and it does not list dependencies at a runtime level.

How should I go about this?

I would list both of these as a recommends requirement in yourcpanfile . This way they are there as dependencies, but they don't get installed unless the user asks for it. I would then add a runtime check into the code that croaks if neither of them is available.

To map this into Dist::Zilla, there are probably a couple of different ways. You can write your own cpanfile and let dzil take it from there, or you can specify dependencies in your dist.ini, or rely on dzil to find them from your sources... or a combination of these.

For WWW::Mechanize , we use a combination. In our dist.ini we specify minimum versions using the Prereqs plugin.

[Prereqs / RuntimeRequires]
perl = 5.008
HTML::Form = 6.08
Scalar::Util = 1.14

[Prereqs / TestRequires]
HTTP::Daemon = 6.12
Test::Memory::Cycle = 1.06
Test::NoWarnings = 1.04
Test::Taint = 1.08

[Prereqs / DevelopRequires]
LWP::Protocol::https = 6.07
Perl::Critic = 0
Perl::Tidy = 0

This is not the complete list of requirements, because AutoPrereqs finds those for us. We just need to set explicit versions.

We then also use Prereqs::Soften 1 to convert requirements down to a lower... requiredness.

[Prereqs::Soften]
module = Compress::Zlib
to_relationship = recommends

This is probably what you would want to do for both of your database modules, too.


1) This dist is in need of being taken over , because the author Kent Fredric sadly passed away after an accident last year.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM