Five ways to install module prereqs by hand

Reading time: 2 minutes

Have you ever tried installing a CPAN module’s dependencies by hand? Imagine that you’ve downloaded a strange tarball or cloned a strange module repository. Running “perl Makefile.PL” or “perl Build.PL” gives you a long list of missing dependencies. How do you quickly install all those dependencies?

Here are some options. See the last for a new way that I just cooked up and released to CPAN.

Use your favorite CPAN client against the current directory 🔗︎

Example:

$ cpan .

Beware that this also installs the module in the current directory, which may not be what you want.

cpanminus is smarter than that if you give it an option

$ cpanm --installdeps .

For Module::Build-based modules: Build installdeps 🔗︎

Example:

$ perl Build.PL
$ Build installdeps

For (some) Module::Install-based modules: make installdeps 🔗︎

Example:

$ perl Makefile.PL
$ make installdeps

Note that this requires the Makefile.PL to use the ‘auto_install’ plugin.

For Dist::Zilla-based modules: dzil listdeps 🔗︎

Example:

$ dzil listdeps | cpanm
# or
$ cpan $(dzil listdeps)

This requires installing Dist::Zilla any any dist.ini dependencies first:

$ cpanm Dist::Zilla
$ dzil authordeps | cpanm

(Notice a pattern here?)

Anything with Makefile.PL or Build.PL: MYMETA and mymeta-requires 🔗︎

Install the latest ExtUtils::MakeMaker, Module::Build and App::mymeta_requires. Then configure as usual and run ‘mymeta-requires’ to get a list of dependencies.

Example:

$ perl Makefile.PL
$ mymeta-requires | cpanm
# or
$ cpan $(mymeta-requires)

A nice feature of ‘mymeta-requires’ is that it gives you access to all the different prerequisite types defined in the CPAN::Meta::Spec. So if a module offers ‘develop’ prerequisites, you can include those like this:

$ mymeta-requires --develop | cpanm

See the documentation for other ways to control which prerequisites are included in the output.

One drawback is that you’ll still need to install any configuration prerequisites needed to run Makefile.PL or Build.PL, but that is true of all other recipes above (except that ones that use a CPAN client).

Update: as of version 0.002, ‘mymeta-requires’ will fallback to a META.json|yml file and also picks up configuration prerequisites. So now you can bootstrap completely like this:

# get configuration prerequisites
$ mymeta-requires | cpanm

# run configuration
$ perl Makefile.PL

# get any additional dynamic prerequisites from configuration
$ mymeta-requires | cpanm

Easy!

•      •      •

If you enjoyed this or have feedback, please let me know by or