Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

cpan home

by equick (Acolyte)
on Feb 16, 2011 at 11:15 UTC ( #888494=perlquestion: print w/replies, xml ) Need Help??
equick has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to start perl -MCPAN -e shell pointing at a different config file? I have a floating home directory so when I log on to a solaris box, I have the same home directory as when I log on to a linux box. This causes issues when running cpan, because the environments differ.

Thanks for any help,


Replies are listed 'Best First'.
Re: cpan home
by roboticus (Chancellor) on Feb 16, 2011 at 11:35 UTC


    In the CPAN docs, it mentions that you can override values in CPAN/ by putting a file in $HOME/.cpan/CPAN/ Perhaps you can then place a bit of code in to detect your login and perform the appropriate initializations.

    # # Stuff common to all configurations $CPAN::Config = { 'applypatch' => q[], # bunch of junk snipped out }; if ($Config{osname} eq 'foo') { $CPAN::Config->{build_dir} = '/work/builds/foo'; } elsif ($Config{osname} eq 'bar') { $CPAN::Config->{build_dir} = '/work/builds/foo'; } 1;


    When your only tool is a hammer, all problems look like your thumb.

Re: cpan home
by Corion (Pope) on Feb 16, 2011 at 11:22 UTC

    There seems to be no documented way, but looking at CPAN::HandleConfig::require_myconfig_or_config, the following could work (likely you want that as a separate script or alias):

    perl -e "require '~/.cpan/MyConfig.$(uname).pm'; $INC{'CPAN/MyConfig.p +m'}=1" -MCPAN -eshell

    Likely, your ~/.cpan/ should look like

    package CPAN::MyConfig; ... options as in the common CPAN::MyConfig
      Thanks for the quick reply. I gave that a try but hit a slight error.
      perl -e "require '~/.cpan/CPAN/MyConfig.$(uname).pm'; $INC{'CPAN/MyCon'}=1" -MCPAN -e shell Semicolon seems to be missing at -e line 1. syntax error at -e line 1, near "}=" Execution of -e aborted due to compilation errors.
        Put it in a file
        $ cat mcpan #!/usr/bin/perl -- require $INC{'CPAN/'} = ...; require CPAN; CPAN::shell();
Re: cpan home
by tinita (Parson) on Feb 16, 2011 at 12:06 UTC
    try the -j option with the cpan script:
    cpan -j some/other/file Module::Foo
      Hmm, is -j a new option?
      $ cpan -j some/other/file Module::Foo Unknown option: j LWP not available $ cpan -v cpan script version 1.03 version 1.7602
        yes, it's quite new, but OTOH, it's in version App::Cpan 1.57 which is from december 2009.
        I just knew about the option because I was one of the people who requested this feature. Unfortunately I don't see it in the changelog so I don't know in which version it was introduced.

        update: s/App::cpan/App::Cpan/ (although the linked cpan search is case insensitive, but anonymous monk complained)
        The -j option exists in the current release (5.12.2) on Perl documentation. Refer to cpan. You could search through the perldelta's if you want to know when this feature was added.

        I'm on perl 5.12.2:

        cpan -v cpan script version 1.5701, version 1.9456

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://888494]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-05-21 05:45 GMT
Find Nodes?
    Voting Booth?