Releasing a module with additional dependencies
Alex Balhatchet
kaoru at slackwise.net
Tue Apr 15 16:00:25 BST 2014
On 15 April 2014 15:39, Leo Lapworth <leo at cuckoo.org> wrote:
> Make is a mandatory dependency.
>
> This is what every other CPAN module does and is easiest for your module
> users.
I've actually tried to do optional dependencies a couple of times.
Once it was a complete disaster, and once it worked quite well.
The Complete Disaster: Geo::Coder::Many
I tried to implement optional dependencies in Build.PL / Module::Build.
https://metacpan.org/source/KAORU/Geo-Coder-Many-0.45/Build.PL
The logic is supposed to be "if the user has it installed already, at
least make sure it's a recent enough version, but if the user doesn't
have it installed then it's not a dependency".
The alternative would have been making Geo::Coder::Many depend on all
of the different Geo::Coder modules it has plugins for, even if the
user only wanted to interface with Yahoo! PlaceFinder and nothing
else, for example.
To be honest in hindsight that probably would have been better :-)
This was way more trouble than it was worth, and has been a constant
source of pain for the authors of the module and for people trying to
install the module. I recommend strongly against trying to use
Module::Build or ExtUtils::MakeMaker-based "optional dependencies"
solutions.
The Success: App::highlight
App::highlight likes you to have, but doesn't require you to have,
Term::ANSIColor or Win32::Console::ANSI installed depending on your
platform.
https://metacpan.org/source/KAORU/App-highlight-0.14/lib/App/highlight.pm
It has a good fall back behaviour if neither module is available, and
the dependency is well documented.
https://metacpan.org/pod/App::highlight#Color-Support
I also recommend using Test::Without::Module to test both behaviours.
https://metacpan.org/source/KAORU/App-highlight-0.14/t/05-nocolors.t
-----
But in general I would agree with Leo's suggestion to avoid doing
either, and just set it as a mandatory dependency, unless you have a
really good reason :-)
Hope that's useful,
- Alex
More information about the london.pm
mailing list