Chris Winters


OpenInteract2::Repository - Operations to manipulate package repositories.


  # Get a reference to a repository
  my $repository = OpenInteract2::Repository->new( CTX->base_config );
  # OR a handy shortcut
  my $repository = CTX->repository;
 # Create a new package, set some properties and save to the repository
  my $pkg_info = {
      name        => 'MyPackage',
      version     => 3.13,
      author      => 'Arthur Dent <>',
      base_dir    => '/path/to/installed/OpenInteract',
      package_dir => 'pkg/mypackage-3.13',
 $repository->save_package_info( $info );
 # Retrieve the installed version of a package
 my $pkg = eval { $repository->fetch_package( 'MyPackage' ) };
 unless ( $pkg ) {
     oi_error "No package found with name 'MyPackage'";
 # Install a package
 my $pkg = OpenInteract2::Package->install( .. );
 eval { $repository->add_package( $pkg ) };
 if ( $@ ) {
     print "Could not add package to repository! Error: $@";
 else {
     print "Package ", $pkg->name, " ", $pkg->version, " installed ok!";
 # Install to website (apply package)
 my $info = eval { $repository->fetch_package( 'mypackage' ) };
 my $site_repository = OpenInteract2::Package->fetch(
                                      { directory => "/home/MyWebsiteDir" } );
 $info->{installed_on}  = $repository->now;
 $site_repository->save_package_info( $info );
 # Create a package skeleton (for when you are developing a new
 # package)
 $repository->create_package_skeleton( $package_name );
 # Export a package into a tar.gz distribution file
 chdir( '/home/MyWebsiteDir' );
 my $status = OpenInteract2::Package->export_package();
 print "Package: $status->{name}-$status->{version} ",
       "saved in $status->{file}";
 # Find a file in a package
 my $filename = $repository->find_file(
                         'MyPackage', 'template/mytemplate.tmpl' );
 open( TMPL, $filename ) || die "Cannot open $filename: $!";
 while ( <TMPL> ) { ... }


The package repository stores references to all currently installed packages to an OpenInteract website. This ensures OpenInteract can always find which version of a package to use and acts as a facade for retrieving packages by name from a website.

The repository is stored in INI format to your website's conf/ dir, normally with the name repository.ini. (The default filename of the repository is always available in the exported constant REPOSITORY_FILE.) The repository does not contain much information, just the name, version and directory for all installed packages.

The OpenInteract2::Context will create and store a repository object when it's initialized, so you normally only use it rather than create it.


new( [ $base_config | \%params ] )

Creates a new repository object. You normally do not call this directly, since you can easily retrieve the repository from the context.

Initialization is preferred with $base_config, which is a OpenInteract2::Config::Base object. This contains the website, config and package directories we need to initialize the repository.

You can also pass in a hashref of parameters to accomplish the same goal. It may have the following keys defined:


The full path to the website.

config_dir (optional)

The relative path to the configuration directory. (Defaults to conf.)

package_dir (optional)

The relative path to the package directory. (Defaults to pkg.)

repository_file (optional)

The name of the repository file. (Defaults to the REPOSITORY_FILE constant.)

If a valid website and configuration directory are specified, we set the property repository_file to the full path to the repository and try to read it in. So if you want to create a new repository do not instantiate it with the necessary path information. Just create it with no parameters and set them after instantiation.

Returns: repository object.


Returns: full path to the configuration directory


Returns: full path to the package directory

fetch_package( $package_name )

Retrieves a package from the repository by $package_name. If no package matches $package_name returns undef.


 my $pkg = $repository->fetch_package( 'zigzag' );
 if ( $pkg ) {
     print "Latest installed version of zigzag: ", $pkg->version, "\n";

Returns: OpenInteract2::Package object if in the repository, undef if not.


Returns: Arrayref of all packages hashrefs in a particular repository.

Returns: Arrayref of all OpenInteract2::Package objects in the repository.

add_package( $package )

Given an OpenInteract2::Package object, add it to the repository. If an older version of $package already exists in the repository, we first remove that then add the new one. The repository should not be in an inconsistent state if any part of this fails.

Returns: repository

remove_package( $package )

Removes package $package from the repository. It may fail due to unforeseen I/O errors.

Returns: repository

find_file( $package_name, @files )

Shortcut to find a particular package by name and if found call the find_file() method on it, passing @files as the argument. See OpenInteract2::Package#find_file for more.

Returns: First file from @files that exists in package $package_name Throws exception if $package_name not provided or package corresponding to $package_name not found.


Nothing known.


None known.




Copyright (c) 2002-2004 Chris Winters. All rights reserved.

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


Chris Winters <>