PAR::Repository::Client - Access PAR repositories
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'!
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::Repository::Query implements the querying interface. The methods described in that module's documentation can be called on PAR::Repository::Client objects.
PAR::Repository::Client
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.
Following is a list of class and instance methods. (Instance methods until otherwise mentioned.)
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.
file:///path/to/repository
/path/to/repository
http://foo
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.
install_module()
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.
In order to control where the modules are installed to, you can use the installation_targets method.
installation_targets
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.
architecture
perl_version
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.
http_timeout
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.
prefered_distribution()
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().
require()
Returns 1 on success, the empty list on failure. In case of failure, an error message can be obtained with the error() method.
error()
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.
require_module
import
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.
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.
get_module
install_par()
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.
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.
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.
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.
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.
PAR::Dist
Returns a hash reference to a hash containing the installation targets.
Returns the last error message if there was an error or the empty list otherwise.
These methods get or set some attributes of the repository client.
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).
.par
%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!
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).
These methods, while part of the official interface, should need rarely be called by most users.
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.
Math::Symbolic
0.502
0.128
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.
Takes one or no arguments. Without arguments, all DBM files are checked. With an argument, only the specified DBM file will be checked.
Returns true if either one of the following conditions match:
The repository does not support checksums.
The checksums (and thus also the DBM files) haven't been downloaded yet.
The local copies of the checksums do not match those of the repository.
In cases two and three above, the return value is actually the hash reference of checksums that was fetched from the repository.
Returns the empty list if the local checksums match those of the repository exactly.
You don't usually need to call this directly. By default, DBM files are only fetched from the repository if necessary.
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.
modules_dists.dbm
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.
_fetch_dbm_file()
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.
scripts_dists.dbm
Closes the modules_dists.dbm file and does all necessary cleaning up.
This is called when the object is destroyed.
Closes the scripts_dists.dbm file and does all necessary cleaning up.
These private methods should not be relied upon from the outside of the module. (See also: PAR::Repository::Client::Util)
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/
PAR
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.
Steffen Mueller, <smueller@cpan.org>
Copyright 2006-2008 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.
To install PAR::Repository::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PAR::Repository::Client
CPAN shell
perl -MCPAN -e shell install PAR::Repository::Client
For more information on module installation, please visit the detailed CPAN module installation guide.