Distributing a Perl Application

2019-02-10 15:25发布

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.

2条回答
Melony?
2楼-- · 2019-02-10 15:46

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.

查看更多
Animai°情兽
3楼-- · 2019-02-10 15:47
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.

查看更多
登录 后发表回答