.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTTP::Link::Parser 3pm" .TH HTTP::Link::Parser 3pm 2024-03-06 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME HTTP::Link::Parser \- parse HTTP Link headers .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use HTTP::Link::Parser \*(Aq:standard\*(Aq; \& 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 . \& my $iterator = $model\->get_statements( \& RDF::Trine::Node::Resource\->new(\*(Aqhttp://example.com/foo\*(Aq), \& 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=\e"%s\e".\en", \& $statement\->object\->uri, \& $statement\->predicate\->uri); \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" HTTP::Link::Parser parses HTTP "Link" headers found in an HTTP::Response object. Headers should conform to the format described in RFC 5988. .SS Functions .IX Subsection "Functions" To export all functions: .PP .Vb 1 \& use HTTP::Link::Parser \*(Aq:all\*(Aq; .Ve .ie n .IP """parse_links_into_model($response, [$existing_model])""" 4 .el .IP "\f(CWparse_links_into_model($response, [$existing_model])\fR" 4 .IX Item "parse_links_into_model($response, [$existing_model])" Takes an HTTP::Response object (or in fact, any HTTP::Message object) and returns an RDF::Trine::Model containing link data extracted from the response. Dublin Core is used to encode 'hreflang', 'title' and 'type' link parameters. .Sp \&\f(CW$existing_model\fR is an RDF::Trine::Model to add data to. If omitted, a new, empty model is created. .ie n .IP parse_links_to_rdfjson($response) 4 .el .IP \f(CWparse_links_to_rdfjson($response)\fR 4 .IX Item "parse_links_to_rdfjson($response)" Returns a hashref with a structure inspired by the RDF/JSON specification. This can be thought of as a shortcut for: .Sp .Vb 1 \& parse_links_into_model($response)\->as_hashref .Ve .Sp But it's faster as no intermediate model is built. .ie n .IP relationship_uri($short) 4 .el .IP \f(CWrelationship_uri($short)\fR 4 .IX Item "relationship_uri($short)" This function is not exported by default. .Sp 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". .Sp If passed a string which is a URI already, simply returns it as-is. .SS "Internal Functions" .IX Subsection "Internal Functions" These are really just internal implementations, but you can use them if you like. .ie n .IP parse_links_to_list($response) 4 .el .IP \f(CWparse_links_to_list($response)\fR 4 .IX Item "parse_links_to_list($response)" This function is not exported by default. .Sp 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. .Sp 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 \&\f(CW\*(C`relationship_uri\*(C'\fR function. .Sp The structure returned by this function should not be considered stable. .ie n .IP """parse_single_link($link, $base, [$default_lang])""" 4 .el .IP "\f(CWparse_single_link($link, $base, [$default_lang])\fR" 4 .IX Item "parse_single_link($link, $base, [$default_lang])" This function is not exported by default. .Sp 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. .Sp The structure returned by this function should not be considered stable. .SH BUGS .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" . .PP RDF::Trine, HTTP::Response, XRD::Parser, HTTP::LRDD. .PP . .PP . .SH AUTHOR .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" Copyright (C) 2009\-2011, 2014 by Toby Inkster .PP 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: .PP The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. .PP 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.