8

Is it possible to install multiple modules using CPAN? I've tried:

perl -MCPAN -e 'install DBIx::Transaction File::Basename::Object'

but I get this error:

Can't locate object method "Transaction" via package "DBIx" at -e line 1

2 Answers 2

13

You need a separate install command for each module:

perl -MCPAN -e 'install DBIx::Transaction; install File::Basename::Object'

If you want to simplify the install process even more, take a look at cpanm, which requires no configuration and by default will install modules without prompting.

You can install both modules with a single cpanm command like this:

cpanm DBIx::Transaction File::Basename::Object

Although as ikegami points out, this is not exactly the same as the first command since you can't specify which version of perl to use.

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

7 Comments

That last command is equivalent to cpan DBIx::Transaction File::Basename::Object (use a cpan and the perl it was installed with), not perl -MCPAN -e 'install DBIx::Transaction; install File::Basename::Object' (use the specified perl). // Not sure how installing a whole new installer is easier than pressnig Enter the first time cpan is used.
@ikegami Thanks, fixed the "equivalent" part. I prefer cpanm over cpan since it is 1) less verbose, 2) doesn't prompt by default, and 3) seems to Just Work more often than cpan. I know you can configure cpan to not prompt and such, but I'd rather install cpanm with a single command and never have to worry about configuration again.
@ikegami Having said that, I can see how my "If you want to simplify the install process even more" bit is an over-generalization. It may not be simpler for someone managing a large number of systems, for example.
It doesn't simplify the process at all. One command to install vs one command to set the prerequisites_policy. In context, it actually complicates the process by getting someone to convert from a known and used system. // As for working, I've never had a single problem with cpan across 3 OSs and 8 version of Perl. // As for verbosity, 99% of the output comes from the installers, not cpan.
@ikegami cpan DBI produced 794 lines of output compared to only 6 for cpanm DBI. The first time I tried installing a module with cpan, I was prompted to answer about a long series of questions about configuration, many of which were utterly meaningless to me as someone new to Perl. I had to do that on every system I wanted to install a module on, which was annoying enough that I just installed cpanm and never bothered with cpan again. I think cpanm is more beginner friendly than cpan, hence my recommendation.
|
10
cpan DBIx::Transaction File::Basename::Object

Use the cpan that was installed by the perl for which you want to install.


If you have problems installing for the correct perl, explicitly use the correct perl.

.../perl -S cpan DBIx::Transaction File::Basename::Object

or

.../perl -MCPAN -e'install($_) for @ARGV' DBIx::Transaction File::Basename::Object

The problem you have is the unquoted use of DBIx::Transaction.

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.