Data::Sah::Resolve - Resolve Sah schema
This document describes version 0.007 of Data::Sah::Resolve (from Perl distribution Data-Sah-Resolve), released on 2017-04-19.
use Data::Sah::Resolve qw(resolve_schema); my $sch = resolve_schema("int"); # => ["int", []] my $sch = resolve_schema("posint*"); # => ["int", [{min=>1}, {req=>1}] my $sch = resolve_schema([posint => div_by => 3]); # => ["int", {min=>1}, {div_by=>3}] my $sch = resolve_schema(["posint", "merge.delete.min"=>undef, div_by => 3]); # => ["int", {div_by=>3}]
Sah schemas can be defined in terms of other schemas. The resolving process follows the base schema recursively until it finds a builtin type as the base.
This routine performs the following steps:
Unless schema_is_normalized option is true, in which case schema is assumed to be normalized already.
schema_is_normalized
Currently this is done by checking if the module of the name Data::Sah::Type::<type> is loadable. If it is a builtin type then we are done.
Data::Sah::Type::<type>
This is done by checking if Sah::Schema::<name> module exists and is loadable. If this is the case then we retrieve the base schema from the $schema variable in the Sah::Schema::<name> package and repeat the process while accumulating and/or merging the clause sets.
Sah::Schema::<name>
$schema
Returns [base_type, clause_sets]. If return_intermediates option is true, then the third elements will be the list of intermediate schema names.
[base_type, clause_sets]
return_intermediates
Example 1: int.
int
First we normalize to ["int",{},{}]. The type is int and it is a builtin type (Data::Sah::Type::int exists) so the final result is ["int", []].
["int",{},{}]
["int", []]
Example 2: posint*.
posint*
First we normalize to ["posint",{req=>1},{}]. The type is posint and it is the name of another schema (Sah::Schema::posint). We retrieve the schema which is ["int", {summary=>"Positive integer (1,2,3,...)", min=>1}, {}]. We now try to resolve int and find that it's a builtin type. So the final result is: ["int", [ {req=>1}, {summary=>"Positive integer (1,2,3,...)", min=>1} ]].
["posint",{req=>1},{}]
posint
["int", {summary=>"Positive integer (1,2,3,...)", min=>1}, {}]
["int", [ {req=>1}, {summary=>"Positive integer (1,2,3,...)", min=>1} ]]
Known options:
schema_is_normalized => bool (default: 0)
When set to true, function will skip normalizing schema and assume input schema is normalized.
merge_clause_sets => bool (default: 1)
return_intermediates => bool
Please visit the project's homepage at https://metacpan.org/release/Data-Sah-Resolve.
Source repository is at https://github.com/perlancar/perl-Data-Sah-Resolve.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah-Resolve
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Sah, Data::Sah
perlancar <perlancar@cpan.org>
This software is copyright (c) 2017, 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Sah::Resolve, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Sah::Resolve
CPAN shell
perl -MCPAN -e shell install Data::Sah::Resolve
For more information on module installation, please visit the detailed CPAN module installation guide.