user59053
user59053

Reputation: 51

how to install cpan modules using system command - perl

I am using Windows operating system and i have my running perl script.In my script Path::Class::Rule module i am using .

My script is not able to run, on some of the system, because the above mentioned module is not installed.So i need to add a logic for pre-setup which will check whether all the required module is installed on the system or not if not then install the module first then do rest of the processing.

I am trying to install the module using system subroutine but perl modules are not getting install.

Here is the code which i am using:

use warnings;
use Path::Class;
use Path::Class::Rule;
use Cwd qw();
use File::Path qw(make_path);
use File::Copy;
system ("ppm install Path::Class::Rule");

can any body help me out how to add the logic ?

Upvotes: 1

Views: 5142

Answers (3)

Marcel Kraan
Marcel Kraan

Reputation: 107

or use perl -MCPAN -eshell

to use the install [module] from the command line

Upvotes: 0

Polar Bear
Polar Bear

Reputation: 6808

Your logic is flawed -- your code should not check for missing modules (it will be done on each run).

You can install CPAN modules with following command

perl -MCPAN -e 'install [MODULE]'

You could use batch or cmd installation file to install all required modules.

You could use perl installation script which will verify what modules are missing and install them.

NOTE: Your post is not clear if you refer to install script or not.

You need read documentation 'perl module installation'

How to install CPAN modules

How to install CPAN modules

What's the easiest way to install a missing Perl module?

Upvotes: 0

tobyink
tobyink

Reputation: 13664

Look at this:

use Path::Class::Rule;
...;
system ("ppm install Path::Class::Rule");

You're trying to use the module before installing it.

Try something like this:

BEGIN {
   eval { require Path::Class::Rule }
      or system("ppm install Path::Class::Rule");
}
use Path::Class::Rule;

Though personally I think a better idea is something like:

BEGIN {
   eval { require Path::Class::Rule }
      or die "Missing Path::Class::Rule. See README for installation instructions.\n";
}
use Path::Class::Rule;

Upvotes: 2

Related Questions