DAIA::Response - DAIA information root element


DAIA documentation Contained in the DAIA distribution.

Index


Code Index:

NAME

Top

DAIA::Response - DAIA information root element

SYNOPSIS

Top

  $r = response( # or DAIA::Response->new( 
      institution => $institution,
      message => [ $msg1, $msg2 ],
      document => [ $document ]
  );

  $r->institution( $institution );
  $institution = $r->institution;

  my $documents = $r->document;

  $r->timestamp;
  $r->version;

PROPERTIES

Top

document

a list of DAIA::Document objects. You can get/set document(s) with the document accessor, with addDocument, and with provideDocument.

institution

a DAIA::Institution that grants or knows about the documents, items services and availabilities described in this response.

message

a list of DAIA::Message objects. You can set message(s) with the message accessor, with addMessage, and with provideMessage.

timestamp

date and time of the response information. It must match the pattern of xs:dateTime and is set to the current date and time on initialization.

The additional read-only attribute version gives the current version of DAIA format.

METHODS

Top

DAIA::Response provides the default methods of DAIA::Object and accessor methods for all of its properties. To serialize and send a HTTP response, you can use the method serve, which is accessible for all DAIA objects.

serve ( [ [ format => ] $format ] [ %options ] )

Serialize the response and send it to STDOUT with the appropriate HTTP headers. This method is mostly used to serve DAIA::Response objects, but it is also available for other DAIA objects. See serve in DAIA::Object for a description.

In most cases, a simple call of $response->serve will be the last statement of a DAIA server implementation.

check_valid_id ( $id )

Check whether a valid identifier has been provided. If not, this methods appends an error message ("please provide a document id" or "document id ... is no valid URI") and returns undef.

AUTHOR

Top

Jakob Voss <jakob.voss@gbv.de>

LICENSE

Top

Copyright (C) 2009-2010 by Verbundzentrale Goettingen (VZG) and Jakob Voss

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.


DAIA documentation Contained in the DAIA distribution.
package DAIA::Response;

use strict;
use base 'DAIA::Object';
our $VERSION = '0.28';
use POSIX qw(strftime);

our %PROPERTIES = (
    version => {
        default => '0.5', 
        filter => sub { '0.5' }
    },
    timestamp => {
        default => sub { strftime("%Y-%m-%dT%H:%M:%SZ", gmtime); },
        filter => sub { $_[0] } # TODO: check format 
    },
    message => $DAIA::Object::COMMON_PROPERTIES{message},
    institution => { 
        type => 'DAIA::Institution',
    },
    document => { 
        type => 'DAIA::Document',
        repeatable => 1
    },
);

1;

sub check_valid_id {
    my $self = shift;
    my $id = shift; # TODO: take from CGI object, if not given

    if ( ! defined $id ) {
        $self->addMessage( "en" => "please provide a document id!", errno => 1 );
    } elsif ( ! DAIA::is_uri( $id ) ) {
        $id = " $id";
        $id = (substr($id,0,32) . '...') if (length($id) > 32);
        $self->addMessage( "en" => "document id$id is no valid URI!", errno => 2 );
    } else {
        return $id;
    }

    return undef;
}