|
NAMEData::Sah::Resolve - Resolve Sah schema VERSIONThis document describes version 0.011 of Data::Sah::Resolve (from Perl distribution Data-Sah-Resolve), released on 2021-07-29. SYNOPSIS use Data::Sah::Resolve qw(resolve_schema);
my $sch = resolve_schema("int");
# => {
# v => 2,
# type=>"int",
# clsets_after_type => [],
# "clsets_after_type.alt.merge.merged" => [],
# base=>"int",
# clsets_after_base => [],
# resolve_path => ["int"],
# }
my $sch = resolve_schema("posint*");
# => {
# v => 2,
# type=>"int",
# clsets_after_type => [{min=>1}, {req=>1}],
# "clsets_after_type.alt.merge.merged" => [{min=>1}, {req=>1}],
# base => "posint",
# clsets_after_base => [{req=>1}],
# resolve_path => ["int","posint"],
# }
my $sch = resolve_schema([posint => div_by => 3]);
# => {
# v => 2,
# type=>"int",
# clsets_after_type => [{min=>1}, {div_by=>3}],
# "clsets_after_type.alt.merge.merged" => [{min=>1}, {div_by=>3}],
# base => "posint",
# clsets_after_base => [{div_by=>3}],
# resolve_path => ["int","posint"],
# }
# => ["int", {min=>1}, {div_by=>3}]
my $sch = resolve_schema(["posint", "merge.delete.min"=>undef, div_by => 3]);
# basically becomes: ["int", div_by=>3]
# => {
# v => 2,
# type=>"int",
# clsets_after_type => [{min=>1}, {"merge.delete.min"=>undef, div_by=>3}],
# "clsets_after_type.alt.merge.merged" => [{div_by=>3}],
# base => undef,
# clsets_after_base => [{div_by=>3}],
# resolve_path => ["int","posint"],
# }
# => ["int", {min=>1}, {div_by=>3}]
DESCRIPTIONThis module provides "resolve_schema". FUNCTIONSresolve_schemaUsage: my $res = resolve_schema([ \%opts, ] $sch); # => hash Sah schemas can be defined in terms of other schemas as base. The resolving process follows the (outermost) base schema until it finds a builtin type as the (innermost) base. It then returns a hash result (a DefHash with "v"=2) containing the type as well other information like the collected clause sets and others. This routine performs the following steps:
Will also die on circularity or when there is other failures like failing to get schema from the schema module. Example 1: "int". First we normalize to "["int",{}]". The type is "int" and it is a builtin type (Data::Sah::Type::int exists). The final result is: {
v => 2,
type=>"int",
clsets_after_type => [],
"clsets_after_type.alt.merge.unmerged" => [],
base=>undef,
clsets_after_base => [],
resolve_path => ["int"],
}
Example 2: "posint*". First we normalize to "["posint",{req=>1}]". The type part of this schema is "posint" and it is actually the name of another schema because "Data::Sah::Type::posint" is not found and we find schema module Sah::Schema::posint) instead. We then retrieve the "posint" schema from the schema module's $schema and we get "["int", {min=>1}]" (additional informative clauses omitted for brevity). We now try to resolve "int" and find that it's a builtin type. So the final result is: {
v => 2,
type=>"int",
clsets_after_type => [{min=>1}, {req=>1}],
"clsets_after_type.alt.merge.unmerged" => [{min=>1}, {req=>1}],
base => "posint",
clsets_after_base => [{req=>1}],
resolve_path => ["int","posint"],
}
Known options:
As mentioned, result is a hash conforming to the DefHash restriction. The following keys will be returned:
HOMEPAGEPlease visit the project's homepage at <https://metacpan.org/release/Data-Sah-Resolve>. SOURCESource repository is at <https://github.com/perlancar/perl-Data-Sah-Resolve>. BUGSPlease 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. SEE ALSOSah, Data::Sah AUTHORperlancar <perlancar@cpan.org> COPYRIGHT AND LICENSEThis software is copyright (c) 2021, 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.
|