If I want to distribute a Perl script, what is the best way to painlessly install any required modules that are missing on the user's system? Extra credit if there is a way to even install/upgrade Perl itself if it is missing or "too old".
CPAN doesn't actually install files. It runs the install script embedded in each distribution, which then performs the actual install. For distributions using ExtUtils::MakeMaker, the defaults are documented here: https://metacpan.org/pod/ExtUtils::MakeMaker#make-install (and the default value of INSTALLDIRS is site ).
To install Perl modules using CPAN, you need to use the cpan command-line utility. You can either run cpan with arguments from the command-line interface, for example, to install a module (e.g Geo::IP) use the -i flag as shown.
One possible solution is to install libcgi-pm-perl , which currently replaces the default version by a supported one (2011-0-10). To do so, type sudo apt-get install libcgi-pm-perl from the command line or install it with your favorite package manager. Gentoo has ebuilds for the CPAN.
Auto-installing software is the best way to make both end users and sysadmins very angry with you. Forget about this approach.
You can simply ship all your dependencies with your application distro, the inc
directory is customary.
Usually this ends with CPAN-like package creation.
So, when you need to install all dependencies you type make installdeps
See perldoc perlmodlib
Also Module::Install
may be useful for you and some Makefile.PL example
Makefile.PL
allows you to define deps and required perl version.
Also you may add
use 5.010;
To your script in order to require minimal version of perl to run. See perldoc -f use for details.
Why not use pp (PAR Packager) that creates an executable. No need for Perl or anything on the target machine.
If you look at cpanminus, this you can install by simply executing one file:
curl -L http://cpanmin.us | perl - --self-upgrade
This might be the behaviour you're looking for; it's done with App::Fatpacker. Check it out:
https://metacpan.org/module/App::FatPacker
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With