NAME
Test::AutoBuild::Archive - archival of files and metadata
SYNOPSIS
  my $manager = [...get instance of Test::AutoBuild::ArchiveManager...]
  my $archive = $manager->get_current_archive;
  my %orig_files = (
    "/usr/src/redhat/RPMS/noarch/autobuild-1.0.0-1.noarch.pm" => ...metadata...
  );
  # Save status of the 'build' action for module 'autobuild-dev'
  $archive->save_data("autobuild-dev",
		      "build",
		      "success");
  # Save list of packages associated with module 'autobuild-dev'
  $archive->save_files("autobuild-dev",
		       "packages",
		       \%orig_files,
		       { link => 1,
			 move => 1,
			 base => "/usr/src/redhat"});
  # Retrieve status of the 'build' action for module 'autobuild-dev'
  my $status = $archive->get_data("autobuild-dev",
				  "build");
  # Retrieve metadata associated with saved files
  my $metadat = $archive->get_files("autobuild-dev",
				    "packages");
  # Save RPMSs to an HTTP site
  $archive->extract_files("autobuild-dev",
			  "packages",
			  "/var/www/html/packages/autobuild-dev",
			  { link => 1 });
DESCRIPTION
The Test::AutoBuild::Archive module provides an API for associating chunks of data and files, with objects, persisting them to some form of storage. Each object in the archive is uniquely identified by an alphanumeric string, and can in turn contain many storage buckets, again uniquely identified by an alphanumeric string. An individual bucket can store a chunk of metadata, and a set of files at any one time. Each file stored can also have a chunk of associated metadata. Conceptually the organization of an archive is thus
ROOT
 |
 +- myobject
 |   |
 |   +- mybucket
 |   |   |
 |   |   +- DATA       - chunk of generic metadata
 |   |   +- FILES      - set of files
 |   |   +- FILE-DATA  - chunk of metadata about FILES
 |   |
 |   +- otherbucket
 |   |   |
 |   |   +- DATA       - chunk of generic metadata
 |   |   +- FILES      - set of files
 |   |   +- FILE-DATA  - chunk of metadata about FILES
 |   |
 |   +- ...
 |
 +- otherobject
 |   |
 |   +- mybucket
 |   |   |
 |   |   +- DATA       - chunk of generic metadata
 |   |   +- FILES      - set of files
 |   |   +- FILE-DATA  - chunk of metadata about FILES
 |   |
 |   +- otherbucket
 |   |   |
 |   |   +- DATA       - chunk of generic metadata
 |   |   +- FILES      - set of files
 |   |   +- FILE-DATA  - chunk of metadata about FILES
 |   |
 |   +- ...
 |
 +- ...
METHODS
- $archive->save_data($object, $bucket, $data);
 - 
Save a chunk of data
$dataassociated with object$objectinto the storage bucket named$bucket. Both the$objectand$bucketparameters must be plain strings comprising characters from the set 'a'..'z','A'..'Z','0'-'9','-','_' and '.'. The$datacan be comprised scalars, array references and hash references. Code references and file handles are forbidden. If there is already data present in the bucket$bucketassociated with the object$objectthen an error will be thrown. The data can later be retrieved from the archive by calling theget_datamethod with matching arguments for object and bucket. - $archive->save_files($object, $bucket, $files, $options)
 - 
Saves a set of files
$filesassociated with object$objectinto the storage bucket named$bucket. Both the$objectand$bucketparameters must be plain strings comprising characters from the set 'a'..'z','A'..'Z','0'-'9','-','_' and '.'. The$filesparameter should be a hash reference where the keys are fully qualified file names, and the values are arbitrary chunks of data, comprised of scalars, array references and hash references. Code references and file handles are forbidden. If there are already files present in the bucket$bucketassociated with the object$objectthen an error will be thrown. The data can later be retrieved from the archive by calling theextract_filesmethod with matching arguments for object and bucket. A listing of files stored in the archive can be retrieved by calling the methodget_fileswith matching arguments for object and bucket. The$optionsparameter controls the way in which the files are stored. It can contain the following keys- link
 - 
