A jar of perl…PAR

PAR is a way to distribute packed perl applications in executable format. Something like jar files for java, but in a platform dependant way. A par file contains all the nested dependencies of a perl script and a par executor.

Shortly, let’s create a perl script

# cat < sample.pl
use Data::Dumper;
my %hash = (“a”=>1, “b”=>2);
print “hash: [“. Dumper(%a).”]”;

an make it an executable file with pp – the par packager:

# pp -o sample.bin sample.pl

Now we get a binary executable file – sample.bin – containing all the dependencies (Data::Dumper) packed as a zip file.

# ll sample.bin;
-rwxr-xr-x 1 rpolli rpolli 3.1M 2012-07-26 10:15 sample.bin

We can really unzip it (but can’t modify wit zip -u or -g) watching the anatomy of the PARchive.

# unzip -t sample.bin
script/sample.pl <- our script file

lib/Data/Dumper.pm <- explicit dependecy

lib/File/Spec.pm <- implicit dependency

Together with the deps we have:
a main.pl file used internally by par
a MANIFEST and META.yml with packaging info

PARchives can still be create as a perl script, saving some space:

# pp -P -o sample.bin.pl sample.pl
# ll -h sample.bin.pl
-rwxr-xr-x 1 rpolli rpolli 25K 2012-07-26 10:28 sample.bin.pl

Next time we’ll see how to unpack and repack a PAR file…