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

NAME

SeeAlso::Response - SeeAlso Simple Response

DESCRIPTION

This class models a SeeAlso Simple Response which is practically the same as am OpenSearch Suggestions Response.

METHODS

new ( [ $query [, $labels, $descriptions, $urls ] )

Creates a new SeeAlso::Response object (this is the same as an OpenSearch Suggestions Response object). The optional parameters are passed to the set method, so this is equivalent:

  $r = SeeAlso::Response->new($query, $labels, $descriptions, $urls);
  $r = SeeAlso::Response->new->set($query, $labels, $descriptions, $urls);

To create a SeeAlso::Response from JSON use the fromJSON method.

set ( [ $query [, $labels, $descriptions, $urls ] )

Set the query parameter or the full content of this response. If the query parameter is an instance of SeeAlso::Identifier, the return of its normalized method is used. This methods croaks if the passed parameters do not fit to a SeeAlso response.

add ( $label [, $description [, $uri ] ] )

Add an item to the result set. All parameters must be strings. The URI is only partly checked for well-formedness, so it is recommended to use a specific URI class like URI and pass a normalized version of the URI:

  $uri = URI->new( $uri_str )->canonical

Otherwise your SeeAlso response may be invalid. If you pass a non-empty URI without schema, this method will croak. If label, description, and uri are all empty, nothing is added.

Returns the SeeAlso::Response object so you can chain method calls.

size ( )

Get the number of entries in this response.

get ( $index )

Get a specific triple of label, description, and url (starting with index 0):

  ($label, $description, $url) = $response->get( $index )

query ( [ $query ] )

Get and/or set query parameter. If the query is a SeeAlso::Identifier it will be normalized, otherwise it will be converted to a string.

toJSON ( [ $callback [, $json ] ] )

Return the response in JSON format and a non-mandatory callback wrapped around. The method will croak if you supply a callback name that does not match ^[a-z][a-z0-9._\[\]]*$.

The encoding is not changed, so please only feed response objects with UTF-8 strings to get JSON in UTF-8. Optionally you can pass a JSON object to do JSON encoding of your choice.

fromJSON ( $jsonstring )

Set this response by parsing JSON format. Croaks if the JSON string does not fit SeeAlso response format. You can use this method as as constructor or as method;

  my $response = SeeAlso::Response->fromJSON( $jsonstring );
  $response->fromJSON( $jsonstring )

toCSV ( )

Returns the response in CSV format with one label, description, uri triple per line. The response query is omitted. Please note that newlines in values are allowed so better use a clever CSV parser!

toRDF ( )

Returns the response as RDF triples in JSON/RDF structure. Parts of the result that cannot be interpreted as valid RDF are omitted.

toRDFJSON ( )

Returns the response as RDF triples in JSON/RDF format.

toN3 ( )

Return the repsonse in RDF/N3 (including pretty print).

INTERNAL FUNCTIONS

_escape ( $string )

Escape a specific characters in a UTF-8 string for Turtle syntax / Notation 3

_JSON ( $object [, $callback [, $JSON ] ] )

Encode an object as JSON string, possibly wrapped by callback method.

AUTHOR

Jakob Voss <jakob.voss@gbv.de>

LICENSE

Copyright (C) 2007-2009 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.