DAIA - Document Availability Information API
version 0.421
This package includes and installs the client program daia to fetch, validate and convert DAIA data (both command line and CGI). See also the clients directory for an XML Schema of DAIA/XML and an XSLT script to transform DAIA/XML to HTML.
daia
clients
use DAIA; # or: use DAIA qw(parse); $daia = DAIA::parse( $url ); $daia = DAIA::parse( file => $file ); $daia = DAIA::parse( data => $string ); # $string must be Unicode
It is highly recommended to use Plack:App::DAIA instead of creating a DAIA server from scratch. The following example implements a DAIA Server without this module.
use DAIA; use CGI; my $id = CGI->new->param('id'); my $r = response( institution => { href => "http://example.com/your-institution's-homepage", content => "Your institution's name" } ); $r->addMessage("en" => "Not an URI: $id", errno => 1 ) unless DAIA::is_uri($id); my @holdings = get_holding_information($id); # your custom method if ( @holdings ) { my $doc = document( id => $id, href => "http://example.com/docs/$id" ); foreach my $h ( @holdings ) { my $item = item(); my %stor = get_holding_storage( $h ); # your custom method $item->storage( id => $stor{id}, href => $stor{href}, $stor{name} ); $item->label( get_holding_label( $h ) ); # your custom method $item->href( get_holding_url( $h ) ); # your custom method # add availability services my @services; if ( get_holding_is_here( $h ) ) { # your custom method push @services, available('presentation'), available('loan'); } elsif( get_holding_is_not_here( $h ) ) { # your custom method push @services, # expected to be back in 5 days unavailable( 'presentation', expected => 'P5D' ), unavailable( 'loan', expected => 'P5D' ); } else { # more cases (depending on the complexity of you application) } $item->add( @services ); } $r->document( $doc ); } else { $r->addMessage( "en" => "No holding information found for id $id" ); } $r->serve( xslt => "http://path.to/daia.xsl" );
To run your script as CGI, you may have to enable CGI with Options +ExecCGI and AddHandler cgi-script .pl in your Apache configuration or in .htaccess.
Options +ExecCGI
AddHandler cgi-script .pl
.htaccess
The Document Availability Information API (DAIA) defines a model of information about the current availability of documents, for instance in a library. DAIA includes a specification of serializations in JSON, XML, and RDF. More details can be found in the DAIA specification at http://purl.org/NET/DAIA and at the developer repository at http://daia.sourceforge.net/.
This package provides Perl classes and functions to easily create and manage DAIA information in any form. It can be used to quickly implement DAIA servers, clients, and other programs that handle availability information of documents.
The most important concepts of the DAIA model are:
These abstract works or editions are implemented as objects of class DAIA::Document.
These particular copies of documents (physical or digital) are implemented as objects of class DAIA::Item.
availability status
A service is something that can be provided with an item. A particular service has a particular availability status, that is implemented as object of class DAIA::Available or DAIA::Unavailable.
A boolean value and a service that indicates for what an item is available or not available. Implemented as DAIA::Availability with the subclasses DAIA::Available and DAIA::Unavailable.
A response contains information about the availability of documents at a given point in time, optionally at some specific institution. It is implemented as object of class DAIA::Response.
Additional DAIA objects include institutions (DAIA::Institution), departments (DAIA::Department), storages (DAIA::Storage), messages and errors (DAIA::Message). All these objects provide standard methods for creation, modification, and serialization. This package also exports functions as shorthand for object constructors, for instance the following two result in the same:
item( id => $id ); DAIA::Item->new( id => $id );
By default constructor functions are exported for all objects. To disable exporting, include DAIA like this:
use DAIA qw(); # do not export any functions use DAIA qw(serve); # only export function 'serve' use DAIA qw(:core); # only export core functions
You can select two groups, both are exported by default:
:core
response, document, item, available, unavailable, availability
response
document
item
available
unavailable
availability
:entities
institution, department, storage, limitation
institution
department
storage
limitation
Additional functions are message as object constructor, and serve. The other functions below are not exported by default. You can call them as method or as function, for instance:
message
serve
DAIA->parse_xml( $xml ); DAIA::parse_xml( $xml );
Calls the method method serve of DAIA::Response or another DAIA object to serialize and send a response to STDOUT with appropriate HTTP headers. You can call it this way:
serve( $response, @additionlArgs ); # as function $response->serve( @additionlArgs ); # as method
Parse DAIA/XML or DAIA/JSON from a file or string. You can specify the source as filename, string, or IO::Handle object as first parameter or with the named from parameter. Alternatively you can either pass a filename or URL with parameter file or a string with parameter data. If from or file is an URL, its content will be fetched via HTTP. The format parameter (json or xml) is required unless the format can be detected automatically the following way:
from
file
data
format
json
xml
A scalar starting with < and ending with > is parsed as DAIA/XML.
<
>
A scalar starting with { and ending with } is parsed as DAIA/JSON.
{
}
A scalar ending with .xml is is parsed as DAIA/XML file.
.xml
A scalar ending with .json is parsed as DAIA/JSON file.
.json
A scalar starting with http:// or https:// is used to fetch data via HTTP. The resulting data is interpreted again as DAIA/XML or DAIA/JSON.
http://
https://
Normally this function or method returns a single DAIA object. When parsing DAIA/XML it may also return a list of objects. It is recommended to always expect a list unless you are absolutely sure that the result of parsing will be a single DAIA object.
Parse DAIA/XML from a file or string. The first parameter must be a filename, a string of XML, or a IO::Handle object.
Parsing is more lax then the specification so it silently ignores elements and attributes in foreign namespaces. Returns either a DAIA object or croaks on uncoverable errors.
Parse DAIA/JSON from a file or string. The first parameter must be a filename, a string of XML, or a IO::Handle object.
Guess serialization format (DAIA/JSON or DAIA/XML) and return json, xml or the empty string.
Return a has with allowed serialization formats and their mime types.
Checks whether the value is a well-formed URI. This function is imported from Data::Validate::URI into the namespace of this package as DAIA::is_uri. On request the function can be exported into the default namespace.
DAIA::is_uri
All objects (documents, items, availability status, institutions, departments, limitations, storages, messages) are implemented as subclass of DAIA::Object, which is just another Perl meta-class framework. All objects have the following methods:
Constructs a new object.
Adds typed properties.
Returns several serialization forms.
Serialize the object and send it to STDOUT (or to another stream) with the appropriate HTTP headers. This method is available for all DAIA objects but mostly used to serve a DAIA::Response. The serialized object must already be encoded in UTF-8 (but it can contain Unicode strings).
The serialization format can be specified with the first parameter as format string (json or xml) or cgi object. If no format is given, it is searched for in the CGI query parameters. The default format is xml. Other possible options are:
cgi
Print HTTP headers (default). Use header => 0 to disable headers.
header => 0
Print the XML header of XML format is used. Enabled by default.
Add a link to the given XSLT stylesheet if XML format is used.
Add one or more processing instructions if XML format is used.
Add this JavaScript callback function in JSON format. If no callback function is specified, it is searched for in the CGI query parameters. You can disable callback support by setting callback => undef.
callback => undef
Serialize to a given stream (IO::Handle, GLOB, or string reference) instead of STDOUT. You may also want to set exitif if you use this option.
exitif
By setting this method to a true value you make it to exit the program. you provide a method, the method is called and the script exits if only if the return value is true.
Jakob Voss
This software is copyright (c) 2012 by Jakob Voss.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
1 POD Error
The following errors were encountered while parsing the POD:
Unknown directive: =head
To install DAIA, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DAIA
CPAN shell
perl -MCPAN -e shell install DAIA
For more information on module installation, please visit the detailed CPAN module installation guide.