NAME

OpenInteract::PackageRepository - Operations to represent, install, remove and otherwise manipulate package repositories.

SYNOPSIS

 # Get a reference to a repository

 my $repository = OpenInteract::PackageRepository->fetch(
                                    undef,
                                    { directory => '/opt/OpenInteract' } );

# Create a new package, set some properties and save to the repository

 my $pkg_info = {
     name        => 'MyPackage',
     version     => 3.13,
     author      => 'Arthur Dent <arthurd@earth.org>',
     base_dir    => '/path/to/installed/OpenInteract',
     package_dir => 'pkg/mypackage-3.13',
};
$repository->save_package_info( $info );

# Retrieve the latest version of a package

my $info = eval { $repository->fetch_package_by_name({
                                       name => 'MyPackage' }) };
unless ( $info ) {
  die "No package found with that name!";
}

# Retrieve a specific version

my $info = eval { $repository->fetch_package_by_name({
                                       name    => 'MyPackage',
                                       version => 3.12 }) };
unless ( $info ) {
  die "No package found with that name and version!";
}

# Install a package

my $info = eval { $repository->install_package({
                      package_file => $OPT_package_file }) };
if ( $@ ) {
  print "Could not install package! Error: $@";
}
else {
  print "Package $info->{name}-$info->{version} installed ok!";
}

# Install to website (apply package)

my $info = eval { $repository->fetch_package_by_name({
                                       name    => 'MyPackage',
                                       version => 3.12 }) };
my $site_repository = OpenInteract::Package->fetch(
                                     undef,
                                     { directory => "/home/MyWebsiteDir" } );
$info->{website_name} = "MyApp";
$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 = OpenInteract::Package->export_package();
print "Package: $status->{name}-$status->{version} ",
      "saved in $status->{file}";

# Find a file in a package

$repository->find_file({ package => 'MyPackage',
                         file    => 'template/mytemplate.tmpl' });
open( TMPL, $filename ) || die "Cannot open $filename: $!";
while ( <TMPL> ) { ... }

DESCRIPTION

This is a different type of module than many others in the OpenInteract:: hierarchy. Instead of being created from scratch, the configuration information is in the class rather than in a configuration file. It does not use a SQL database for a back end. It does not relate to any other objects.

Instead, all we do is represent a package repository. An OpenInteract package repository is a collection of metadata about files installed to a particular location, known as a package. The OpenInteract package is a means of distributing Perl object and handler code, configuration, SQL structures and data, templates and anything else necessary to implement a discrete set of functionality.

A package can exist in two places: in the base installation and in one or more websites. (You can tell the difference when you are going through a package information hashref because website packages have the property 'website_dir' defined.)

The package in the base installation is the master package and should never be changed. Since you never use it directly, you should never need to change it, either. Every time you create a website the website gets a customized copy of the master package. The website author can then change the website package as much as desired without affecting the base installation master package.

METHODS

_class_initialize( $CONFIG )

When we initialize the class we want to use the OpenInteract installation directory for the default package database location.

pre_save_action

Ensure that before we add a package to a database it has the 'base_dir' property.

fetch_package_by_name( \%params )

Retrieve a package by name and/or version. If you ask for a specific version and that version does not exist, you will get nothing back. If you do not ask for a version, you will get the latest one available.

Parameters:

  • name ($)

    Package name to retrieve

  • version ($) (optional)

    Version of package to retrieve; if you specify a version then *only* that version can be returned.

Example:

my $pkg = $pkg_class->fetch_by_name( { name => 'zigzag' } );
if ( $pkg ) {
  print "Latest installed version of zigzag: $pkg->{version}\n";
}

fetch_all_packages()

Returns: Arrayref of all package information hashrefs in a particular repository.

verify_package( @package_names )

Verify that each of the packages listed in @package_names exists for this repository.

Returns: For each package verified a hashref of the package information. If you pass only one name, you get a single result back; multiple names get returned in an arrayref.

verify_package_list( @package_names )

The same as verify_package() except we return a list reference of package instead of a single

find_file( [ $package_name | \%package_info ], @file_list )

Pass in one or more possible variations on a filename that you wish to find within a package. If you pass multiple files, each will be checked in order. Note that the name must include any directory prefix as well. For instance:

$repos->find_file( 'mypackage',
                   'template/mytemplate', 'template/mytemplate.tmpl' );

Returns a full filename of an existing file, undef if no existing file found matching any of the filenames passed in.

include_package_dir

Put both the base package dir and the website package_dir into @INC. Both directories are put onto the front of @INC, the website directory first and then the base directory. (This enables packages found in the app to override the base.) Both directories are first tested to ensure they actually exist.

Returns: directories that were unshifted onto @INC, in the same order.

TO DO

Nothing known.

BUGS

None known.

SEE ALSO

OpenInteract::Package, OpenInteract documentation: Packages in OpenInteract

COPYRIGHT

Copyright (c) 2001-2002 intes.net, inc.. All rights reserved.

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

AUTHORS

Chris Winters <chris@cwinters.com>

Christian Lemburg <lemburg@aixonix.de> suffered through early versions of the package management system and offered insightful feedback, including a pointer to ExtUtils::Manifest and the advice to move to a text-based storage system.