Subject: | Params should validate as scalars by default |
There are ways to specify that a value must be a hash or an array, but none to limit a value to a scalar, even though this is probably the most common use case.
An easy solution is to add a 'scalar' validator, but I'd argue that this should be the default if 'hash' or 'array' are not specified. Especially since some other validators may have odd behavior if the value is not a scalar.
Here's an example of behavior I did not expect:
#!/usr/bin/perl
use Brannigan;
use Data::Dumper 'Dumper';
my $v = Brannigan->new({
name => 'x',
params => {
foo => { required => 1, min_length => 1 }
},
});
# All of these are valid
print Dumper map $v->process(x => $_),
{foo => 'a'},
{foo => [1,2,3]},
{foo => [{}, 'arbitrarily nested structure here']},
{foo => {a=>'b'}};
# This one is particularly fun, validates just fine.
print Dumper Brannigan::process(
{ params => { foo => { matches => qr/^HASH/ }} },
{ foo => {} }
);