NAME
Plack::App::DAIA - DAIA Server as Plack application
VERSION
version 0.43
SYNOPSIS
It is recommended to derive from this class:
package Your::App;
use parent 'Plack::App::DAIA';
sub retrieve {
my ($self, $id) = @_;
# construct DAIA object (you must extend this in your application)
my $daia = DAIA::Response->new;
return $daia;
};
1;
Then create an app.psgi
that returns an instance of your class:
use Your::App;
Your::App->new;
To quickly hack a DAIA server you can also put all into app.psgi
:
use Plack::App::DAIA;
my $app = Plack::App::DAIA->new( code => sub {
my $id = shift;
# ...construct and return DAIA object
} );
$app;
This module contains a dummy application app.psgi
and a more detailed example daia-ubbielefeld.pl.
DESCRIPTION
This module implements a DAIA server as PSGI application. It provides serialization in DAIA/XML and DAIA/JSON and automatically adds some warnings and error messages. The core functionality must be implemented by deriving from this class and implementing the method retrieve
. The following serialization formats are supported by default:
- xml
-
DAIA/XML format (default)
- json
-
DAIA/JSON format
- rdfjson
-
DAIA/RDF in RDF/JSON.
In addition you get DAIA/RDF in several RDF formats (rdfxml
, turtle
, and ntriples
if RDF::Trine is installed. If RDF::NS is installed, you also get known namespace prefixes for RDF/Turtle format. Furthermore the output formats svg
and dot
are supported if RDF::Trine::Exporter::GraphViz is installed to visualize RDF graphs (you may need to make sure that dot
is in your $ENV{PATH}
).
METHODS
new ( [%options] )
Creates a new DAIA server. Supported options are
- xslt
-
Path of a DAIA XSLT client to attach to DAIA/XML responses.
- xsd
-
Path of a DAIA XML Schema to validate DAIA/XML response.
- warnings
-
Enable warnings in the DAIA response (enabled by default).
- code
-
Code reference to the 'retrieve' method if you prefer not to create a module derived from this module.
- idformat
-
Optional regular expression to validate identifiers. Invalid identifiers are set to the empty string before they are passed to the 'retrieve' method. In addition an error message "unknown identifier format" is added to the response, if warnings are enabled.
retrieve ( $id )
Must return a status and a DAIA::Response object. Override this method if you derive an application from Plack::App::DAIA. By default it either calls the retrieve code, as passed to the constructor, or returns undef, so a HTTP 500 error is returned.
as_psgi ( $status, $daia [, $format [, $callback ] ] )
Serializes a DAIA::Response in some DAIA serialization format (xml
by default) and returns a a PSGI response with given HTTP status code.
call
Core method of the Plack::Component. You should not need to override this.
SEE ALSO
Plack::App::DAIA::Validator, Plack::DAIA::Test.
AUTHOR
Jakob Voss
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 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.