Automating CPAN on FreeBSD

When using CPAN for the first time, a number of questions are prompted to the user, thereby halting the process. Since I am running FreeBSD I was wondering whether the inclusion of the port instead leads to the same result. So instead of having the following:

perl -MCPAN -e "install DBD::SQLite"

and getting trapped into the CPAN dialogue, I might as well do the following:

cd /usr/ports/databases/p5-DBD-SQLite
make install clean

or

pkg_add -r p5-DBD-SQLite

Is that a fair alternative?

Ports will not help if you have specific packages that do not exist on the ports tree.

You may try to see if a CPAN no-prompt trick will help you. It may work for some modules but perhaps not for the rest. There's no harm trying though.

CPAN - perldoc.perl.org

Take a look at Q13.

Thank you for your response. The bit that I have added to the line will make a line look as follows:

PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Term::ReadLine::Gnu"

Problematically, this will bring the script in an endless loop requesting the user to select a geographical location of the CPAN server, without the possibility for the user to provide any answer.

This is not the problem due to the package, but the CPAN installation being not set up on a specific workstation/user yet. That option will not help with this, because you must set up the configuration on first use.

Please refer to this section:

CPAN - perldoc.perl.org

One possible thought is to manually copy an existing CPAN configuration file and make sure it is installed in the user environment before you execute other CPAN commands. Try it and tell us if it works.

Thank you for your response. This is the content of the $HOME/.cpan/CPAN/Config.pm file:

$CPAN::Config = {
'build_cache' => q[10],
'build_dir' => q[/root/.cpan/build],
'cache_metadata' => q[1],
'cpan_home' => q[/root/.cpan],
'ftp' => q[ ],
'ftp_proxy' => q[ ],
'gzip' => q[/usr/bin/gzip],
'histfile' => q[/root/.cpan/histfile],
'histsize' => q[100],
'inactivity_timeout' => q[0],
'index_expire' => q[1],
'inhibit_startup_message' => q[0],
'make' => q[/usr/bin/make],
'make_arg' => q[],
'make_install_arg' => q[],
'makepl_arg' => q[],
'ncftp' => q[ ],
'ncftpget' => q[ ],
'no_proxy' => q[],
'pager' => q[/usr/bin/less],
'prerequisites_policy' => q[follow],
'proxy_user' => q[],
'scan_cache' => q[atstart],
'shell' => q[/bin/sh],
'tar' => q[/usr/bin/tar],
'term_is_latin' => q[1],
'unzip' => q[],
'urllist' => [q[http://www.perl.com/CPAN/]],
'wget' => q[],
};

It looks like it is working, but I will run some more tests to see what is the optimal configuration, since it has not run uninterrupted for various other reasons.

UPDATE: even on a clean installation of the operating system I have not been able to make this work; the same CPAN questions keep appearing, please advise.

Are you sure you are putting it in the correct home dir (your config seems to work only with "root")?

One suggestion. Try to run cpan with strace and find out (from the system calls output) what locations cpan has sought for the configuration file(s). It's not very easy to trace this way but will certainly give you a better idea how the search goes. Make sure cpan has actually tried to find that file.

I don't have access to a Linux Perl installation at the moment. Will try myself maybe tomorrow if I have the time.

The script this comes from is run as root as part of a system installation. The directory .cpan and its subdirectory CPAN are created on the fly. The Config.pm is placed in $HOME/.cpan/CPAN and the cpan modules are loaded. It's the last bit that is not silent.

Will come back with more details later.

For root, I tested on Linux and CPAN seems to write the configuration to /usr/lib/perl5/5.x.x/CPAN/Config.pm.

Thank you again for your help. The file Config.pm is in a different location in my case, namely: /usr/local/lib/perl5/5.8.8/BSDPAN/Config.pm
The contents do not look like a Config.pm as outlined in the various tutorials on the web. It has not been touched for months, and I cannot tell if it was accessed either.
Strace will not install on a i386 system.

If you can enter the cpan shell (by running "cpan" or "perl -MCPAN -e shell"), the "o conf" command generated output will tell you the locations from which configuration is read.

This is mine on a certain Linux system I have:

admin@np64gw:~$ cpan

cpan shell -- CPAN exploration and modules installation (v1.7601)
ReadLine support available (try 'install Bundle::CPAN')

cpan> o conf
CPAN::Config options from /usr/lib/perl5/5.8.7/CPAN/Config.pm and /test/.cpan/CPAN/MyConfig.pm:
    commit             Commit changes to disk
    defaults           Reload defaults from disk
    init               Interactive setting of all options

    build_cache        10
    build_dir          /test/.cpan/build
    cache_metadata     1
    cpan_home          /test/.cpan
...

Thanks for your response. I generated the Config.pm file using the same output, namely from "o conf". The path at the top is /usr/local/lib/perl5/5.8.8/CPAN/Config.pm
when invoking cpan. So actually different from where I put my hand-crafted version. Are you suggesting I should overwrite the one shown in this posting with the hand-crafted one?

Also typo in my previous post:

This should be: Strace will not install on a non-i386 system.

If cpan is looking at the location specified, then you should overwrite it or it will not be seen. Of course please keep backup of the original file before you overwrite it, as your version may not necessarily work!

The following solution works and places the Config.pm file in two places:

$HOME/.cpan/CPAN
/usr/local/lib/perl5/5.8.8/CPAN/

The directories are created in a script, in case they do not exist.
Forum members testing this might want to indicate which of the two locations actually makes the difference.