perl script to check if perl modules are installed

前端 未结 4 1415
无人共我
无人共我 2021-01-20 19:27

I\'d like to be able to run this test on each module in the list. Not sure how to ger perl looping over each item.

use Module::Load;
eval {
  load Image::Mag         


        
4条回答
  •  感动是毒
    2021-01-20 20:23

    full script

      # a around M42's answer with some more user-kindness ...
      use strict ; use warnings ; 
      use 5.10.0 ; 
    
      #  quick and dirty check for prerequisites perl modules:
      #  courtesy of:http://stackoverflow.com/a/9340304/65706
      #  if you have a calling bash script call by :
      #  perl "/path/to/isg_pub_preq_cheker.pl"
      #  export ret=$?
      #  test $ret -ne 0 && doExit 1 "[FATAL] perl modules not found!!!"
    
    
      # check that all the required modules are installed
      my ( $ret , $msg ) = doCheckRequiredModules();
    
      unless ( $ret == 0 ) {
         print "$msg" ; 
         # give some time for the user to react
         sleep 7;
      }
    
      exit(0);
    
      sub doCheckRequiredModules {
    
         my @modules = qw(
            ExtUtils::MakeMaker
            Test::More
            Test::Deep
            File::Copy::Recursive
            HTML::TreeBuilder
            HTML::TreeBuilder::XPath
            HTML::TableExtract
            HTML::ElementTable
            Data::Printer
         );
    
         for(@modules) {
             eval "use $_";
             if ($@) {
    
               my $msg = "\n\n\n [FATAL] did not found the following perl module: $_ " ; 
               $msg .= "\n install it in the shell by running the following command:" ; 
               # if the user knows already the difference between the running the cmd 
               # with sudo or he / she probably knows already how-to install perl modules
               $msg .= "\n sudo perl -MCPAN -e 'install $_'\n\n\n" ; 
               $msg .= "\n if you seem to be stuck in circular reference kind of loop try even :\n" ; 
               $msg .= "\n sudo perl -MCPAN -e 'CPAN::Shell->force(qw( install $_));'\n" ; 
               $msg .= "\n You may end-up now with Ctrl + C \n\n\n" ; 
    
               return ( 1, "$msg")  if $@;
             } else {
                 say "[INFO ] == ok == check for prerequisite perl module : $_";
             }
         }
    
         return ( 0 , "all required modules found" ) ;   
      }
      #eof sub
    

提交回复
热议问题