LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Distributing a perl script (http://www.linuxquestions.org/questions/programming-9/distributing-a-perl-script-822427/)

forquare 07-27-2010 09:31 AM

Distributing a perl script
 
Hi all,

I'm new to the world of Perl so may have gone about this in the wrong way (my background is mainly Java and Bash).

I have a Perl script (gallery.pl) which takes in various arguments (the only mandatory arguments is a directory full of images) and creates an HTML, standards compliant gallery. Seeing how images might be too big, I use the Image::Magick module to do any resizing that is necessary.

If I want to pass this script to a technically minded user to use then I'd just email the script or put it on my site for them to download and then they can sort out any modules they need to install.
However, what about non-technically minded users? How can I distribute my script in such a way that the end user doesn't have to care about missing dependancies?

I've thought about an installation script to install the main script under /opt/local/bin, could I use this installation script to install missing modules? If so, how might I do this?

I've tried looking at things like Module::AutoInstall and ExtUtils::MakeMaker but my interpretation is that these are only for modules, not for scripts.

Sorry to sound so dim about it all, but as I said, it's all rather new to me!

Many thanks,
Ben

amani 07-27-2010 09:45 AM

www.cpan.org should be the right place for this

forquare 07-27-2010 11:57 AM

Thanks for your response amani,

I've looked at CPAN, but didn't understand how it could help with my problem other than if I uploaded my script to CPAN. I'm not sure this is the right option for me, certainly not at this time.

Thanks again,
Ben

TB0ne 07-27-2010 03:10 PM

Quote:

Originally Posted by forquare (Post 4046990)
Thanks for your response amani,

I've looked at CPAN, but didn't understand how it could help with my problem other than if I uploaded my script to CPAN. I'm not sure this is the right option for me, certainly not at this time.

Thanks again,
Ben

I think what you're looking for is "pp", or the Perl Packager. Works great for me. It may be available in your repos, or you can grab it from CPAN here:

http://search.cpan.org/~mdootson/Wx-Perl-Packager-0.26/

It essentially 'compiles' a Perl program into an executable. Send it out like you would any other executable, and it'll have everything it needs to run, no tweaking of the environment needed. Works on Linux and Windows, anything that supports Perl.

zirias 07-27-2010 03:44 PM

If you want to distribute the script without compiling it, I'd suggest to NOT automatically install modules because some distributions also package them and the user could very well prefer installing the distribution's package over CPAN...

But you could make your script give better error messages by "require"ing the package in an eval block like this:
Code:

eval {
  require Image::Magick;
};
if ($@)
{
  print STDERR "Module Image::Magick was not found.\n";
  print STDERR "In order to use this script, please install the Image::Magick package for perl.\n";
  exit(0);
}



All times are GMT -5. The time now is 03:13 AM.