#!perl -w
$Data::Dumper::Terse
= 1;
$Data::Dumper::Indent
= 0;
my
$schema
= [
hash
=> {
some_of
=> [[
[
str
=> {
one_of
=> [
qw/username email userid/
]}],
[
str
=> {
required
=> 1}],
1, 1
]],
"some_of.errmsg"
=>
"Please specify either username, email, OR userid"
,
}];
my
@data
;
$data
[
@data
] = {
email
=>
'foo@bar'
};
$data
[
@data
] = {
email
=>
undef
};
$data
[
@data
] = {};
$data
[
@data
] = {
email
=>
'foo@bar'
,
username
=>
'foo'
};
for
(0..
$#data
) {
print
"data$_: "
, Dumper(
$data
[
$_
]),
": "
;
my
$res
= ds_validate(
$data
[
$_
],
$schema
);
for
(@{
$res
->{errors} }) {
s/^data\@\S* schema\@\S* //;
}
if
(
$res
->{success}) {
print
"valid"
;
}
else
{
print
"invalid: "
;
print
join
(
", "
, @{
$res
->{errors} });
}
print
"\n"
;
}