NAME

PAR::Repository::Client - Access PAR repositories

SYNOPSIS

  use PAR::Repository::Client;
  
  my $client = PAR::Repository::Client->new(
    uri => 'http://foo/repository',
  );
  
  # This is happening at run-time, of course:
  # But calling import from your namespace
  $client->use_module('Foo::Bar') or die $client->error;
  
  $client->require_module('Bar::Baz') or die $client->error;
  
  $client->run_script('foo', 'arg1', 'arg2') or die $client->error;
  # should not be reached since we ran 'foo'!

DESCRIPTION

This module represents the client for PAR repositories as implemented by the PAR::Repository module.

Chances are, you should be looking at the PAR module instead. Starting with version 0.950, it supports automatically loading any modules that aren't found on your system from a repository. If you need finer control than that, then this module is the right one to use.

You can use this module to access repositories in one of two ways: On your local filesystem or via HTTP. The access methods are implemented in PAR::Repository::Client::HTTP and PAR::Repository::Client::Local. Any common code is in this module.

PAR REPOSITORIES

For a detailed discussion of the structure of PAR repositories, please have a look at the PAR::Repository distribution.

A PAR repository is, well, a repository of .par distributions which contain Perl modules and scripts. You can create .par distributions using the PAR::Dist module or the PAR module itself.

If you are unsure what PAR archives are, then have a look at the "SEE ALSO" section below, which points you at the relevant locations.

METHODS

Following is a list of class and instance methods. (Instance methods until otherwise mentioned.)

new

Creates a new PAR::Repository::Client object. Takes named arguments.

Mandatory paramater:

uri specifies the URI of the repository to use. Initially, http and file URIs will be supported, so you can access a repository locally using file:///path/to/repository or just with /path/to/repository. HTTP accessible repositories can be specified as http://foo and https://foo.

If the optional auto_install parameter is set to a true value (default: false), any .par file that is about to be loaded is installed on the local system instead. In this context, please refer to the install_module() method.

Similar to auto_install, the auto_upgrade parameter installs a distribution that is about to be loaded - but only if the specified module does not exist on the local system yet or is outdated.

You cannot set both auto_install and auto_upgrade. If you do, you will get a fatal error.

Upon client creation, the repository's version is validated to be compatible with this version of the client.

require_module

First argument must be a package name (namespace) to require. The method scans the repository for distributions that contain the specified package.

When one or more distributions are found, it determines which distribution to use using the prefered_distribution() method.

Then, it fetches the prefered .par distribution from the repository and opens it using the PAR module. Finally, it loads the specified module from the downloaded .par distribution using require().

Returns 1 on success, the empty list on failure. In case of failure, an error message can be obtained with the error() method.

use_module

Works the same as the require_module method except that instead of only requiring the specified module, it also calls the import method if it exists. Any arguments to this methods after the package to load are passed to the import call.

get_module

First parameter must be a namespace, second parameter may be a boolean indicating whether the PAR is a fallback-PAR or one to load from preferably. (Defaults to false which means loading preferably.)

Searches for a specified namespace in the repository and downloads the corresponding PAR distribution. Automatically loads PAR and appends the downloaded PAR distribution to the list of PARs to load from.

Returns the name of the local PAR file. Think of this as require_module without actually doing a require() of the module.

install_module

Works the same as get_module but instead of loading the .par file using PAR, it installs its contents using PAR::Dist's install_par() routine.

First argument must be the namespace of a module to install.

Note that this method always installs the whole .par distribution that contains the newest version of the specified namespace and not only the .pm file from the distribution which contains the specified namespace.

Returns the name of the local .par file which was installed or the empty list on failure.

upgrade_module

Works the same as get_module but instead of loading the .par file using PAR, it checks whether the local version of the module is current. If it isn't, the distribution containing the newest version of the module is installed using PAR::Dist's install_par() routine.

First argument must be the namespace of a module to upgrade.

Note that this method always installs the whole .par distribution that contains the newest version of the specified namespace and not only the .pm file from the distribution which contains the specified namespace.

Returns the name of the local .par file which was installed or the empty list on failure or if the local version of the module is already current.

run_script

First parameter must be a script name.

Searches for a specified script in the repository and downloads the corresponding PAR distribution. Automatically loads PAR and appends the downloaded PAR distribution to the list of PARs to load from.

Then, it runs the script. It does not return unless some error occurrs.

If either auto_install or auto_upgrade were specified as parameters to the constructor, the downloaded PAR distribution will be installed regardless of the versions of any previously installed scripts. This differs from the behaviour for mdoules.

error

Returns the last error message if there was an error or the empty list otherwise.

prefered_distribution

Takes a namespace as first argument followed by a reference to a hash of distribution file names with associated module versions. The file name should have the following form:

  Math-Symbolic-0.502-x86_64-linux-gnu-thread-multi-5.8.7.par

This method decides which distribution to load and returns that file name.

validate_repository_version

Accesses the repository meta information and validates that it has a compatible version. This is done on object creation, so it should not normally be necessary to call this from user code.

Returns a boolean indicating the outcome of the operation.

_modules_dbm

This is a private method.

Fetches the modules_dists.dbm database from the repository, ties it to a DBM::Deep object and returns a tied hash reference or the empty list on failure. Second return value is the name of the local temporary file.

In case of failure, an error message is available via the error() method.

The method uses the _fetch_dbm_file() method which must be implemented in a subclass such as PAR::Repository::Client::HTTP.

_scripts_dbm

This is a private method.

Fetches the scripts_dists.dbm database from the repository, ties it to a DBM::Deep object and returns a tied hash reference or the empty list on failure. Second return value is the name of the local temporary file.

In case of failure, an error message is available via the error() method.

The method uses the _fetch_dbm_file() method which must be implemented in a subclass such as PAR::Repository::Client::HTTP.

_close_modules_dbm

This is a private method.

Closes the modules_dists.dbm file and does all necessary cleaning up.

This is called when the object is destroyed.

_close_scripts_dbm

This is a private method.

Closes the scripts_dists.dbm file and does all necessary cleaning up.

This is called when the object is destroyed.

_unzip_file

This is a private method. Callable as class or instance method.

Unzips the file given as first argument to the file given as second argument. If a third argument is used, the zip member of that name is extracted. If the zip member name is omitted, it is set to the target file name.

Returns the name of the unzipped file.

SEE ALSO

This module is directly related to the PAR project. You need to have basic familiarity with it. Its homepage is at http://par.perl.org/

See PAR, PAR::Dist, PAR::Repository, etc.

PAR::Repository implements the server side creation and manipulation of PAR repositories.

PAR::WebStart is doing something similar but is otherwise unrelated.

AUTHOR

Steffen Müller, <smueller@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Steffen Müller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 810:

Non-ASCII character seen before =encoding in 'Müller,'. Assuming UTF-8