SYNOPSIS

(If you want to make an executable that contains all module, scripts and data files, please consult the pp utility instead. pp used to be part of the \s-1PAR\s0 distribution but is now shipped as part of the PAR::Packer distribution instead.)

Following examples assume a foo.par file in Zip format.

To use Hello.pm from ./foo.par:

    % perl -MPAR=./foo.par -MHello
    % perl -MPAR=./foo -MHello          # the .par part is optional

Same thing, but search foo.par in the @INC;

% perl -MPAR -Ifoo.par -MHello % perl -MPAR -Ifoo -MHello # ditto

Following paths inside the \s-1PAR\s0 file are searched:

/lib/ /arch/ /i386-freebsd/ # i.e. $Config{archname} /5.8.0/ # i.e. $Config{version} /5.8.0/i386-freebsd/ # both of the above /

\s-1PAR\s0 files may also (recursively) contain other \s-1PAR\s0 files. All files under following paths will be considered as \s-1PAR\s0 files and searched as well:

/par/i386-freebsd/ # i.e. $Config{archname} /par/5.8.0/ # i.e. $Config{version} /par/5.8.0/i386-freebsd/ # both of the above /par/

Run script/test.pl or test.pl from foo.par:

% perl -MPAR foo.par test.pl # only when $0 ends in '.par'

However, if the .par archive contains either script/main.pl or main.pl, then it is used instead:

% perl -MPAR foo.par test.pl # runs main.pl; @ARGV is 'test.pl'

Use in a program:

use PAR 'foo.par'; use Hello; # reads within foo.par

# PAR::read_file() returns a file inside any loaded PARs my $conf = PAR::read_file('data/MyConfig.yaml');

# PAR::par_handle() returns an Archive::Zip handle my $zip = PAR::par_handle('foo.par') my $src = $zip->memberNamed('lib/Hello.pm')->contents;

You can also use wildcard characters:

use PAR '/home/foo/*.par'; # loads all PAR files in that directory

Since version 0.950, you can also use a different syntax for loading .par archives:

use PAR { file => 'foo.par' }, { file => 'otherfile.par' };

Why? Because you can also do this:

