The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PAR::Repository::Client - Access PAR repositories

SYNOPSIS

  use PAR::Repository::Client;
  
  my $client = PAR::Repository::Client->new(
    uri => 'http://foo/repository',
    http_timeout => 20, # default is 180s
  );
  
  # 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(S?). The access methods are implemented in PAR::Repository::Client::HTTP and PAR::Repository::Client::Local. Any common code is in this module.

PAR::Repository::Query implements the querying interface. The methods described in that module's documentation can be called on PAR::Repository::Client objects.

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.

PUBLIC 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 parameter:

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.

Optional parameters:

  auto_install
  auto_upgrade
  static_dependencies
  cache_dir
  private_cache_dir
  architecture
  perl_version
  installation_targets
  http_timeout
  checksums_timeout

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.

If you set the static_dependencies option to a true value, then the inter-distribution dependency information that is retrieved from the repository will be used to recursively apply your requested action to all dependencies. Essentially, this makes the install_module method act like a real package manager similar to PPM. In contrast, the default behaviour is to fetch distributions only on demand and potentially recursively.

In order to control where the modules are installed to, you can use the installation_targets method.

The optional architecture and perl_version parameters can be used to specify the architecture and perl version that are used to choose the right PAR archives from the repository. Defaults to your running perl, so please read the comments on architecture and perl_version below before blindly using this.

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

You may specify a http_timeout in seconds.

The cache_dir parameter can be used to set the directory where you want the downloaded files to reside. It defaults to the $ENV{PAR_TEMP} directory or otherwise the par subdirectory of your system's temporary directory. If you set cache_dir to something other than the default, the downloaded files should be automatically cached when the HTTP transport layer is used as LWP::mirror() only checks for updates.

By default, each repository client uses its own private cache directory. If you specify private_cache_dir => 0, caching will be mostly disabled. While a private_cache_dir and caching are the default, if you explicitly set a different cache directory with cach_dir, you also have to explicitly flag it as a repository-private cache directory (aka re-enable caching) with private_cache_dir => 1.

By default, it is assumed that the package indices do not change all that often. Therefore, there is a default delay of 30 seconds before their checksums are re-checked as this may require a network request. You can specify in seconds or disable the delay using the checksums_timeout => XX option.

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. If auto-installation or auto-upgrading was enabled, the contents of the PAR distribution will be installed in addition to loading the PAR.

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.

CAVEAT: This will first try to require a locally installed version of the module. If that succeeds, its version is compared to the highest version in the repository. If an upgrade is necessary, the new module will be installed. If the module hadn't been found locally before the installation, it will be loaded. If it was found locally (and thus loaded), IT WILL NOT BE RELOADED SO YOU GET THE NEW VERSION. This is because reloading of modules is not a simple issue. If you need this behaviour, you can get it manually using Class::Unload and another require.

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.

get_module_dependencies

Given a module name, determines the correct distribution in the repository that supplies the module. Returns a reference to an array containing that distribution and all distributions it depends on. The distribution that contains the given module is the first in the array.

Returns the empty list on failure.

get_script_dependencies

Given a script name, determines the correct distribution in the repository that supplies the script. Returns a reference to an array containing that distribution and all distributions it depends on. The distribution that contains the given script is the first in the array.

Returns the empty list on failure.

installation_targets

Sets the installation targets for modules and scripts if any arguments are passed. Returns the current setting otherwise.

Arguments should be key/value pairs of installation targets as recognized by the install_par() routine in PAR::Dist. The contents of this hash are passed verbatim to every call to install_par() made by this package.

In this context, note that aside from the normal i<inst_lib> and similar targets, you can also specify a custom_targets element starting with PAR::Dist version 0.20. For details, refer to the PAR::Dist manual.

Returns a hash reference to a hash containing the installation targets.

ACCESSORS

These methods get or set some attributes of the repository client.

error

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

perl_version

Sets and/or returns the perl version which is used to choose the right .par packages from the repository. Defaults to the currently running perl version (from %Config).

You'd better know what you're doing if you plan to set this to something you're not actually running. One valid use is if you use the installation_targets possibly in conjunction with ExtUtils::InferConfig to install into a different perl than the one that's running!

architecture

Sets and/or returns the name of the architecture which is used to choose the right .par packages from the repository. Defaults to the currently running architecture (from %Config).

You'd better know what you're doing if you plan to set this to something you're not actually running. One valid use is if you use the installation_targets possibly in conjunction with ExtUtils::InferConfig to install into a different perl than the one that's running!

OTHER METHODS

These methods, while part of the official interface, should need rarely be called by most users.

prefered_distribution

This method decides from which distribution a module will be loaded. It returns the corresponding distribution file name.

Takes a namespace as first argument followed by a reference to a hash of distribution file names with associated module versions. Example:

  'Math::Symbolic',
  { 'Math-Symbolic-0.502-x86_64-linux-gnu-thread-multi-5.8.7.par' => '0.502',
    'Math-Symbolic-0.128-any_arch-any_version.par' => '0.128'
  }

This means that the Math::Symbolic namespace was found in version 0.502 and 0.128 in said distribution files. If you were using linux on an x86_64 computer using perl 5.8.7, this would return the first file name. Otherwise, you would only get version 0.128.

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.

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::Query implements the querying interface. The methods described in that module's documentation can be called on PAR::Repository::Client objects.

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

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

AUTHOR

Steffen Mueller, <smueller@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2006-2009 by Steffen Mueller

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.