views:

89

answers:

3

Hi all,

I'm very new to Perl programming. I've just finished reading the Llama book. Up until now I have scripted in Bash, but I'm wanting to try out Perl and it's benefits over Bash scripting.

I'm creating a script that uses a number of standard modules (e.g. Getopt) and some not-so-standard modules (e.g. PerlMagick)

At some point I want to distribute my Perl code and I want it to be usable by people who don't really know about Perl or programming. Obviously the standard modules should always be there (I'm using "use 5.010" to guarantee this to a certain extent), but what of the non-standard ones?

I guess there are two possibilities: 1) Should I tell the end user to install the missing modules? 2) Should I create an installation script that tests for the modules and if they are not there, then install them? If choice 2 is chosen, should I download the modules and install them? Or distribute them with my main code? I'm just not sure what the etiquette is with such things...

Thank you very much for all advice, Ben

+3  A: 

you can convert them to executables. You can try things like perlcc, perl2exe, PAR, or Perl development kit.

ghostdog74
+1  A: 

And if you don't want to compile them with prelcc or perlapp - then any posibility works.

  • You sould check the module of correct version present, for your Perl code not to claim some error message like: "Can't locate Data/UUID.pm in @INC (@INC contains: ... )". For example:

    eval { use Data::UUID; };
    if( $@ ) { 
            print "Data::UUID not found\n"; 
    }
    

    or

    eval { use Text::ParseWords 3.23; }; 
    if( $@ ) { 
            print "Text::ParseWords 3.23 not found\n"; 
    }
    
  • You can try using CPAN module (or cpan program on unix). Like, you can try shell command:

    cpan Data::UUID
    

    or from the perl-script:

    #!/usr/bin/perl
    use CPAN;
    CPAN::install("Data::UUID");
    
2can
Downvote: This does not work because `use` runs at compile time. Also, we already have perfectly fine dependency tracking + installation toolchain as hobbs' answer describes, no need for this hackery.
daxim
+5  A: 

If you design your app as a Perl distribution (as used on CPAN), then you get the power of the Perl toolchain to deal with this kind of thing for you. You just make sure that the modules you depend on are listed properly in your Makefile.PL, and then someone only has to write cpan YourApp::Name to get your application and everything it requires. Or if they downloaded your app from somewhere other than CPAN and they're building it manually, the make process can find the dependencies for them (which is why Module::AutoInstall isn't entirely dead and doesn't deserve to be IMO).

For Windows users, the only thing you have to add before the cpan YourApp::Name step is "install Strawberry Perl".

You also have the option of bundling (whether that involves PAR or just an installer or archive that includes both your app and all of the necessary modules, and probably perl itself) but there's one major drawback to that technique: it means you either can't use any XS code, or else you have to provide a separate package for each different platform that you want your app to support. The CPAN route doesn't run into that problem.

hobbs