1JSON::Validator::Store(U3s)er Contributed Perl DocumentatJiSoOnN::Validator::Store(3)
2
3
4

NAME

6       JSON::Validator::Store - Load and caching JSON schemas
7

SYNOPSIS

9         use JSON::Validator;
10         my $jv = JSON::Validator->new;
11         $jv->store->add("urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f" => {...});
12         $jv->store->load("http://api.example.com/my/schema.json");
13

DESCRIPTION

15       JSON::Validator::Store is a class for loading and caching JSON-Schemas.
16

ATTRIBUTES

18   cache_paths
19         my $store     = $store->cache_paths(\@paths);
20         my $array_ref = $store->cache_paths;
21
22       A list of directories to where cached specifications are stored.
23       Defaults to "JSON_VALIDATOR_CACHE_PATH" environment variable and the
24       specs that is bundled with this distribution.
25
26       "JSON_VALIDATOR_CACHE_PATH" can be a list of directories, each
27       separated by ":".
28
29       See "Bundled specifications" in JSON::Validator for more details.
30
31   schemas
32         my $hash_ref = $store->schemas;
33         my $store = $store->schemas({});
34
35       Hold the schemas as data structures. The keys are schema "id".
36
37   ua
38         my $ua    = $store->ua;
39         my $store = $store->ua(Mojo::UserAgent->new);
40
41       Holds a Mojo::UserAgent object, used by "schema" to load a JSON schema
42       from remote location.
43
44       The default Mojo::UserAgent will detect proxy settings and have
45       "max_redirects" in Mojo::UserAgent set to 3.
46

METHODS

48   add
49         my $normalized_id = $store->add($id => \%schema);
50
51       Used to add a schema data structure. Note that $id might not be the
52       same as $normalized_id.
53
54   exists
55         my $normalized_id = $store->exists($id);
56
57       Returns a $normalized_id if it is present in the "schemas".
58
59   get
60         my $schema = $store->get($normalized_id);
61
62       Used to retrieve a $schema added by "add" or "load".
63
64   load
65         my $normalized_id = $store->load('https://...');
66         my $normalized_id = $store->load('data://main/foo.json');
67         my $normalized_id = $store->load('---\nid: yaml');
68         my $normalized_id = $store->load('{"id":"yaml"}');
69         my $normalized_id = $store->load(\$text);
70         my $normalized_id = $store->load('/path/to/foo.json');
71         my $normalized_id = $store->load('file:///path/to/foo.json');
72         my $normalized_id = $store->load('/load/from/ua-server-app');
73
74       Can load a $schema from many different sources. The input can be a
75       string or a string-like object, and the "load" method will try to
76       resolve it in the order listed in above.
77
78       Loading schemas from $text will generate an $normalized_id in "schemas"
79       looking like "urn:text:$text_checksum". This might change in the
80       future!
81
82       Loading files from disk will result in a $normalized_id that always
83       start with "file://".
84
85       Loading can also be done with relative path, which will then load from:
86
87         $store->ua->server->app;
88
89       This method is EXPERIMENTAL, but unlikely to change significantly.
90

SEE ALSO

92       JSON::Validator.
93
94
95
96perl v5.34.0                      2021-07-22         JSON::Validator::Store(3)
Impressum