Attempt to hardlink the files into the archive, rather than doing a regular copy. In combination with same option on the
extra_filesandattach_filesmethods, this allows for considerable conversation of disk space, by only ever having one copy of the data no matter how many locations the file is kept. Care must be taken, however, to ensure that the contents of the original file is not modified after the archive is saved. If omitted, defaults to 0. - move
 - 
Delete the original file after copying it into the archive. This can also be used in combination with the
linkoption as protect. If omitted, defaults to 0 - base
 - 
When storing the filenames, trim the directory prefix specified by the value to this option, off the front of the filenames to form a relative filename. This can be useful when later extracting the files back out to an alternate directory. If omitted, defaults to the root directory.
 - flatten
 - 
When storing the filenames, trim off the entire directory prefix, only maintaining the basic filename. If two files have the same filename after trimming, an error will be thrown. If omitted, defaults to 0.
 
This method returns a hash reference, whose keys are the filenames saved, relative to the value associated with the
basekey in the$optionsparameter. - $archive->_save_metadata($object, $bucket, $datatype, $data);
 - 
This an internal method to be implemented by subclasses, to provide the actual storage for metadata. The
$objectand$bucketparameters are as per thesave_dataorsave_filesmethods. Thedatatypeparameter is a key, eitherDATAto indicate general metadata being saved, orFILESto indicate the per file metadata. Finally, the$dataparameter is the actual data to be saved, which may be a scalar, hash reference or array reference, nested to arbitrary depth. Implementations must throw an error if the archive already contains data stored against the tuple ($object,$bucket,$type). - my $copied = $archive->clone_files($object, $bucket, $archive, $options);
 - 
This method copies the files associated with the object
$objectin bucket$bucketin the archive$archiveover to this archive. If thelinkkey is specified as an option, then implementations are free to implement this as a zero-copy operation to save storage. This method returns a hash reference whose keys are the list of filenames, relative to their original base directory, and whose values are the metadata associated with each file. - $archive->_persist_files($object, $bucket, $files, $options);
 - 
This an internal method to be implemented by subclasses, to provide the actual storage for metadata. The
$objectand$bucketparameters are as per thesave_dataorsave_filesmethods. The$filesparameter is a hash reference detailing the files to be persisted. The keys of the hash reference are filenames relative to the directory specified by thebasekey in the$optionsparameter. The$optionsparameter can also contain the keyslinkto indicate zero-copy persistence of files, andmoveto indicate the original file should be deleted. - my @objects = $archive->list_objects
 - 
Retrieves a list of all objects which have either files or metadata stored in this archive. The returned list of objects is sorted alphabetically.
 - my @objects = $archive->_get_objects
 - 
This is an internal method used to retrieve the list of objects stored in the archive. This should return a list of objects stored, but need not sort them in any particular order. This method must be implemented by subclasses.
 - my @buckets = $archive->list_buckets($object)
 - 
Retrieves a list of all storage buckets associated with the object
$object. The returned list of buckets is not sorted in any particular order. If the object$objectis not stored in this archive, then the empty list is to be returned. This method must be implemented by subclasses. - my $data = $archive->get_data($object, $bucket);
 - 
Retrieves the data in the bucket
$bucketassociated with the object$object, which was previously stored with thesave_datamethod. 
AUTHORS
Dennis Gregorovic <dgregorovic@alum.mit.edu>, Daniel Berrange <dan@berrange.com>
COPYRIGHT
Copyright (C) 2003-2004 Dennis Gregorovic <dgregorovic@alum.mit.edu>, Copyright (C) 2005 Daniel Berrange <dan@berrange.com>
SEE ALSO
perl(1), Test::AutoBuild::ArchiveManager, Test::AutoBuild::Archive::File