tags:

views:

38

answers:

1

Here http://stackoverflow.com/questions/3462058/how-do-i-automate-cpan-configuration I've found some answers which led to some questions. I tried cpan -j config.pm, but as far as I can see it is meant for per installation usage, not for changing the config-file permanently.

With the $CPAN::Config-method the force CPAN::FirstTime to not default to manual-part didn't work here so I tried without it:

#!/usr/bin/perl
use strict;
use warnings;
use Config;
use CPAN;
use CPAN::FirstTime;

$ENV{PERL_MM_USE_DEFAULT}=1;
$ENV{PERL_MM_NONINTERACTIVE}=1;
$ENV{AUTOMATED_TESTING}=1;

my $cpan_home = '/home/me/.cpan';

mkdir $cpan_home or die $! if not -d $cpan_home;
mkdir "$cpan_home/CPAN" or die $! if not -d "$cpan_home/CPAN";

CPAN::FirstTime::init( "$cpan_home/CPAN/MyConfig.pm" );

delete $CPAN::Config->{links};

$CPAN::Config->{applypatch} = '';
# ...
$CPAN::Config->{build_dir} = "$cpan_home/build";
$CPAN::Config->{cpan_home} = $cpan_home;
$CPAN::Config->{histfile} = "$cpan_home/histfile";
$CP$CPAN::Config->{keep_source_where} = "$cpan_home/sources";
$CPAN::Config->{make_install_make_command} = 'sudo make';
$CPAN::Config->{mbuild_install_build_command} = 'sudo ./Build';
$CPAN::Config->{prefs_dir} = "$cpan_home/prefs";
# ...
$CPAN::Config->{yaml_module} = 'YAML';

CPAN::HandleConfig->commit("$cpan_home/CPAN/MyConfig.pm");

CPAN::install('Bundle::CPAN');
# ...
# etc.

exit 0;

Is this OK? The only bad thing that I have noticed so far is the waiting, until the cpan-mirror-urls are found. And what is the delete $CPAN::Config->{links}; for?

A: 

It looks like you are doing a lot of work. What are you trying to accomplish?

If you want to change the configuration file permanently, just change the configuration file. It's Perl code, so I think you can do everything you need, such as setting the root directory, right in the config file without having to deal with CPAN.pm.

brian d foy
When I install a new Linux-version I would like to do as less configuration by hand as possible. I thought such a script looks more elegant than copying a Config-file. And I would have the configuration and the module-installation in one script. But since this looks like a lot of work I tried this: <code>#!/bin/bash mkdir -p ~/.cpan/CPAN mkdir -p ~/.cpan/build mkdir -p ~/.cpan/histfile mkdir -p ~/.cpan/sources cp MyConfig.pm ~/.cpan/CPAN cpan Moldule::1 Module::2 Module::3</code>But it doesn't work as I hoped.
sid_com
This is the sort of stuff to add to your question, not hide in a comment. :)
brian d foy