.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "JSON::Hyper 3pm" .TH JSON::Hyper 3pm "2020-01-14" "perl v5.30.0" "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" JSON::Hyper \- extract links from JSON via a schema .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 7 \& my $hyper = JSON::Hyper\->new($hyperschema); \& my $json = from_json( ... ); \& my @links = $hyper\->find_links($json\->[1]\->{some}\->{object}); \& foreach my $link (@links) \& { \& printf("<%s> (%s)", $link\->{href}, $link\->{rel}); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \s-1JSON\s0 Hyper Schema proposal defines hypertext navigation through data structures represented by \s-1JSON.\s0 .SS "Constructor" .IX Subsection "Constructor" .ie n .IP """new($hyperschema)""" 4 .el .IP "\f(CWnew($hyperschema)\fR" 4 .IX Item "new($hyperschema)" Given a \s-1JSON\s0 (or equivalent Perl nested hashref/arrayref structure) Hyper Schema, returns a Perl object capable of interpreting that schema. .Sp If the schema is omitted, defaults to the \s-1JSON\s0 Referencing hyper schema (described at ) .SS "Methods" .IX Subsection "Methods" .ie n .IP """schema""" 4 .el .IP "\f(CWschema\fR" 4 .IX Item "schema" Returns the original schema as a hashref/arrayref structure. .ie n .IP """ua""" 4 .el .IP "\f(CWua\fR" 4 .IX Item "ua" Get/set the LWP::UserAgent instance used to retrieve things. .ie n .IP """find_links($object, $base)""" 4 .el .IP "\f(CWfind_links($object, $base)\fR" 4 .IX Item "find_links($object, $base)" Given a \s-1JSON\s0 object (or equivalent Perl nested hashref/arrayref structure) and optionally a base \s-1URL\s0 for interpreting relative \s-1URI\s0 references, returns a list of links found on object node. Does not operate recursively. .Sp Each link is a JSON::Hyper::Link object. .ie n .IP """get($uri)""" 4 .el .IP "\f(CWget($uri)\fR" 4 .IX Item "get($uri)" Performs an \s-1HTTP\s0 request for the given \s-1URI\s0 and returns a list of Perl nested hashref/arrayref structures corresponding to the \s-1JSON\s0 response. The \s-1URI\s0 may contain a fragment identifier, which will be interpreted according to the schema's fragment resolution method. Fragment resolution methods supported include: .RS 4 .IP "\(bu" 8 slash-delimited (default) .IP "\(bu" 8 dot-delimited .IP "\(bu" 8 jsonpath .RE .RS 4 .Sp For example, assuming the hyper schema specifies slash-delimited fragments, the following: .Sp .Vb 2 \& my $hyper = JSON::Hyper\->new($hyperschema); \& my ($result) = $hyper\->get(\*(Aqhttp://example.com/data.json#foo/bar/0\*(Aq); .Ve .Sp Is roughly equivalent to: .Sp .Vb 6 \& use JSON; \& use LWP::UserAgent; \& my $ua = LWP::UserAgent\->new; \& my $response = $ua\->get(\*(Aqhttp://example.com/data.json\*(Aq); \& my $object = from_json($response\->decoded_content); \& my $result = $object\->{foo}{bar}[0]; .Ve .Sp Note, if called multiple times on the same \s-1URL\s0 will return not just equivalent objects, but the same object. .Sp So, why does this method return a list of results instead of just a single result? In most cases, there will be either 0 or 1 items on the list; however, JSONPath allows a path to match multiple nodes, so there will occasionally be more than one result. (In scalar context, this method just returns the first result anyway.) .RE .ie n .IP """resolve_fragment($object, $fragment)""" 4 .el .IP "\f(CWresolve_fragment($object, $fragment)\fR" 4 .IX Item "resolve_fragment($object, $fragment)" Used by \f(CW\*(C`get\*(C'\fR to resolve the fragment part of a \s-1URL\s0 against an object. .ie n .IP """process_includes($object, $base, $recurse)""" 4 .el .IP "\f(CWprocess_includes($object, $base, $recurse)\fR" 4 .IX Item "process_includes($object, $base, $recurse)" Given an \s-1JSON\s0 object (or equivalent Perl nested hashref/arrayref structure) and optional base \s-1URL,\s0 crawls the object finding rel=\*(L"full\*(R" links, dereferences them using \f(CW\*(C`get\*(C'\fR and replaces the appropriate nodes with the retrieved content. \f(CW$recurse\fR is a boolean. .Sp This has the effect of rel=\*(L"full\*(R" behaving like inclusion does in various programming languages. .Sp This modifies the given object rather than creating a new object. .SS "Utilities" .IX Subsection "Utilities" .ie n .IP """JSON::Hyper::json_ref()""" 4 .el .IP "\f(CWJSON::Hyper::json_ref()\fR" 4 .IX Item "JSON::Hyper::json_ref()" Returns the \s-1JSON\s0 referencing hyperschema as a hashref. .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" JSON::Hyper::Link. .PP Related modules: \s-1JSON::T\s0, JSON::Path, \s-1JSON::GRDDL\s0, JSON::Schema. .PP . .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" Copyright 2010\-2012 Toby Inkster. .PP This module is tri-licensed. It is available under the X11 (a.k.a. \s-1MIT\s0) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. .ie n .SS "a.k.a. ""The \s-1MIT\s0 Licence""" .el .SS "a.k.a. ``The \s-1MIT\s0 Licence''" .IX Subsection "a.k.a. The MIT Licence" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \*(L"Software\*(R"), 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 \&\s-1THE SOFTWARE IS PROVIDED \*(L"AS IS\*(R", 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.\s0