The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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, $rev_number)

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

add()

Adds a new document to the repository. Establishes a new document ID and returns it.

If you wish to simply register the document ID without actually uploading a file, send a zero-byte temp file.

Specify a $revision if you want the document to start at a revision number other than 0.

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

get()

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).

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.

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 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().

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

stats()

Returns a hash containing statistics about the document repository as a whole, such as number of documents, disk space used, etc.