Distributing a Perl Application

随声附和 提交于 2019-12-30 05:09:08

问题


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:

  1. Unpack the archive.
  2. 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 ; }
}
  1. 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)

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!