The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


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


version 0.55


Either derive from Plack::App::DAIA

    package Your::App;
    use parent 'Plack::App::DAIA';

    sub init {
        my $self = shift;
        $self->idformat( qr{^[a-z]+:.*$} ) unless $self->idformat;

    sub retrieve {
        my ($self, $id, %idparts) = @_;

        my $daia = DAIA::Response->new;

        # construct full response ...

        return $daia;


or pass a code reference as option code:

    use Plack::App::DAIA;

        code => sub {
            my ($id, %idparts) = @_;

            my $daia = DAIA::Response->new;

            # construct full response ...

            return $daia;
        idformat => qr{^[a-z]+:.*$}


This module implements a Document Availability Information API (DAIA) server as PSGI application. A DAIA server receives two URL parameters:


refers to the document to retrieve availability information. The id is parsed based on the "idformat" option and passed to an internal "retrieve" method, which must return a DAIA::Response object.


specifies a DAIA serialization format, that the resulting DAIA::Response is returned in. By default the formats xml (DAIA/XML, the default), json (DAIA/JSON), and rdfjson (DAIA/RDF in RDF/JSON) are supported. Additional RDF serializations (rdfxml, turtle, and ntriples) are supported if RDF::Trine is installed. If RDF::NS is installed, the RDF/Turtle output uses well-known namespace prefixes. Visual RDF graphs are supported with format svg and dot if RDF::Trine::Exporter::GraphViz is installed and dot is in $ENV{PATH}.

This module automatically adds appropriate warnings and error messages. A simple HTML interface based on client side XSLT is added with option xslt.


new ( [%options] )

Creates a new DAIA server. Supported options are


Code reference to the retrieve method if you prefer not to create a module derived from this module.


Path of a DAIA XSLT client to attach to DAIA/XML responses. Set to daia.xsl by default. The default client is provided 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.

Set xslt => 0 to disable the client.

You may need to adjust the path if your server rewrites the request path.


Path of a directory with XSLT client files.


Enable warnings in the DAIA response (enabled by default).


Enable warnings and directly return a response without calling the retrieve method on error.


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 the option warnings are enabled. If the option errors is enabled, the retrieve method is not called on error.

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.


Catch errors on the request format if enabled (by default). You may want to disable this to get a stack trace if the request method throws an error.


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.


This method is called by Plack::Component::prepare_app, once before the first request and before undefined options are set to their default values. 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.


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/


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.


Jakob Voß


This software is copyright (c) 2014 by Jakob Voß.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.