.\" Automatically generated by Pod::Man 4.14 (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 .. .\" 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::Validator::Util 3pm" .TH JSON::Validator::Util 3pm "2023-03-06" "perl v5.36.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::Validator::Util \- Utility functions for JSON::Validator .SH "DESCRIPTION" .IX Header "DESCRIPTION" JSON::Validator::Util is a package containing utility functions for JSON::Validator. Each of the \*(L"\s-1FUNCTIONS\*(R"\s0 can be imported. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "data_checksum" .IX Subsection "data_checksum" .Vb 1 \& $str = data_checksum $any; .Ve .PP Will create a checksum for any data structure stored in \f(CW$any\fR. .SS "data_section" .IX Subsection "data_section" .Vb 2 \& $str = data_section "Some::Module", "file.json"; \& $str = data_section "Some::Module", "file.json", {encode => \*(AqUTF\-8\*(Aq}; .Ve .PP Same as \*(L"data_section\*(R" in Mojo::Loader, but will also look up the file in any inherited class. .SS "data_type" .IX Subsection "data_type" .Vb 3 \& $str = data_type $any; \& $str = data_type $any, [@schemas]; \& $str = data_type $any, [{type => "integer", ...}]; .Ve .PP Returns the \s-1JSON\s0 type for \f(CW$any\fR. \f(CW$str\fR can be array, boolean, integer, null, number object or string. Note that a list of schemas need to be provided to differentiate between \*(L"integer\*(R" and \*(L"number\*(R". .SS "is_bool" .IX Subsection "is_bool" .Vb 1 \& $bool = is_bool $any; .Ve .PP Checks if \f(CW$any\fR looks like a boolean. .SS "is_num" .IX Subsection "is_num" .Vb 1 \& $bool = is_num $any; .Ve .PP Checks if \f(CW$any\fR looks like a number. .SS "is_type" .IX Subsection "is_type" .Vb 2 \& $bool = is_type $any, $class; \& $bool = is_type $any, $type; .Ve .PP Checks if \f(CW$any\fR is a, or inherits from, \f(CW$class\fR or \f(CW$type\fR. .SS "negotiate_content_type" .IX Subsection "negotiate_content_type" .Vb 1 \& $content_type = negotiate_content_type($header, \e@content_types); .Ve .PP This method can take a \*(L"Content-Type\*(R" or \*(L"Accept\*(R" header and find the closest matching content type in \f(CW@content_types\fR. \f(CW@content_types\fR can contain wildcards, meaning \*(L"*/*\*(R" will match anything. .SS "prefix_errors" .IX Subsection "prefix_errors" .Vb 1 \& @errors = prefix_errors $prefix, @errors; .Ve .PP Consider this internal for now. .SS "schema_type" .IX Subsection "schema_type" .Vb 2 \& $str = schema_type $hash_ref; \& $str = schema_type $hash_ref, $any; .Ve .PP Looks at \f(CW$hash_ref\fR and tries to figure out what kind of type the schema represents. \f(CW$str\fR can be \*(L"array\*(R", \*(L"const\*(R", \*(L"number\*(R", \*(L"object\*(R", \*(L"string\*(R", or fallback to empty string if the correct type could not be figured out. .PP \&\f(CW$any\fR can be provided to double check the type, so if \f(CW$hash_ref\fR describes an \*(L"object\*(R", but \f(CW$any\fR is an array-ref, then \f(CW$str\fR will become an empty string. Example: .PP .Vb 2 \& # $str = ""; \& $str = schema {additionalProperties => false}, []; \& \& # $str = "object" \& $str = schema {additionalProperties => false}; \& $str = schema {additionalProperties => false}, {}; .Ve .PP Note that this process is relatively slow, so it will make your validation faster if you specify \*(L"type\*(R". Both of the two below is valid, but the one with \&\*(L"type\*(R" will be faster. .PP .Vb 2 \& {"type": "object", "properties": {}} # Faster \& {"properties": {}} # Slower .Ve .SS "str2data" .IX Subsection "str2data" .Vb 1 \& $any = str2data $str; .Ve .PP Will try to parse \f(CW$str\fR as \s-1JSON\s0 or \s-1YAML,\s0 and return a data structure. .SH "SEE ALSO" .IX Header "SEE ALSO" JSON::Validator.