Andrew
Andrew

Reputation: 241

force module install with CPAN

I know it's easy to install a module with 'force' using CPAN from command prompt. I am trying to achieve same through the script:

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

Is there any way to add the option 'force' to the code? I am having the following error while compiling the module:

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

The warnings could not be serious, so I would like to proceed with the installation. Thanks.

Upvotes: 4

Views: 4984

Answers (3)

Brad Gilbert
Brad Gilbert

Reputation: 34120

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

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

If you want to make sure that Filesys::DiskSpace is loaded, and install it if it's not available:

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

NOTE:

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

That particular module hasn't had an official release since 1999.
It also has a fair number of bug reports:

Upvotes: 3

mob
mob

Reputation: 118605

So long as you Really Know What You Are Doing:

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

The use builtin doesn't return anything useful, even when it is successful, so it is necessary to include the ";1" in the string eval.

Upvotes: 3

Glen Solsberry
Glen Solsberry

Reputation: 12320

Looks like you'll need to instantiate CPAN to a variable and call the force() method on it

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

Upvotes: 5

Related Questions