Plack::App::DAIA - DAIA Server as Plack application
version 0.47
To quickly hack a DAIA server, create a simple app.psgi:
app.psgi
use Plack::App::DAIA; Plack::App::DAIA->new( code => sub { my $id = shift; # ...construct and return DAIA object } );
However, you should better derive from this class:
package Your::App; use parent 'Plack::App::DAIA'; sub retrieve { my ($self, $id, %parts) = @_; # 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;
You can also mix this application with Plack middleware.
It is highly recommended to test your services! Testing is made as easy as possible with the provedaia command line script.
This module contains a dummy application app.psgi and a more detailed example examples/daia-ubbielefeld.pl.
examples/daia-ubbielefeld.pl
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:
retrieve
DAIA/XML format (default)
DAIA/JSON format
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}).
rdfxml
turtle
ntriples
svg
dot
$ENV{PATH}
Creates a new DAIA server. Supported options are
Path of a DAIA XSLT client to attach to DAIA/XML responses. Not set by default and set to daia.xsl if option html is set. You still may need to adjust the path if your server rewrites the request path.
daia.xsl
html
Enable a HTML client for DAIA/XML via XSLT. The client is returned in form of three files (daia.xsl, daia.css, xmlverbatim.xsl) and DAIA icons, all shipped together with this module. Enabling HTML client also enables serving the DAIA XML Schema as daia.xsd.
daia.css
xmlverbatim.xsl
daia.xsd
Enable warnings in the DAIA response (enabled by default).
Code reference to the retrieve method if you prefer not to create a module derived from this module.
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.
It is recommended to use regular expressions with named capturing groups as introduced in Perl 5.10. The named parts are also passed to the retrieve method. For instance:
retrieve method
idformat => qr{^ (?<prefix>[a-z]+) : (?<local>.+) $}x
will give you $parts{prefix} and $parts{local} in the retrieve method.
$parts{prefix}
$parts{local}
Stores whether the application had been initialized.
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.
This method is passed the original query identifier and a hash of named capturing groups from your identifier format.
This method is called by Plack::Component::prepare_app, once before the first request. You can define this method in you subclass as initialization hook, for instance to set default option values. Initialization during runtime can be triggered by setting initialized to false.
initialized
Serializes a DAIA::Response in some DAIA serialization format (xml by default) and returns a a PSGI response with given HTTP status code.
xml
Plack::App::DAIA::Validator, Plack::DAIA::Test, and Plack::Component
Plack::Component
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.
To install Plack::App::DAIA, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::App::DAIA
CPAN shell
perl -MCPAN -e shell install Plack::App::DAIA
For more information on module installation, please visit the detailed CPAN module installation guide.