NAME

TM::Resource - Topic Maps, abstract class for resource-backed Topic Maps

SYNOPSIS

# this class is probably only interesting for implementors of individual
# low-level drivers

# see TM for the 'application engineer' API

DESCRIPTION

This class is a subclass of TM, so it implements map objects. It is abstract, though, as it only defined how a resource-backed driver package should behave. It may thus be inherited by classes which implement external formats (TM::Materialized::AsTMa, TM::Materialized::XML, ....) or virtual maps connected to resources.

It defines synchronisations with external resources (read: local/remote files, everything which can be addressed via a URL) given that the map has a last-modified data as the resource.

The methods sync_in, sync_out and last_mod implement the synchronization between the in-memory data structure and the content on the external resource. That resource is specified via a URI.

Predefined URIs

The following resources, actually their URIs are predefined:

io:stdin

Symbolizes the UNIX STDIN file descriptor. The resource is all text content coming from this file.

io:stdout

Symbolizes the UNIX STDOUT file descriptor.

null:

Symbolizes a resource which never delivers any content and which can consume any content silently (like /dev/null under UNIX).

Predefined URI Methods

inline

An inlined resource is a resource which contains all content as part of the URI.

INTERFACE

Constructor

The constructor of implementations should expect a hash as parameter containing the field(s) from TM and one or more of the following:

url:

If given, then the instance will be read from this url whenever synced in.

file:

If given, then the data will be read/written from/to this file. This is just a convenience as it will be mapped to url.

inline:

If given, then the instance will be read directly from this text provided inline when synced.

If several fields (file, url, inline) are specified, it is undefined which one will be used.

Examples (using the AsTMa driver as example):

# opening from an AsTMa= file
$atm = new TM::Materialized::AsTMa (file   => 'here.atm');

# why need a file? files are evil, anyway
$atm = new TM::Materialized::AsTMa (inline => '# this is AsTMa');

Methods

url

$tm->url

Once an object of this class is instantiated it keeps the URL of the resource to which it is associated. This descriptor will always be in form of a URL, regardless whether you used a URL, a file or inline text at instantiation time.

With this method you can retrieve that. You cannot change the URL (well you can, but nothing special will happen).

last_mod

$time = $tm->last_mod

This function returns the UNIX time when the resource has been modified last. undef is returned if the result cannot be determined.

sync_in

$tm->sync_in

If the map is connected to a resource, then this method will try to load the content behind the resource into the map. Depending on the driver, most likely any existing content will be replaced.

If the resource URI is io:stdout, then nothing happens.

If the resource URI is null:, then nothing happens.

If the last modification date of the resource is not younger than that of the map, then no synchronisation happens.

This method provides only the main logic, wether a synchronisation should occur. Implementations, such as materialized maps synchronizing from an XTM resource, will have to implement their specific mechanism which will be triggered here. This is accomplished by a virtual method

sub _sync_in {
    my $self = shift;

    # here the real work happens

}

which all implementations have to provide. (See TM::Materialized::File for an example.)

sync_out

$tm->sync_out

If a map is connected to a resource, then this method contains the logic under which circumstances to synchronize with the external resource.

If the resource URI is io:stdin, nothing happens.

If the resource URI is null:, nothing happens.

If the resource URI is inline:.. nothing happens.

If the map has not changed since the last modification of the external resource, nothing happens.

The real functionality has to be provided by implementations which define

sub _sync_out {
    my $self = shift;

    # hard work here
}

SEE ALSO

TM

AUTHOR INFORMATION

Copyright 200[2-6], Robert Barta <drrho@cpan.org>, All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. http://www.perl.com/perl/misc/Artistic.html