Perl Advent Calendar 2006-12-22

…and a PARtridge in a PAR tree

by Jerrad Pierce

When Mark Fowler first covered PAR in 2003, useful though it may have been, it was still quite young and not much more than a linker for modules and scripts. The accompanying pp (now in PAR::Packer) also allowed for the linking of the perl binary, and therefore the distribution of a program as a stand-alone executable. Since then a little noticed1 addition has matured.

PAR::Dist allows one to package modules—any random module, or multiple modules together through merge_par—for redistribution and installation. You can thusly use PARchives as an alternative to RPMs (or whatever your distribution uses), ActiveState's PPMs, or a Bundle::. Some of the benefits of such a scheme are the abilities to compile and test only once for a given platform (potentially saving a lot of time), and to install modules without network access.

An interesting extension to PAR::Dist is PAR::Dist::FromCPAN. Both are usable programatically, but the latter provides the convenient cpan2par wrapper for use from the command line. The results of

$ cpan2par -P Regexp::Keep

are lots of the usual CPAN install spew, some additional messages from PAR::Dist::FromCPAN and finally the PARchive.

$ unzip -t Regexp-Keep-0.02-i386-linux-thread-multi-5.8.0.par
Archive:  Regexp-Keep-0.02-i386-linux-thread-multi-5.8.0.par
    testing: lib/                     OK
    testing: lib/Regexp/              OK
    testing: lib/Regexp/.exists       OK
    testing: lib/Regexp/       OK
    testing: lib/auto/                OK
    testing: lib/auto/Regexp/         OK
    testing: lib/auto/Regexp/Keep/    OK
    testing: lib/auto/Regexp/Keep/.exists   OK
    testing: arch/                    OK
    testing: arch/auto/               OK
    testing: arch/auto/Regexp/        OK
    testing: arch/auto/Regexp/Keep/   OK
    testing: arch/auto/Regexp/Keep/.exists   OK
    testing: arch/auto/Regexp/Keep/   OK
    testing: arch/auto/Regexp/Keep/   OK
    testing: man3/                    OK
    testing: man3/.exists             OK
    testing: man3/Regexp::Keep.3pm    OK
    testing: MANIFEST                 OK
    testing: META.yml                 OK
No errors detected in compressed data of Regexp-Keep-0.02-i386-linux-thread-multi-5.8.0.par.

(Un)fortunately, PAR::Dist::install_par does not seem to check that the archive platform/perl version matches/is appropriate for the target system. On the one hand, this means you can install PARchives containing XS modules on sufficiently similar setups without a hitch. On the other hand, it gives you enough rope to yank out your tooth. I was able to install_par the PARchive above on a Solaris box, though clearly not use it.

Note: If you happen to encounter the PARchive build error with v.04:
No such file or directory at …/PAR/ line 249
All may not be lost, see this RT ticket.


Apache::PAR, PAR::Dist::InstallPPD


1. As of 2006-12-23 I am only able to find two PARchives online; XML::Parser for Darwin. and POE::Component::IRC for Windows.