Jakob Voß > Plack-App-DAIA-0.471 > Plack::App::DAIA

Download:
Plack-App-DAIA-0.471.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.471   Source   Latest Release: Plack-App-DAIA-0.55

NAME ^

Plack::App::DAIA - DAIA Server as Plack application

VERSION ^

version 0.471

SYNOPSIS ^

To quickly hack a DAIA server, create a simple 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.

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

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.

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.

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:

  idformat => qr{^ (?<prefix>[a-z]+) : (?<local>.+) $}x

will give you $parts{prefix} and $parts{local} in the retrieve method.

initialized

Stores whether the application had been initialized.

retrieve ( $id [, %parts ] )

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.

init

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.

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.

SEE ALSO ^

Plack::App::DAIA is derived from Plack::Component. Use Plack::DAIA::Test and provedaia (using Plack::App::DAIA::Test::Suite) for writing tests. See Plack::App::DAIA::Validator for a DAIA validator and converter.

AUTHOR ^

Jakob Voss

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: