hi. i encounter an fatal error 'Argument "test_abc" isn't numeric in addition (+)...' when executing an validator.
the validator dies when the return type is 'str', but with an return_type 'bool' the validation works as expected. the error condition is also dependent of he input data. to illustrate this i attached an example script.
schema:
[
array => {
of => [
'hash',
'keys' => {
test_abc => [ 'array', 'of', 'any' ]
}
]
}
];
test data1:
[{ test_abc => ["a"] }]
=> validation works (str and bool return_type)
test data2:
[{ test_abc => ["a"] }, { test_abc => ["b"] }]
=> validation return_type=>bool works, return_type=>str dies with
'Argument "test_abc" isn't numeric in addition (+)...'
i get this error with Data::Sah version 0.42 on perl 5.20.1 (linux)
thanks, michael
Subject: | sah.pl |
use Data::Sah qw(normalize_schema gen_validator);
use Data::Dump;
my $def = [
array => {
of => [
'hash',
'keys' => {
test_abc => [ 'array', 'of', 'any' ]
}
]
}
];
eval {
for my $return_type (qw(bool str)) {
my $data = [];
print "\n>>> return_type: $return_type\n";
for ( 0 .. 1 ) {
push @$data, { test_abc => ['a'] };
ddx $data;
print "validate > ", gen_validator( $def, { return_type => $return_type } )->($data), "\n";
}
}
};
print "ERR: $@\n\n" if $@;