use PAR { file => 'foo.par, fallback => 1 }; use Foo::Bar;

Foo::Bar will be searched in the system libs first and loaded from foo.par if it wasn't found!

use PAR { file => 'foo.par', run => 'myscript' };

This will load foo.par as usual and then execute the script/myscript file from the archive. Note that your program will not regain control. When script/myscript exits, so does your main program. To make this more useful, you can defer this to runtime: (otherwise equivalent)

require PAR; PAR->import( { file => 'foo.par', run => 'myscript' } );

If you have PAR::Repository::Client installed, you can do this:

use PAR { repository => 'http://foo/bar/' }; use Module; # not locally installed!

And \s-1PAR\s0 will fetch any modules you don't have from the specified \s-1PAR\s0 repository. For details on how this works, have a look at the \s-1SEE\s0 \s-1ALSO\s0 section below. Instead of an \s-1URL\s0 or local path, you can construct an PAR::Repository::Client object manually and pass that to \s-1PAR\s0. If you specify the \*(C`install => 1\*(C' option in the \*(C`use PAR\*(C' line above, the distribution containing \*(C`Module\*(C' will be permanently installed on your system. (\*(C`use PAR { repository => 'http://foo/bar', install => 1 };\*(C')

Furthermore, there is an \*(C`upgrade => 1\*(C' option that checks for upgrades in the repository in addition to installing. Please note that an upgraded version of a module is only loaded on the next run of your application.

Adding the \*(C`dependencies => 1\*(C' option will enable PAR::Repository::Client's static dependency resolution (PAR::Repository::Client 0.23 and up).

Finally, you can combine the \*(C`run\*(C' and \*(C`repository\*(C' options to run an application directly from a repository! (And you can add the \*(C`install\*(C' option, too.)

use PAR { repository => 'http://foo/bar/', run => 'my_app' }; # Will not reach this point as we executed my_app,

DESCRIPTION

This module lets you use special zip files, called Perl Archives, as libraries from which Perl modules can be loaded.

It supports loading \s-1XS\s0 modules by overriding DynaLoader bootstrapping methods; it writes shared object file to a temporary file at the time it is needed.

A .par file is mostly a zip of the blib/ directory after the build process of a \s-1CPAN\s0 distribution. To generate a .par file yourself, all you have to do is compress the modules under arch/ and lib/, e.g.:

% perl Makefile.PL % make % cd blib % zip -r mymodule.par arch/ lib/

Afterward, you can just use mymodule.par anywhere in your @INC, use \s-1PAR\s0, and it will Just Work. Support for generating .par files is going to be in the next (beyond 0.2805) release of Module::Build.

For convenience, you can set the \*(C`PERL5OPT\*(C' environment variable to \*(C`-MPAR\*(C' to enable \*(C`PAR\*(C' processing globally (the overhead is small if not used); setting it to \*(C`-MPAR=/path/to/mylib.par\*(C' will load a specific \s-1PAR\s0 file. Alternatively, consider using the par.pl utility bundled with the PAR::Packer distribution, or using the self-contained parl utility which is also distributed with PAR::Packer on machines without \s-1PAR\s0.pm installed.

Note that self-containing scripts and executables created with par.pl and pp may also be used as .par archives:

% pp -o packed.exe source.pl # generate packed.exe (see PAR::Packer) % perl -MPAR=packed.exe other.pl # this also works % perl -MPAR -Ipacked.exe other.pl # ditto

Please see \*(L"\s-1SYNOPSIS\s0\*(R" for most typical use cases.

NOTES

Settings in \s-1META\s0.yml packed inside the \s-1PAR\s0 file may affect \s-1PAR\s0's operation. For example, pp provides the \*(C`-C\*(C' (\*(C`--clean\*(C') option to control the default behavior of temporary file creation.

Currently, pp-generated \s-1PAR\s0 files may attach four PAR-specific attributes in \s-1META\s0.yml:

par: clean: 0 # default value of PAR_CLEAN signature: '' # key ID of the SIGNATURE file verbatim: 0 # was packed prerequisite's PODs preserved? version: x.xx # PAR.pm version that generated this PAR

User-defined environment variables, like \s-1PAR_GLOBAL_CLEAN\s0, always overrides the ones set in \s-1META\s0.yml. The algorithm for generating caching/temporary directory is as follows:

  • If \s-1PAR_GLOBAL_TEMP\s0 is specified, use it as the cache directory for extracted libraries, and do not clean it up after execution.

  • If \s-1PAR_GLOBAL_TEMP\s0 is not set, but \s-1PAR_CLEAN\s0 is specified, set \s-1PAR_GLOBAL_TEMP\s0 to \*(C`TEMP/par-USER/temp-PID/\*(C', cleaning it after execution.

  • If both are not set, use \*(C`TEMP/par-USER/cache-HASH/\*(C' as the \s-1PAR_GLOBAL_TEMP\s0, reusing any existing files inside.

Here is a description of the variables the previous paths.

  • \s-1TEMP\s0 is a temporary directory, which can be set via $ENV{PAR_GLOBAL_TMPDIR}, $ENV{TMPDIR}, $ENV{TEMPDIR}, $ENV{TEMP} or $ENV{TMP}, in that order of priority. If none of those are set, C:\TEMP, /tmp are checked. If neither of them exists, . is used.

  • \s-1USER\s0 is the user name, or \s-1SYSTEM\s0 if none can be found. On Win32, this is $Win32::LoginName. On Unix, this is $ENV{USERNAME} or $ENV{USER}.

  • \s-1PID\s0 is the process \s-1ID\s0. Forked children use the parent's \s-1PID\s0.

  • \s-1HASH\s0 is a crypto-hash of the entire par file or executable, calculated at creation time. This value can be overloaded with \*(C`pp\*(C''s --tempdir parameter.

By default, \s-1PAR\s0 strips \s-1POD\s0 sections from bundled modules. In case that causes trouble, you can turn this off by setting the environment variable \*(C`PAR_VERBATIM\*(C' to 1.

import options

When you \*(L"use \s-1PAR\s0 {...}\*(R" or call \s-1PAR-\s0>import({...}), the following options are available.

PAR->import({ file => 'foo.par' }); # or PAR->import({ repository => 'http://foo/bar/' });

file

The par filename. You must pass one option of either 'file' or 'repository'.

repository

A par repository (exclusive of file)

fallback

Search the system @INC before the par. Off by default for loading .par files via \*(C`file =\*(C' ...>. On by default for \s-1PAR\s0 repositories. To prefer loading modules from a repository over the locally installed modules, you can load the repository as follows: use PAR { repository => 'http://foo/bar/', fallback => 0 };

run

The name of a script to run in the par. Exits when done.

no_shlib_unpack

Skip unpacking bundled dynamic libraries from shlib/$archname. The client may have them installed, or you may wish to cache them yourself. In either case, they must end up in the standard install location (such as /usr/local/lib/) or in $ENV{\s-1PAR_TEMP\s0} before you require the module which needs them. If they are not accessible before you require the dependent module, perl will die with a message such as \*(L"cannot open shared object file...\*(R"

RELATED TO PAR…

The \s-1PAR\s0 homepage at <http://par.perl.org>.

PAR::Tutorial, \s-1PAR::FAQ\s0 (For a more current \s-1FAQ\s0, refer to the homepage.)

The PAR::Packer distribution which contains the packaging utilities: par.pl, parl, pp.

PAR::Dist for details on \s-1PAR\s0 distributions.

PAR::Repository::Client for details on accessing \s-1PAR\s0 repositories. PAR::Repository for details on how to set up such a repository.

Archive::Zip, \*(L"require\*(R" in perlfunc

ex::lib::zip, Acme::use::strict::with::pride

Steffen Mueller has detailed slides on using \s-1PAR\s0 for application deployment at http://steffen-mueller.net/talks/appdeployment/ <http://steffen-mueller.net/talks/appdeployment/>.

\s-1PAR\s0 supports the prefork module. It declares various run-time dependencies so you can use the prefork module to get streamlined processes in a forking environment.

ACKNOWLEDGMENTS

Nicholas Clark for pointing out the mad source filter hook within the (also mad) coderef @INC hook, as well as (even madder) tricks one can play with PerlIO to avoid source filtering.

Ton Hospel for convincing me to ditch the \*(C`Filter::Simple\*(C' implementation.

Uri Guttman for suggesting \*(C`read_file\*(C' and \*(C`par_handle\*(C' interfaces.

Antti Lankila for making me implement the self-contained executable options via \*(C`par.pl -O\*(C'.

See the \s-1AUTHORS\s0 file in the distribution for a list of people who have sent helpful patches, ideas or comments.

AUTHORS

Audrey Tang <[email protected]>

Steffen Mueller <[email protected]>

<http://par.perl.org/> is the official \s-1PAR\s0 website. You can write to the mailing list at <[email protected]>, or send an empty mail to <[email protected]> to participate in the discussion.

Please submit bug reports to <[email protected]>. If you need support, however, joining the <[email protected]> mailing list is preferred.

COPYRIGHT

Copyright 2002-2010 by Audrey Tang <[email protected]>. Copyright 2005-2010 by Steffen Mueller <[email protected]>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>