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!
5 Comments
"Have you ever tried installing a CPAN module's dependencies by hand?"
Yes, back in the days when I had to compile Perl by hand. Try installing XML::Parser and compiling the Expat library by hand. It' a treat, not. These days I don't bother. If cpan fails, I whine and bitch until someone fixes it. :)
One more option to add to the list. If you are a
cpanpuser, there is a plugin that adds the/prereqscommand.First, install the plugin:
$ cpanp i CPANPLUS::Shell::Default::Plugin::Prereqs
Then use the /prereqs command:
# Install the prereqs for the project in the cwd:
$ cpanp /prereqs install .
# Show the prereqs for any module:
$ cpanp /prereqs show Moose
See the docs for CPANPLUS::Shell::Default::Plugin::Prereqs for more details.
I'm the plugin author, so this has been a shameless plug. To be honest, I've been using
cpanmquite a bit lately. My one complaint aboutcpanm(which brings me back tocpanpand this plugin) is thatcpanmlacks integration withTest::Reporter.I have no problem with shameless plugs. Thanks for pointing out another way to do it!
Goodness. Thanks!
You're welcome. :-)
One Trackback
[...] 2011-08-13 by dagolden Posted by briang Filed in Uncategorized Tags: cpan, cpanm, perl Leave a Comment » [...]