HTTP::LRDD(3pm) | User Contributed Perl Documentation | HTTP::LRDD(3pm) |
HTTP::LRDD - link-based resource descriptor discovery
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 }
Note: the LRDD specification has ceased to be, with some parts being merged into the host-meta Internet Draft. This CPAN module will go in its own direction, bundling up best-practice techniques for discovering links and descriptors for a given URI.
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.
A descriptor is a resource that provides a description for something. So, if the given resource URI 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 URI 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.
If none of the above is able to yield a link to a descriptor, then the resource URI itself may be returned if it is in a self-describing format (e.g. RDF).
There is no guaranteed file format for the descriptor, but it is usually RDF, POWDER XML or XRD.
This method can also be called without an object (as a class method) in which case, a temporary object is created automatically using "new".
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 "new".
Calls "discover" in a non-list context, so only the first descriptor is used.
Calls "discover" in a list context, so multiple descriptors are combined into the resulting graph.
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="author") from an HTML page:
my $lrdd = HTTP::LRDD->new('author'); my $author = $lrdd->discover('http://example.com/page.html');
(For RDF people, you should note that rel="author" is not semantically equivalent to the "foaf:maker" property but closer to the "foaf:maker/foaf:homepage" SPARQL 1.1 property path - i.e. the rel="author" link destination is not a URI for the author themselves, but a page about the author.)
If that author resource is in a machine-readable format (e.g. RDF), then parse the data:
my $author_data = $lrdd->parse($author);
Or, you can combine "discover" and "parse":
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) );
Please report any bugs to <http://rt.cpan.org/>.
Note: many problems can stem from servers that send incorrect "Content-Type" headers. If you send an XRD file as "text/html", then this module will not guess what you're doing - it will assume the file is really HTML, and inspect it for RDFa. For host-meta files, this module is slightly more relaxed, as there's a strong assumption that they are XRD... but YOU SHOULD NOT RELY ON THIS. If you're running a server, use the correct media type.
HTTP::Link::Parser, XRD::Parser, XML::Atom::OWL WWW::Finger.
<http://www.perlrdf.org/>.
Toby Inkster <tobyink@cpan.org>.
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.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2021-09-11 | perl v5.32.1 |