HTTP::Link::Parser(3pm) | User Contributed Perl Documentation | HTTP::Link::Parser(3pm) |
HTTP::Link::Parser - parse HTTP Link headers
use HTTP::Link::Parser ':standard'; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $response = $ua->get("http://example.com/foo"); # Parse link headers into an RDF::Trine::Model. my $model = parse_links_into_model($response); # Find data about <http://example.com/foo>. my $iterator = $model->get_statements( RDF::Trine::Node::Resource->new('http://example.com/foo'), undef, undef); while ($statement = $iterator->next) { # Skip data where the value is not a resource (i.e. link) next unless $statement->object->is_resource; printf("Link to <%s> with rel=\"%s\".\n", $statement->object->uri, $statement->predicate->uri); }
HTTP::Link::Parser parses HTTP "Link" headers found in an HTTP::Response object. Headers should conform to the format described in RFC 5988.
To export all functions:
use HTTP::Link::Parser ':all';
$existing_model is an RDF::Trine::Model to add data to. If omitted, a new, empty model is created.
parse_links_into_model($response)->as_hashref
But it's faster as no intermediate model is built.
It may be used to convert short strings identifying relationships, such as "next" and "prev", into longer URIs identifying the same relationships, such as "http://www.iana.org/assignments/relation/next" and "http://www.iana.org/assignments/relation/prev".
If passed a string which is a URI already, simply returns it as-is.
These are really just internal implementations, but you can use them if you like.
Returns an arrayref of hashrefs. Each hashref contains keys corresponding to the link parameters of the link, and a key called 'URI' corresponding to the target of the link.
The 'rel' and 'rev' keys are arrayrefs containing lists of relationships. If the Link used the short form of a registered relationship, then the short form is present on this list. Short forms can be converted to long forms (URIs) using the "relationship_uri" function.
The structure returned by this function should not be considered stable.
This parses a single Link header (minus the "Link:" bit itself) into a hashref structure. A base URI must be included in case the link contains relative URIs. A default language can be provided for the 'title' parameter.
The structure returned by this function should not be considered stable.
Please report any bugs to <http://rt.cpan.org/>.
<http://www.ietf.org/rfc/rfc5988.txt>.
RDF::Trine, HTTP::Response, XRD::Parser, HTTP::LRDD.
<http://n2.talis.com/wiki/RDF_JSON_Specification>.
<http://www.perlrdf.org/>.
Toby Inkster <tobyink@cpan.org>.
Copyright (C) 2009-2011, 2014 by Toby Inkster
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2021-01-06 | perl v5.32.0 |