6

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
tvs
  • 737
  • 2
  • 17
  • 33

2 Answers2

10

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.

ThisSuitIsBlackNot
  • 23,492
  • 9
  • 63
  • 110
  • 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 Aug 25 '14 at 20:00
  • @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. – ThisSuitIsBlackNot Aug 25 '14 at 20:08
  • @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. – ThisSuitIsBlackNot Aug 25 '14 at 20:10
  • 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 Aug 25 '14 at 20:24
  • @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. – ThisSuitIsBlackNot Aug 25 '14 at 21:21
  • Re "I was prompted to answer about a long series of questions", The only question is something to the effect of "Do you want cpan to configure itsef? [y]" – ikegami Aug 26 '14 at 15:06
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.

ikegami
  • 367,544
  • 15
  • 269
  • 518