CPAN Requirements File

2019-04-21 18:07发布

问题:

With pip you are able to create a requirements file to specify which libraries to install. Is there an equivalent for perl modules using CPAN?

I came across ExtUtils::MakeMaker, but this seems like the make file is for each module specifically.

I guess to try and give a better idea of what I am asking is if there is a way to do something like

cpan install -r requirements.txt

and then specify which modules to install in that requirements file.

Thanks in advance!

回答1:

I think Carton is what you're looking for.

To start using Carton, install it. Then create a cpanfile with your dependencies:

require 'Test::Most';
require 'Math::BaseConvert';

With this file in place, run

carton install

This will install those modules, if necessary, and write a file called cpanfile.snapshot with dependency information.

Also see: Brief Notes on Managing Perl Dependencies with Carton

PS: Check out Stratopan.



回答2:

When you install modules from CPAN, each module specifies its dependencies in the Makefile.PL (or Build.PL) and the CPAN shell will resolve those dependencies recursively when installing.

If you want to specify dependencies for an application (rather than a CPAN module), you can create a file called cpanfile in this format:

requires 'JSON';
requires 'Template';
requires 'DateTime';
requires 'DBIx::Class';

Then you can install those dependencies with one command:

cpanm --installdeps .

The cpanm command comes from the App::cpanminus distribution and is an alternative tool for installing modules from CPAN.

See the cpanfile docs for more information.