logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

HTTP::Link::Parser - parse HTTP Link headers

Author

       Toby Inkster <tobyink@cpan.org>.

Bugs

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

Description

       HTTP::Link::Parser parses HTTP "Link" headers found in an HTTP::Response object. Headers should conform
       to the format described in RFC 5988.

   Functions
       To export all functions:

         use HTTP::Link::Parser ':all';

       "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.

           $existing_model is an RDF::Trine::Model to add data to. If omitted, a new, empty model is created.

       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:

             parse_links_into_model($response)->as_hashref

           But it's faster as no intermediate model is built.

       relationship_uri($short)
           This function is not exported by default.

           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.

   InternalFunctions
       These are really just internal implementations, but you can use them if you like.

       parse_links_to_list($response)
           This function is not exported by default.

           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.

       "parse_single_link($link, $base, [$default_lang])"
           This function is not exported by default.

           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.

Name

       HTTP::Link::Parser - parse HTTP Link headers

See Also

Synopsis

         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);
         }

See Also