问题
I recently created a little Perl application that utilizes a few non-core modules that will need to be installed via CPAN.
Is there a way to distribute the application with the ability to check to see if the required modules are installed and pull them from CPAN if they aren't? I suppose I am looking for something similar to the CPAN auto-dependency-install feature.
I thought about using module-starter and Module::Install to create a module-like directory structure and then tailor the Build file to install the application to /bin... but I'm not sure if this is a shoe-horn solution.
回答1:
It's not a shoe-horn solution, but the Right Thing to do. You should let a specialised tool handle the dependencies because of the corner cases, e.g. write in the installation instructions:
- Unpack the archive.
- Run
cpan .
in the unarchived directory.
You need not change the Build file to install programs in the bin
directory, it does this by default.
回答2:
BEGIN {
eval "use evil::module";
if($@) { `sudo perl -MCPAN -e 'install evil::module'`; exit ; }
}
You can easily check if certain module is present and a)try to install it and exit/restart application b)croak/die. (sth like in the code snippet above)
You can also attach the modules you want to package, extract them to a certain directory, and push the dir to @INC in the begin block.
来源:https://stackoverflow.com/questions/3385759/distributing-a-perl-application