2

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?

1
  • I would put both of them in as recommends, and have a runtime check that blows up if neither is installed. Commented Sep 5, 2022 at 8:30

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.