1HTTP::Link::Parser(3) User Contributed Perl DocumentationHTTP::Link::Parser(3)
2
3
4

NAME

6       HTTP::Link::Parser - parse HTTP Link headers
7

SYNOPSIS

9         use HTTP::Link::Parser ':standard';
10         use LWP::UserAgent;
11
12         my $ua = LWP::UserAgent->new;
13         my $response = $ua->get("http://example.com/foo");
14
15         # Parse link headers into an RDF::Trine::Model.
16         my $model = parse_links_into_model($response);
17
18         # Find data about <http://example.com/foo>.
19         my $iterator = $model->get_statements(
20           RDF::Trine::Node::Resource->new('http://example.com/foo'),
21           undef,
22           undef);
23
24         while ($statement = $iterator->next)
25         {
26            # Skip data where the value is not a resource (i.e. link)
27            next unless $statement->object->is_resource;
28
29            printf("Link to <%s> with rel=\"%s\".\n",
30               $statement->object->uri,
31               $statement->predicate->uri);
32         }
33

DESCRIPTION

35       HTTP::Link::Parser parses HTTP "Link" headers found in an
36       HTTP::Response object. Headers should conform to the format described
37       in RFC 5988.
38
39   Functions
40       To export all functions:
41
42         use HTTP::Link::Parser ':all';
43
44       "parse_links_into_model($response, [$existing_model])"
45           Takes an HTTP::Response object (or in fact, any HTTP::Message
46           object) and returns an RDF::Trine::Model containing link data
47           extracted from the response. Dublin Core is used to encode
48           'hreflang', 'title' and 'type' link parameters.
49
50           $existing_model is an RDF::Trine::Model to add data to. If omitted,
51           a new, empty model is created.
52
53       "parse_links_to_rdfjson($response)"
54           Returns a hashref with a structure inspired by the RDF/JSON
55           specification. This can be thought of as a shortcut for:
56
57             parse_links_into_model($response)->as_hashref
58
59           But it's faster as no intermediate model is built.
60
61       "relationship_uri($short)"
62           This function is not exported by default.
63
64           It may be used to convert short strings identifying relationships,
65           such as "next" and "prev", into longer URIs identifying the same
66           relationships, such as
67           "http://www.iana.org/assignments/relation/next" and
68           "http://www.iana.org/assignments/relation/prev".
69
70           If passed a string which is a URI already, simply returns it as-is.
71
72   Internal Functions
73       These are really just internal implementations, but you can use them if
74       you like.
75
76       "parse_links_to_list($response)"
77           This function is not exported by default.
78
79           Returns an arrayref of hashrefs. Each hashref contains keys
80           corresponding to the link parameters of the link, and a key called
81           'URI' corresponding to the target of the link.
82
83           The 'rel' and 'rev' keys are arrayrefs containing lists of
84           relationships. If the Link used the short form of a registered
85           relationship, then the short form is present on this list. Short
86           forms can be converted to long forms (URIs) using the
87           "relationship_uri" function.
88
89           The structure returned by this function should not be considered
90           stable.
91
92       "parse_single_link($link, $base, [$default_lang])"
93           This function is not exported by default.
94
95           This parses a single Link header (minus the "Link:" bit itself)
96           into a hashref structure. A base URI must be included in case the
97           link contains relative URIs.  A default language can be provided
98           for the 'title' parameter.
99
100           The structure returned by this function should not be considered
101           stable.
102

BUGS

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

SEE ALSO

107       <http://www.ietf.org/rfc/rfc5988.txt>.
108
109       RDF::Trine, HTTP::Response, XRD::Parser, HTTP::LRDD.
110
111       <http://n2.talis.com/wiki/RDF_JSON_Specification>.
112
113       <http://www.perlrdf.org/>.
114

AUTHOR

116       Toby Inkster <tobyink@cpan.org>.
117
119       Copyright (C) 2009-2011, 2014 by Toby Inkster
120
121       Permission is hereby granted, free of charge, to any person obtaining a
122       copy of this software and associated documentation files (the
123       "Software"), to deal in the Software without restriction, including
124       without limitation the rights to use, copy, modify, merge, publish,
125       distribute, sublicense, and/or sell copies of the Software, and to
126       permit persons to whom the Software is furnished to do so, subject to
127       the following conditions:
128
129       The above copyright notice and this permission notice shall be included
130       in all copies or substantial portions of the Software.
131
132       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
133       OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
134       MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
135       IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
136       CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
137       TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
138       SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
139
140
141
142perl v5.32.0                      2020-07-28             HTTP::Link::Parser(3)
Impressum