Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister


by rinceWind (Monsignor)
on Jul 06, 2004 at 16:15 UTC ( [id://372131]=modulereview: print w/replies, xml ) Need Help??

Item Description: Packaging perl scripts as executables

Review Synopsis: A useful tool in advocacy

PAR has saved my day! It will go a long way towards helping me in my crusade of Perl advocacy in the present $CLIENT (who shall remain nameless) environment.2

The situation is that we have three Unix (Solaris) environments: dev, test and live. Although Solaris comes with a version of perl pre-installed, the admins have restricted access to it on all but the dev machine (under some historical edicts from senior management).

Now, as part of my activities in development, I have been producing a nice set of perl tools (as is my want), to get my job done. Many of these would benefit production, especially for production support, which is closer to what my current role is.

PAR for the course

          +----+>| pp |====>foo

Just like cc, pp turns your Perl file (and all called modules) into an executable. It's not actually compiling them, just packaging them up (and compressing).

My colleagues feel a lot happier about the (potentially) tamper proof nature of executables, and I can deploy my perl 'scripts' into test and live environments. Funnily enough, they haven't had a problem with deploying .ksh or .awk scripts.

Caveat removed (thanks are due to PodMaster for helping me sort this one out.

Considered: MUBA move to meditations: not actually a review: it's more like giving comliments but that's it
Unconsidered: ysth - Keep/Edit/Delete = 6/9/0 - moving from reviews isn't supported


I do feel that bibo and MUBA have a point, and this node should be more of a review (see also this node). Here goes...

Peeping under the hood

Although PAR delivers applications that work out of the box1, it is worth examining what the output of pp actually is.

The resulting executable is a self extracting zip file, and tools such as winzip or unzip -l can reveal the contents of the file. Besides the various perl modules called, you will find script/ (this being your source script) and script/ Note that you don't see Perl itself or any of the magic glue that makes your application run.

script/ is a small bootstrap script that calls your script, and it looks like this:

my $zip = $PAR::LibCache{$ENV{PAR_PROGNAME}} || Archive::Zip->new(__FI +LE__); my $member = eval { $zip->memberNamed('script/') } or die qq(Can't open perl script "script/": No such file + or directory ($zip)); PAR::_run_member($member, 1);
The first time a PAR application is run (or a new version of the application), it is unzipped into temporary directories: $TEMP/par_$USER/cache_nnnnnnnnnnn

the nnnnnnnnnnn here is an MD5 checksum, hence a new version of the PAR application will generate a new cache directory.

The first time the application is run, there will be a significant startup time, as the zip kit is unpacked. It is worthwhile explaining this to users.

Run time requires

Unfortunately, PAR (and Module::ScanDeps) will not detect all modules, especially those whose name is determined at run time. If you are missing a module or two, you need to include the modules in the build - either by adding explicit use or require statements in the script (useful for Tk widget modules), or by specifying -M to pp.

Parlez vous?

There are circumstances where you don't want to bundle everything into a single executable. You may have several scripts (CGI scripts for example) calling the same bunch of modules, and you want to distribute this.

The PAR install delivers another utility called parl (PAR loader), which takes mostly the same parameters as perl. This provides the ability to run a perl script and call in one or more PAR libraries (built with pp, but called *.par).

Again, a Perl install is not needed on the target machine. You need to deliver parl, the scripts and the PAR libraries. On the Windows platform, you could package this up with Install Shield.


For those averse to command lines, there is a script provided called tkpp, which provides a very thin GUI Tk wrapper around pp. Far from it being a responsive GUI, it freezes while building the application. I find no benefit in using this over the command line, other than saving having to remember the command line options.


1 I like things that work straight out of the box. I am a great fan of Knoppix - a Linux distro that works straight off the CD.

2 This was the subject of a lightning talk I gave at YAPC::Europe 2004, the slides of which are here

Replies are listed 'Best First'.
by PodMaster (Abbot) on Jul 07, 2004 at 03:46 UTC
      Mea culpa...

      It turns out that I was picking up an old version of PAR (0.74) which was exhibiting the problem. I withdraw the caveat.

      I'm Not Just Another Perl Hacker

by bibo (Pilgrim) on Jul 06, 2004 at 19:06 UTC
    Hey, I'm happy this tool helps you. How about 1 or 2 more sentences about what it is, what it does, CPAN links, anything at all? All i see is that it archives perl scripts.

    Thanks, --bibo

      All i see is that it archives perl scripts
      What does Just like cc, pp turns your Perl file (and all called modules) into an executable. It's not actually compiling them, just packaging them up (and compressing) mean to you? Do you not understand executable? PAR
        Thanks for the clarification.

        Somehow, I had the understanding this was a REVIEW. If you are reviewing a product for others, I guess my expectation would be that you describe the product, give some background, explain why anyone would use it, etc. I am happy to apologize for my error and my ignorance about the wonders of PAR. It sounds great.

        Mea Culpa --bibo

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: modulereview [id://372131]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-06-22 23:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.