How to automatically install all modules required by a script from CPAN?

Having a script.pl how can I automatically download from CPAN all required modules and install and update as required? Something like "emerge -uDNav world" for the perl?

---------- Post updated at 05:38 PM ---------- Previous update was at 05:28 PM ----------

Doesn't matter I've found it

cat *.pl  | grep "^use " | tr ';' ' ' | while read a b c; do echo $b; done | sort -iu | while read a; do cpan $a; done

In the CPAN shell:

o conf prerequisites_policy follow
o conf build_requires_install_policy yes 
o conf commit
1 Like

It's not working:

# perl backup.pl 
Can't locate Crypt/OpenSSL/PBKDF2.pm in @INC

Posting the result of cpan <module_name> will be helpful (we don't know what backup.pl contains).

If need to automate the download of the dependencies, you may need to configure the Internet connection:

o conf init connect_to_internet_ok

or

o conf init urllist
1 Like
# cpan Crypt/OpenSSL/PBKDF2.pm
Going to read '/root/.cpan/Metadata'
  Database was generated on Sun, 18 Nov 2012 00:55:04 GMT
Running install for module 'Crypt::OpenSSL::PBKDF2'
Running make for S/SK/SKUPSY/OpenSSL/Crypt-OpenSSL-PBKDF2-0.02.tar.gz
Checksum for /root/.cpan/sources/authors/id/S/SK/SKUPSY/OpenSSL/Crypt-OpenSSL-PBKDF2-0.02.tar.gz ok

  CPAN.pm: Going to build S/SK/SKUPSY/OpenSSL/Crypt-OpenSSL-PBKDF2-0.02.tar.gz

Checking if your kit is complete...
Looks good
Writing Makefile for Crypt::OpenSSL::PBKDF2
Writing MYMETA.yml
cp PBKDF2.pm blib/lib/Crypt/OpenSSL/PBKDF2.pm
AutoSplitting blib/lib/Crypt/OpenSSL/PBKDF2.pm (blib/lib/auto/Crypt/OpenSSL/PBKDF2)
/usr/bin/perl /usr/share/perl/5.14/ExtUtils/xsubpp  -typemap /usr/share/perl/5.14/ExtUtils/typemap -typemap typemap  PBKDF2.xs > PBKDF2.xsc && mv PBKDF2.xsc PBKDF2.c
Please specify prototyping behavior for PBKDF2.xs (see perlxs manual)
cc -c  -I. -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g   -DVERSION=\"0.02\" -DXS_VERSION=\"0.02\" -fPIC "-I/usr/lib/perl/5.14/CORE"   PBKDF2.c
PBKDF2.c:67:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
make: *** [PBKDF2.o] Error 1
  SKUPSY/OpenSSL/Crypt-OpenSSL-PBKDF2-0.02.tar.gz
  /usr/bin/make -- NOT OK
'YAML' not installed, will not store persistent state
Running make test
  Can't test without successful make
Running make install
  Make had returned bad status, install seems impossible

I believe that you need the OpenSSL headers and you need to install them manually. Use CPAN to install Perl modules, not OS packages.

1 Like

Thank you, it was solved installing the SSL headers

sudo apt-get install libssl-dev