Since the CPAN on my system normally needs root access to install, I normally run cpan as root (probably a bad idea, but I need CPAN.pm to ask for my sudo location before I start running it as my own user). The distress this causes is a meditation for another time. Here I would like to talk about setting up a local CPAN settings without much work. The purpose? I just want to fetch some modules so I can put them up on my web host. How to install them without having shell access has been discussed before, so I'm going to search for that, and then do what I need to get them installed privately.
My first attempt was a naive "if I run as my own user, it should just detect I've not done this before and ask me all the questions again." While that is mildly annoying, it's just a one-time setup, and shouldn't be that big of a deal. Unfortunately, that doesn't work. It couldn't mkdir /root/.cpan - permission denied. A bit of digging, and I eventually found that CPAN sets its configuration in /usr/lib/perl5/5.8.8/CPAN/Config.pm. YMMV - but it's definitely a global path. A bit odd... Anyway, that file says that you can override it locally (no interactive setup!) by creating ~/.cpan/CPAN/MyConfig.pm, and putting your changes there. That's a bit awkward, so I put this in my version:
use User::pwent;
my $root = getpw(0)->dir();
my $home = getpw($<)->dir();
for (keys %{$CPAN::Config})
{
$CPAN::Config->{$_} =~ s:^\Q$root:$home:;
}
1;
__END__
Now, most likely, if I try to "
o conf make_arg -j5" or something, it'll do something strange. Like completely override my file, or crash trying to figure it out, or attempt to overwrite the global CPAN::Config. I'm not sure which. So I don't plan on doing that.
Now, if cpan just figured out that the configuration was bogus and simply reinitialised itself, that would have been a step forward. But, until then ... hopefully this helps someone.