SYNOPSIS

 use HTTP::LRDD;

 my $lrdd        = HTTP::LRDD->new;
 my @descriptors = $lrdd->discover($resource);
 foreach my $descriptor (@descriptors)
 {
   my $description = $lrdd->parse($descriptor);
   # $description is an RDF::Trine::Model
 }

DESCRIPTION

Note: the \s-1LRDD\s0 specification has ceased to be, with some parts being merged into the host-meta Internet Draft. This \s-1CPAN\s0 module will go in its own direction, bundling up best-practice techniques for discovering links and descriptors for a given \s-1URI\s0.

Import Routine

When importing \s-1HTTP::LRDD\s0, you can optionally provide a list of predicate URIs (i.e. the URIs which rel values expand to). This may also include IANA-registered link types, which are short tokens rather than full URIs. If you do not provide a list of predicate URIs, then a sensible default set is used. Because this configuration is global in nature, it is not recommended. It is better to supply a list of predicates to the constructor instead, or rely on the defaults. This feature should be regarded as deprecated.

Constructors

Create a new \s-1LRDD\s0 discovery object using the given predicate URIs. If @predicates is omitted, then the predicates passed to the import routine are used instead. Create a new \s-1LRDD\s0 discovery object using the 'describedby' and 'lrdd' IANA-registered predicates. Create a new \s-1LRDD\s0 discovery object using the default set of predicates ('describedby', 'lrdd', 'wdrs:describedby', 'xhv:meta' and 'rdfs:seeAlso').

Public Methods

Discovers a descriptor for the given resource; or if called in a list context, a list of descriptors. A descriptor is a resource that provides a description for something. So, if the given resource \s-1URI\s0 was the web address for an image, then the descriptor might be the web address for a metadata file about the image. If the given \s-1URI\s0 was an e-mail address, then the descriptor might be a profile document for the person to whom the address belongs. The following sources are checked (in order) to find links to descriptors.

  • \s-1HTTP\s0 response headers (\*(L"Link\*(R" header; \*(L"303 See Other\*(R" status)

  • \s-1HTTP\s0 response message (\s-1RDF\s0 or RDFa)

  • https://HOSTNAME/.well-known/host-meta

  • http://HOSTNAME/.well-known/host-meta

If none of the above is able to yield a link to a descriptor, then the resource \s-1URI\s0 itself may be returned if it is in a self-describing format (e.g. \s-1RDF\s0). There is no guaranteed file format for the descriptor, but it is usually \s-1RDF\s0, \s-1POWDER\s0 \s-1XML\s0 or \s-1XRD\s0. This method can also be called without an object (as a class method) in which case, a temporary object is created automatically using \*(C`new\*(C'.

Parses a descriptor in \s-1XRD\s0 or \s-1RDF\s0 (\s-1RDF/XML\s0, RDFa, Turtle, etc). Returns an RDF::Trine::Model or undef if unable to process. This method can also be called without an object (as a class method) in which case, a temporary object is created automatically using \*(C`new\*(C'. Performs the equivalent of \*(C`discover\*(C' and \*(C`parse\*(C' in one easy step. Calls \*(C`discover\*(C' in a non-list context, so only the first descriptor is used. Performs the equivalent of \*(C`discover\*(C' and \*(C`parse\*(C' in one easy step. Calls \*(C`discover\*(C' in a list context, so multiple descriptors are combined into the resulting graph.

EXAMPLES

Discover the hub address (PubSubHubub) for a feed:

my $lrdd = HTTP::LRDD->new('hub'); my $hub = $lrdd->discover('http://example.net/feed.atom');

Discover an author link (rel=\*(L"author\*(R") from an \s-1HTML\s0 page:

my $lrdd = HTTP::LRDD->new('author'); my $author = $lrdd->discover('http://example.com/page.html');

(For \s-1RDF\s0 people, you should note that rel=\*(L"author\*(R" is not semantically equivalent to the \*(L"foaf:maker\*(R" property but closer to the \*(L"foaf:maker/foaf:homepage\*(R" \s-1SPARQL\s0 1.1 property path - i.e. the rel=\*(L"author\*(R" link destination is not a \s-1URI\s0 for the author themselves, but a page about the author.)

If that author resource is in a machine-readable format (e.g. \s-1RDF\s0), then parse the data:

my $author_data = $lrdd->parse($author);

Or, you can combine \*(C`discover\*(C' and \*(C`parse\*(C':

my $lrdd = HTTP::LRDD->new('author'); my $author_data = $lrdd->process('http://example.com/page.html');

Get metadata for an image:

my $lrdd = HTTP::LRDD->new; my $data = $lrdd->process_all('http://example.org/flower.jpeg');

As we're not passing any arguments to the constructor, we can use a shortcut:

my $data = HTTP::LRDD->process_all('http://example.org/flower.jpeg');

Find the title of the image:

use RDF::QueryX::Lazy;

my $image = q<http://example.org/flower.jpeg>; my $results = RDF::QueryX::Lazy -> new("SELECT * WHERE { <$image> dc:title ?t }") -> execute( HTTP::LRDD->process_all($image) );

BUGS

Please report any bugs to <http://rt.cpan.org/>.

Note: many problems can stem from servers that send incorrect \*(C`Content-Type\*(C' headers. If you send an \s-1XRD\s0 file as \*(L"text/html\*(R", then this module will not guess what you're doing - it will assume the file is really \s-1HTML\s0, and inspect it for RDFa. For host-meta files, this module is slightly more relaxed, as there's a strong assumption that they are \s-1XRD\s0... but \s-1YOU\s0 \s-1SHOULD\s0 \s-1NOT\s0 \s-1RELY\s0 \s-1ON\s0 \s-1THIS\s0. If you're running a server, use the correct media type.

RELATED TO HTTP::LRDD…

HTTP::Link::Parser, XRD::Parser, XML::Atom::OWL WWW::Finger.

<http://www.perlrdf.org/>.

AUTHOR

Toby Inkster <[email protected]>.

COPYRIGHT AND LICENCE

Copyright 2010-2012 Toby Inkster

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

DISCLAIMER OF WARRANTIES

\s-1THIS\s0 \s-1PACKAGE\s0 \s-1IS\s0 \s-1PROVIDED\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R" \s-1AND\s0 \s-1WITHOUT\s0 \s-1ANY\s0 \s-1EXPRESS\s0 \s-1OR\s0 \s-1IMPLIED\s0 \s-1WARRANTIES\s0, \s-1INCLUDING\s0, \s-1WITHOUT\s0 \s-1LIMITATION\s0, \s-1THE\s0 \s-1IMPLIED\s0 \s-1WARRANTIES\s0 \s-1OF\s0 \s-1MERCHANTIBILITY\s0 \s-1AND\s0 \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0.