Install Power Module with CPAN

I know that it is easy to install a module with "strength" using CPAN from the command line. I am trying to achieve the same through a script:

use CPAN; eval "use Filesys::DiskSpace" or do { CPAN::install("Filesys::DiskSpace"); }; 

Is there any way to add the "force" parameter to the code? When compiling a module, the following error occurs:

  make test had returned bad status, won't install without force 

Warnings may not be serious, so I would like to continue the installation. Thanks.

+4
source share
3 answers

So far, you really know what you are doing:

 eval "use Filesys::DiskSpace; 1" or do { CPAN::Shell->force("install","Filesys::DiskSpace"); }; 

The built-in use function does not return anything useful, even if it is successful, so you must include " ;1 " in the eval string.

+3
source

It looks like you need to create a CPAN instance for the variable and call the force() method on it

 my $cpan = CPAN->new; $cpan->force(); $cpan->install("Filesys::DiskSpace"); 
+5
source

It looks like you are only making sure Filesys::DiskSpace installed:

 unless( eval { require Filesys::DiskSpace } ){ require CPAN; CPAN::Shell->force("install","Filesys::DiskSpace"); } 

If you want to make sure Filesys::DiskSpace downloaded and install it if it is unavailable:

 BEGIN{ unless( eval { require Filesys::DiskSpace } ){ require CPAN; CPAN::Shell->force("install","Filesys::DiskSpace"); } } use Filesys::DiskSpace; 

Note:

If you are having problems working with your Perl programs, it is probably because you just installed a broken module.

This particular module has not been officially released since 1999.
It also has a bug report report:

+3
source

Source: https://habr.com/ru/post/1395494/


All Articles