Subject: | Support for named constraints |
I think it would be a good idea that the built in Constraints could be
renamed using the idea of the named constraints so that we can use
custom error messages more easily.
I think it would be simple to change the default Constraints.pm and
would not brake any existing code.
For example, change in Constraints.pm FV_length_between from:
sub FV_max_length {
my ($max) = @_;
croak "max is required" unless defined $max;
return sub {
my ($dfv,$value) = @_;
$dfv->name_this('max_length');
return undef if ( length($value) > $max );
# Use a regexp to untaint
$value=~/(.*)/;
return $dfv->untainted_constraint_value($1);
}
}
To:
sub FV_max_length {
my ($max) = @_;
croak "max is required" unless defined $max;
return sub {
my ($dfv,$value) = @_;
$dfv->name_this('max_length') unless
$dfv->get_current_constraint_name();
return undef if ( length($value) > $max );
# Use a regexp to untaint
$value=~/(.*)/;
return $dfv->untainted_constraint_value($1);
}
}