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

NAME

Document::Repository

SYNOPSIS

my $repository = new Document::Repository;

my $doc_id = $repository->add($filename);

my $filename = $repository->get($doc_id, $dir);

$repository->put($doc_id, $filename, $filename, $filename) or die "couldn't put $filename";

$repository->delete($doc_id) or die "couldn't delete $doc_id";

DESCRIPTION

This module implements a repository of documents, providing general access to add/get/delete documents. This module is not intended to be used directly; for that see Document::Manager. This acts as a general purpose backend.

A document is a collection of one or more files that are checked out, modified, and checked back in as a unit. Each revision of a document is numbered, and documents can be reverted to older revisions if needed. A document can also have an arbitrary set of metadata associated with it.

FUNCTIONS

new($confighash)

Establishes the repository interface object. You must pass it the location of the repository, and optionally can indicate what permissions to use (0600 is the default).

If the repository already exists, indicate where Document::Repository should start its numbering (e.g., you may want to store this info in a config file or something between invokations...)

get_error()

Retrieves the most recent error message

repository_path($doc_id)

Returns a path to the location of the document within the repository repository.

current_revision($doc_id, [$doc_path])

Returns the current (latest & highest) revision number for the document, or undef if there is no revisions for the document or if the document does not exist.

You must specify the $doc_id to be looked up. Optionally, the $doc_path may be given (saves the lookup time if you have already calculated it).

add(@filenames)

Adds a new document of revision 001 to the repository by adding its files. Establishes a new document ID and returns it.

If you wish to simply register the document ID without actually uploading files, @filenames can be left undefined.

Returns undef on failure. You can retrieve the error message by calling get_error().

put($doc_id, @filenames)

Adds a new revision to a document in the repository. All files must exist.

Returns the revision number created, or undef on failure. You can retrieve the error message by calling get_error().

get($doc_id, $revision, $destination, [$copy_function], [$select_function])

Retrieves a copy of the document specified by $doc_id of the given $revision (or the latest, if not specified), and places it at $location (or the cwd if not specified).

See files() for a description of the optional \&select_function.

The document is copied using the routine specified by $copy_function. This permits overloading the behavior in order to perform network copying, tarball dist generation, etc.

If defined, $copy_function must be a reference to a function that accepts two parameters: an array of filenames (with full path) to be copied, and the $destination parameter that was passed to get(). The caller is allowed to define $destination however desired - it can be a filename, URI, hash reference, etc. $copy_function should return a list of the filenames actually copied.

If $copy_function is not defined, the default behavior is simply to call the File::Copy routine copy($fn, $destination) iteratively on each file in the document, returning the number of files

Returns a list of files (or the return value from $copy_function), or undef if get() encountered an error (such as bad parameters). The error message can be retrieved via get_error().

content( $filename, $doc_id [, $revision] )

Retrieves the contents of a file within the given document id.

If the specified filename is actually a directory, returns an array of the files in that directory, instead.

Returns undef and sets an error (retrievable via get_error() if there is any problem.

update( $filename, $doc_id, $content[, $append] )

This routine alters a file within the repository without creating a new revision number to be generated. This is not intended for regular use but instead for adding comments, updating metadata, etc.

By default, update() replaces the existing file. If $append is defined, however, update() will append $content onto the end of the file (such as for logs). Note that no separation characters are inserted, so make sure to add newlines and record delimiters if you need them.

Returns a true value if the file was successfully updated, or undef on any error. Retrieve the error via get_error();

documents()

Returns a list of document ids in the system.

Note that if you have a lot of documents, this list could be huge, but it's assumed you know what you're doing in this case...

revisions()

Lists the revisions for the given document id

files($doc_id, $revision, [\&selection_function], [$with_path])

Lists the files for the given document id and revision (or the latest revision if not specified.)

The optional \&selection_function allows customized constraints to be placed on what files() returns. This function must accept a file path and return true if the file should be selected for the list to return.

The optional $with_path argument allows control over whether to return files with their path prepended or not.

stats()

Returns a hash containing statistics about the document repository as a whole, including the following:

* num_documents * num_revisions * disk_space * num_files * next_id