Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Automating CPAN Configuration

by Anonymous Monk
on Feb 15, 2008 at 19:17 UTC ( #668225=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Automating CPAN Configuration
in thread Automating CPAN Configuration

After several Days of working this out, I finally got it to work. The finished result is below. Thanks for Perl Monks for the ideas from this thread. Wouldn't have been able to do it without you!

#!/usr/bin/perl -w use strict; # get the path to the library use Config; my $libpath = $Config{privlib}; # force CPAN::FirstTime to not default to manual # setup, since initial CPAN setup needs to be automated system("perl -pi -e\'\$. == 73 and s/yes/no/\' $libpath/CPAN/FirstTime +.pm"); # initialize the Config.pm file use Env; $ENV{PERL_MM_USE_DEFAULT} = 1; require CPAN; require CPAN::FirstTime; CPAN::FirstTime::init("$libpath/CPAN/Config.pm"); delete $ENV{PERL_MM_USE_DEFAULT}; # undo the change system("perl -pi -e\'\$. == 73 and s/no/yes/\' $libpath/CPAN/FirstTime +.pm"); # read in the Config.pm file open(CONFIGFILE,"<","$libpath/CPAN/Config.pm"); my @lines = <CONFIGFILE>; close CONFIGFILE; # ..delete it unlink "$libpath/CPAN/Config.pm"; # ..and then write it back out, replacing the line with the empty arra +y urllist with a filled in array open(NEWFILE,">","$libpath/CPAN/Config.pm"); foreach(@lines){ if($_ =~ m/urllist/){ print NEWFILE " \'urllist\' => [\'http://ppm.activestate.com/ +CPAN\', \'http://cpan.perl.org\'],\n";} else{ print NEWFILE $_;}} close NEWFILE; # install the packages CPAN::install('SOAP::Lite'); CPAN::install('XML::Simple'); 1;


Comment on Re^4: Automating CPAN Configuration
Download Code
Re^5: Automating CPAN Configuration
by runrig (Abbot) on Jun 28, 2010 at 16:11 UTC

    Update: I've since discovered that I prefer cpanm

    Using your code as a starter, here is what I'm using. I think it's a bit simpler not having to rewrite the FirstTime.pm file:
    ######################################## # Get CPAN::Config.pm initialized export PERL_MM_USE_DEFAULT=1 PERL_MM_NONINTERACTIVE=1 AUTOMATED_TESTIN +G=1 perl <<'EOT' || exit use strict; use Data::Dumper; # get the path to the library use Config; 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} = [q[ftp:...your list.../], q[http://...your list...]]; $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::force('install', ''); CPAN::install('JSON'); CPAN::install('JSON::XS'); exit 0; EOT

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://668225]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2015-07-04 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls