simone
simone

Reputation: 5227

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?

Upvotes: 2

Views: 129

Answers (1)

simbabque
simbabque

Reputation: 54323

I would list both of these as a recommends requirement in your cpanfile. 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::Soften1 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.

Upvotes: 3

Related Questions