initself has asked for the wisdom of the Perl Monks concerning the following question:

I am working on an install shell script which installs Perl from source on my machine. I then need to setup CPAN but it needs to be configured. When I type 'cpan' from the command line, it prompts me to auto-configure. I select 'yes'. Is there an argument I can pass the 'cpan' command so that it will automatically auto-configure if it is not already auto-configured? Or is there another way I might automated my initial CPAN setup?

Here are my three commands:

cpan (answer yes to autoconfig) o conf prerequisites_policy follow o conf commit

Thanks!

Replies are listed 'Best First'.
Re: CPAN auto-configure
by marto (Cardinal) on Oct 16, 2009 at 08:49 UTC
Re: CPAN auto-configure
by DrHyde (Prior) on Oct 16, 2009 at 09:51 UTC

    Try this:

    (echo y;echo o conf prerequisites_policy follow;echo o conf commit)|cpan

    Or otherwise, CPAN::Config is just a hash, so you could instead of letting CPAN.pm configure itself, just give it a configuration by dumping it from a variable to the right file using Data::Dumper.

Re: CPAN auto-configure
by YordanGeorgiev (Acolyte) on Apr 13, 2021 at 20:50 UTC
    # just a bash function # file: src/bash/deploy/ubuntu/ubuntu-20.04.2-lts/check-install-perl-m +odules.func.sh do_check_install_perl_modules(){ cd $PRODUCT_DIR # this one is pre-defined in the beginning of your +bash script - the proj root dir # define the local::lib dir local_perl5dir=~/perl5 bash_opts_file=~/.bash_opts # bootstrap the cpan conf (echo yes;echo o conf prerequisites_policy follow;echo o conf commi +t)|cpan cat << EOF_CPAN_CONFIG | cpan o conf makepl_arg 'PREFIX=$local_perl5dir INSTALLMAN3DIR=$local_per +l5dir/man/man3' o conf mbuild_arg '--install_base $local_perl5dir' o conf mbuild_install_arg '--install_base $local_perl5dir' o conf mbuildpl_arg '--install-base $local_perl5dir' o conf commit EOF_CPAN_CONFIG perl -MCPAN -e 'install local::lib' curl -L http://cpanmin.us | perl - --self-upgrade -l $local_perl5di +r App::cpanminus \ && sudo chown -R $USER:$(id -gn) ~/.cpanm && sudo chown -R $USER +:$(id -gn) $local_perl5dir # stored in the src/bash/deploy/ubuntu/ubuntu-20.04.2-lts/check-ins +tall-perl-modules.lst file modules="$(cat ${BASH_SOURCE/.func.sh/.lst})" while read -r module ; do use_modules="${use_modules:-} use $module + ; "; done < <(echo "$modules"); perl -e "$use_modules" || { echo "deploying modules. This WILL take couple of min, but ONLY +ONCE !!!" curl -L cpanmin.us | perl - Mojolicious test "$(grep -c 'Mlocal::lib' $bash_opts_file)" -eq 0 && \ echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >> $ +bash_opts_file while read -r module ; do cpanm_modules="${cpanm_modules:-} $mod +ule " ; done < <(echo "$modules") cpanm --local-lib=$local_perl5dir local::lib && eval $(perl -I $ +local_perl5dir/lib/perl5/ -Mlocal::lib) cmd="cpanm --local-lib=$local_perl5dir $modules" set -x $cmd set +e } } #eof file: src/bash/deploy/ubuntu/ubuntu-20.04.2-lts/check-install-per +l-modules.func.sh