summaryrefslogtreecommitdiff
path: root/lib/TUWF/Validate.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/TUWF/Validate.pm')
-rw-r--r--lib/TUWF/Validate.pm13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/TUWF/Validate.pm b/lib/TUWF/Validate.pm
index 2d46330..fbdfd5c 100644
--- a/lib/TUWF/Validate.pm
+++ b/lib/TUWF/Validate.pm
@@ -14,6 +14,7 @@ our $VERSION = '1.4';
my %builtin = map +($_,1), qw/
type
required default
+ onerror
rmwhitespace
values scalar sort unique
keys unknown
@@ -141,7 +142,8 @@ sub _compile {
croak "Incompatible types, the schema specifies '$top{type}' but validation '$t->{name}' requires '$t->{schema}{type}'" if $schema->{type};
croak "Incompatible types, '$t->[0]' requires '$t->{schema}{type}', but another validation requires '$top{type}'";
}
- exists $t->{schema}{$_} and $top{$_} //= delete $t->{schema}{$_} for qw/required default rmwhitespace type scalar unknown sort unique/;
+ exists $t->{schema}{$_} and !exists $top{$_} and $top{$_} = delete $t->{schema}{$_}
+ for qw/required default onerror rmwhitespace type scalar unknown sort unique/;
push @keys, keys %{ delete $t->{known_keys} };
push @keys, keys %{ $t->{schema}{keys} } if $t->{schema}{keys};
@@ -284,7 +286,7 @@ sub _validate_array {
}
-sub _validate {
+sub _validate_input {
my($c, $input) = @_;
# rmwhitespace (needs to be done before the 'required' test)
@@ -340,6 +342,13 @@ sub _validate {
}
+sub _validate {
+ my($c, $input) = @_;
+ my $r = _validate_input($c, $input);
+ $r->[1] && exists $c->{schema}{onerror} ? [$c->{schema}{onerror}] : $r
+}
+
+
sub validate {
my($c, $input) = ref $_[0] eq __PACKAGE__ ? @_ : (compile($_[0], $_[1]), $_[2]);
bless _validate($c, $input), 'TUWF::Validate::Result';