Validate: Fix referencing & merging already compiled schemas

This commit is contained in:
Yorhel 2025-03-17 12:50:21 +01:00
parent 65cf842500
commit a7bfe146b1
2 changed files with 16 additions and 1 deletions

View file

@ -103,12 +103,14 @@ sub _new { bless { validations => [], @_ }, __PACKAGE__ }
sub _compile($schema, $custom, $rec, $top, $validations=$top->{validations}) {
my $iscompiled = $schema isa __PACKAGE__;
# For hashref schemas, builtins always override other validations
$schema = [
map +($_, $schema->{$_}),
(grep !$builtin{$_}, keys %$schema),
(grep $builtin{$_}, keys %$schema),
] if ref $schema eq 'HASH';
] if ref $schema ne 'ARRAY';
for my($name, $val) (@$schema) {
if ($name eq 'type') {
@ -159,6 +161,11 @@ sub _compile($schema, $custom, $rec, $top, $validations=$top->{validations}) {
next;
}
if ($iscompiled && $name eq 'validations') {
push @$validations, @$val;
next;
}
my $t = $custom->{$name} || $default_validations{$name};
confess "Unknown validation: $name" if !$t;
confess "Recursion limit exceeded while resolving validation '$name'" if $rec < 1;