Perl Modules and CPAN

Come verificare se un modulo e' installato
Per verificare se un modulo, come ad esempio File::Path, e' installato: perl -MFile::Path -le 'print "Modulo presente"'

Se si vuole sapere anche la versione di un modulo eventualmente installato: perl -le 'eval "require $ARGV[0]" and print "Modulo presente (v.",$ARGV[0]->VERSION,")"' File::Path

Configurare CPAN per prendere i moduli da un web server locale
Per fare in modo che i server utilizzino un mirror personale quando si installa un modulo con CPAN, con cpan v1.9: rm -rf /root/.cpan perl -MCPAN -e shell Would you like me to configure as much as possible automatically? [yes] cpan[1]> o conf init urllist Is it OK to try to connect to the Internet? [yes] no Please enter your CPAN site: [] https://myserver.domain.com/CPAN/ Enter another URL or RETURN to quit: [] cpan[2]> o conf build_requires_install_policy yes cpan[3]> o conf prerequisites_policy follow cpan[4]> o conf ncftpget '' cpan[5]> o conf ftp_proxy '' cpan[6]> o conf http_proxy '' cpan[7]> o conf commit cpan[8]> quit

con cpan v1.7: rm -rf /root/.cpan perl -MCPAN -e shell cpan> o conf init Are you ready for manual configuration? [yes] no cpan> o conf urllist push https://myserver.domain.com/CPAN/ cpan> o conf build_requires_install_policy yes cpan> o conf prerequisites_policy follow cpan> o conf ncftpget '' cpan> o conf ftp_proxy '' cpan> o conf http_proxy '' cpan> o conf commit cpan> quit

Installare un modulo con CPAN
Per installare un modulo mediante l'utility CPAN: perl -MCPAN -e 'install MIME::Lite'

Installare diversi moduli con CPAN se non presenti
Se dovete installare diversi moduli mediante l'utility CPAN, previa verifica che non siano gia' presenti, potete usare questo script di esempio: for MODULE in CGI CGI::Simple CGI::Carp HTML::Template CGI::Session \ HTML::Mason MasonX::Request::WithApacheSession \ Perl6::Junction Regexp::Common File::MMagic Image::Size \ HTML::FillInForm Data::FormValidator Scalar::Util CGI::Cookie \ Email::Valid MIME::Lite IPC::System::Simple Log::Log4perl do CHECK=$(perl -M${MODULE} -e '' 2>/dev/null ; echo $?) if [ "${CHECK}" -eq 2 ]; then perl -MCPAN -e "install ${MODULE}" fi done

CPAN::Mini
Se il server non e' collegato ad internet, installare i moduli Perl diventa un'attivita' tediosa: gtar xfz File-HomeDir-0.89.tar.gz cd File-HomeDir-0.89/ perl Makefile.PL make make test make install cd .. gtar xfz File-Path-2.08.tar.gz cd File-Path-2.08/ perl Makefile.PL make make test make install cd .. gtar xfz CPAN-Mini-0.576.tar.gz cd CPAN-Mini-0.576/ perl Makefile.PL make make test make install cd ..

Grazie a questo modulo e' possibile creare un mirror minimale di CPAN in locale: minicpan -h Usage: minicpan [options] Options -l LOCAL  - where is the local minicpan? (required) -r REMOTE - where is the remote cpan mirror? (required) -d 0###   - permissions (numeric) to use when creating directories -f        - check all directories, even if indices are unchanged -p        - mirror perl, ponie, and parrot distributions -q        - run in quiet mode (don't print status) -qq       - run in silent mode (don't even print warnings) -c CLASS  - what class to use to mirror (default: CPAN::Mini) -h        - print help and exit -v        - print version and exit -x        - build an exact mirror, getting even normally disallowed files --offline - operate in offline mode (generally: do nothing)

Per creare tale mirror: minicpan -l /opt/apache/htdocs/CPAN -r " https://www.cpan.org/ " -d 0755 -q