views:

91

answers:

2

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.

+3  A: 

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.

daxim
Thank you very much -- this worked perfectly. I only thought that utilizing module-starter would be a shoe-horn-type solution due to my application being a simple single-file perl-script and not a `lib/My/Module.pm` type project.
Joe
@Joe: There are lots of modules on CPAN that install scripts that go in bin; the approach is the same.
Ether
A: 
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.

hlynur
That's interesting. Thank you.
Joe