Now I've realized there are a number of ways it could be improved. Since the current maintainer has been initially unresponsive to my queries, I plan to go ahead with creating a significant patch to the module. I'd like to ask ya'll monks for feedback on the following module design changes:
### current style: single values must be anon arrays
my $validator = new HTML::FormValidator(
{
form => {
required => [ 'foo' ],
optional => [ 'zoo' ],
filters => [ 'trim' ],
}
}
);
### proposed style, single values can be scalars
my $validator = new HTML::FormValidator({
form => {
required => 'foo',
optional => 'zoo',
filters => 'trim',
}
});
#### an example of how you can currently map the suffix of a field name to a constraint
#### This means that all fields that end in _usps_abbrev must a valid US state and
#### all fields that end in _phone must be a valid US phone number
my %constraints;
foreach my $key (keys %FORM) {
$constraint{$key} = 'state' if $key =~ m/_usps_abbrev$/;
$constraint{$key} = 'american_phone' if $key =~ m/_phone$/;
}
my $validator = new HTML::FormValidator({
form => {
constraints => \%constraints,
}
});
#### same thing, using proposed syntax for constraint suffix mapping:
my $validator = new HTML::FormValidator({
form => {
constraint_suffix_map => {
_usps_abbrev => 'state',
_phone => 'american_phone'
}
}
});
dependency_groups => {
password_group => [qw/password password_confirmation/],
}
An array of arrays would do most of what we want, but by using hashes,
I think we get a form of self-documentation and it should also be
easier to manipulate the structure dynamically since you can say "add
an item to the password group" instead of "add an item to the first
dependency group". In reply to proposal for HTML::FormValidator upgrade by markjugg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |