diabelek has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to prevent CPAN/modules from asking question or auto answering them when installing them. I have the script at the bottom of this post that works great for most modules but there are some modules or CPAN that ask questions during an install, don't time out and don't have an obvious way of overriding it. The current problem I have might be CPAN (not 100% positive). I get "Do you want to install lwp-request? y" for libwww-perl-5.812. It never times out and isn't auto answered by the build_requires_install_policy

Any ideas?

-------
require CPAN; require CPAN::Config; # configure cpan to go to pyro $CPAN::Config->{urllist} = [ q[http://server/cpan] ]; $CPAN::Config->{http_proxy} = q[]; $CPAN::Config->{ftp_proxy} = q[]; $CPAN::Config->{build_requires_install_policy} = q[yes]; $CPAN::Config->{prerequisites_policy} = q[follow]; # now get the modules from the config appropriate file my @packages = []; my @ppm_packages = []; my $common_package_file; my $os_package_file; my $ppm_package_file; if( $^O eq "MSWin32" ) { open( $common_package_file, 'p:\automation\commoncpan.txt' ) or die( "Unable to open common package file\n" ); open( $os_package_file, 'p:\automation\windowscpan.txt' ) or die( "Unable to open windows package file\n" ); open( $ppm_package_file, 'p:\automation\windowsppm.txt' ) or die( "Unable to open windows ppm package file\n" ); } elsif( $^O eq "linux" ) { open( $common_package_file, '/srv/automation/commoncpan.txt' ) or die( "Unable to open common package file\n" ); open( $os_package_file, '/srv/automation/linuxcpan.txt' ) or die( "Unable to open linux package file\n" ); } else { die( "ERROR: Unsupported OS\n" ); } @packages = <$common_package_file>; my $package; while( ($package = <$os_package_file>) ) { #just add the packages to the end of the array push( @packages, $package ); } @ppm_packages = <$ppm_package_file>; close( $common_package_file ); close( $os_package_file ); close( $ppm_package_file ); foreach my $line (@packages) { chomp( $line ); print( CPAN::install( $line ) ); } foreach my $line (@ppm_packages) { chomp( $line ); $ENV{http_proxy} = 'proxy'; print( `ppm install $line` ); }

Replies are listed 'Best First'.
Re: CPAN Modules asking questions
by Corion (Patriarch) on May 02, 2008 at 15:58 UTC

    In theory, every Good distribution behaves well in absence of a terminal/user. This is by virtue of using ExtUtils::MakeMaker's prompt function, which knows to return the default value when there is no user to answer the question.

    In practice, there are bad apples that ask the same question over and over again, providing no default and not realizing that there is nobody there to answer. Such distributions will hopefully become rarer and rarer.

    The ExtUtils::MakeMaker documentation says to set $ENV{PERL_MM_USE_DEFAULT} to a true value to make EU:MM skip the questions. I guess that Module::Build, as incompatible as it may be otherwise, also adheres to this standard.

      FYI, I did verify that Module::Build does use the $ENV{PERL_MM_USE_DEFAULT} value during installation. It was under Module::Build::API, prompt().

      I did not know about this before, glad you mentioned it!

Re: CPAN Modules asking questions
by stiller (Friar) on May 02, 2008 at 16:05 UTC
    There is one cpan option "inactivity timeout", preventing cpan from waiting forever, but it won't help you much here. Are you creating a script for a spesific installation job, or for the general case? If the first, then Expect might help.

    Actually, Expect might be good in the general case too.

      Unfortunately expect isn't an option since it doesn't run on Windows without cygwin (cygwin can't be installed). If there is a way to get expect on Windows, I would be so happy since that will simplify a bunch of problems. The script is a general installation script for automation in Linux/Windows and sooner or later, Solaris, other misc *nixes and *shudder* Dos (if possible). This is just the first step of getting all the CPAN modules on test systems. Next is getting scripts and our modules on the test systems. Any other ideas would be appreciated.
Re: CPAN Modules asking questions
by Ultra (Hermit) on May 19, 2008 at 13:58 UTC