0

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 ?

user59053
  • 41
  • 2
  • 5
  • In Windows - Go to the start and in the Run box type ppm then a window gets opened and their you can find perl modules . You have option mark for install for the perl modules at the top. After clicking that your modules get installed.I believe Path::Class:Rule is found and available in it. – Praveen Sep 13 '14 at 06:12
  • i need to add the logic in my current perl script only . i dont want any manual interference.I have checked the mark for install option as you suggested but i can see it is disabled here. do am i have to update the perl? – user59053 Sep 13 '14 at 06:21
  • Please, don't do that. You can ship the necessary files with your program. Best of all, rewrite your program to use [`File::Spec`](https://metacpan.org/module/File::Spec) and [`File::Find`](https://metacpan.org/module/File::Find) which are core modules. – Borodin Sep 13 '14 at 13:05

3 Answers3

1

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;
tobyink
  • 13,478
  • 1
  • 23
  • 35
0

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?

Polar Bear
  • 6,762
  • 1
  • 5
  • 12
  • Docker alpine gives perl -MCPAN -e 'install File::Which' Can't locate object method "install" via package "File::Which" at -e line 1. – MappaM May 11 '23 at 19:28
0

or use perl -MCPAN -eshell

to use the install [module] from the command line

Marcel Kraan
  • 91
  • 1
  • 9