1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#!/usr/bin/perl -w
# This tests to make sure that we can use hashrefs and code refs as OK values in the input hash
# inspired by a patch from Boris Zentner
use lib ('.','../t');
$^W = 1;
use Test::More tests => 3;
use strict;
use Data::FormValidator;
my $input_profile =
{
required => [ qw( arrayref hashref coderef ) ],
};
my $validator = new Data::FormValidator({default => $input_profile});
my $input_hashref = {
arrayref => ['', 1,2],
hashref => {tofu => 'good'},
coderef => sub { return 'the answer is 42' },
};
my ($valids, $missings, $invalids, $unknowns) = ({},[],[],[]);
($valids, $missings, $invalids, $unknowns) = $validator->validate($input_hashref, 'default');
# empty strings in arrays should be set to "undef"
ok(not defined $valids->{arrayref}->[0]);
# hash refs and code refs should be ok.
is(ref $valids->{hashref}, 'HASH');
is(ref $valids->{coderef}, 'CODE');
|