How do I automate CPAN configuration?

前端 未结 5 2054
礼貌的吻别
礼貌的吻别 2020-12-24 00:58

The first time you run cpan from the command line, you are prompted for answers to various questions. How do you automate cpan and install modules non-interactively from the

相关标签:
5条回答
  • 2020-12-24 01:35

    I was looking for an easy solution for this as well and found that this works:

    (echo y;echo o conf prerequisites_policy follow;echo o conf commit)|cpan
    

    Just thought I would post it here in case anyone else comes along.

    0 讨论(0)
  • 2020-12-24 01:36

    Make your own CPAN.pm config file. The recent versions of the cpan command have a -J switch to dump the current config and a -j switch to load whatever config you like.

    0 讨论(0)
  • 2020-12-24 01:38

    Since it hasn't been mentioned yet, cpanminus is a zero-conf cpan installer. And you can download a self-contained executable if it isn't available for your version control.

    The cpanm executable is easily installed (as documented in the executable itself) with:

    curl -L http://cpanmin.us | perl - --self-upgrade
    # or
    wget -O - http://cpanmin.us | perl - --self-upgrade
    
    0 讨论(0)
  • Recent versions of CPAN.pm ask as first question whether the rest of the configuration should be run automatically, so it is advisable to upgrade CPAN.pm (manually) first: tarballs, repo.

    0 讨论(0)
  • 2020-12-24 01:53

    One way is to take the CPAN/Config.pm (or ~/.cpan/CPAN/MyConfig.pm) created after one run from one system, and install it as ~/.cpan/CPAN/MyConfig.pm on the system you want to automate. Another way is to run the following to create the MyConfig.pm file for you (one thing missing below is the actual values for the urllist parameter which you will have to fill in with appropriate values for CPAN mirrors):

    #!/usr/bin/perl
    
    use strict;
    use Config;
    
    $ENV{PERL_MM_USE_DEFAULT}=1;
    $ENV{PERL_MM_NONINTERACTIVE}=1;
    $ENV{AUTOMATED_TESTING}=1;
    
    # get the path to the library
    my $libpath = $Config{privlib};
    
    # force CPAN::FirstTime to not default to manual
    # setup, since initial CPAN setup needs to be automated
    {
      local @ARGV = "$libpath/CPAN/FirstTime.pm";
      my @source = <>;
      $source[72] =~ s/\byes\b/no/ or die "Could not auto configure CPAN";
      eval join('', @source) or die "Error executing CPAN::FirstTime: $@";
    }
    
    CPAN::FirstTime::init("$libpath/CPAN/Config.pm");
    
    delete $CPAN::Config->{links};
    $CPAN::Config->{auto_commit} = '0';
    $CPAN::Config->{check_sigs} = '0';
    $CPAN::Config->{halt_on_failure} = '0';
    $CPAN::Config->{make_install_make_command} = '/usr/bin/make';
    $CPAN::Config->{mbuild_arg} = '';
    $CPAN::Config->{mbuildpl_arg} = '';
    $CPAN::Config->{mbuild_install_arg} = '';
    $CPAN::Config->{show_upload_date} = '';
    $CPAN::Config->{tar_verbosity} = '1';
    $CPAN::Config->{trust_test_report_history} = '0';
    $CPAN::Config->{use_sqlite} = '0';
    $CPAN::Config->{yaml_load_code} = '0';
    $CPAN::Config->{urllist}
      = [qw(http://... ftp://... etc...)];
    $CPAN::Config->{connect_to_internet_ok} = '1';
    $CPAN::Config->{perl5lib_verbosity}     = 'v';
    $CPAN::Config->{prefer_installer}       = 'MB';
    $CPAN::Config->{build_requires_install_policy} = 'no';
    $CPAN::Config->{term_ornaments}         = '1';
    $CPAN::Config->{mbuild_install_build_command} = './Build';
    
    mkdir ".cpan/CPAN" or die "Can't create .cpan/CPAN: $!";
    CPAN::Config->commit(".cpan/CPAN/MyConfig.pm");
    
    CPAN::install('Bundle::CPAN');
    CPAN::install('JSON');
    CPAN::install('JSON::XS');
    # etc.
    
    exit 0;
    
    0 讨论(0)
提交回复
热议问题