in reply to Re: Data Validation Tests
in thread Data Validation Tests
Even if you replace the regex by ID::validate(), the whole thing remains rather clunky - esp if you imagine that you have to write such a snippet for 25 different parameters: pure drone work. It is much easier to use a Data::FormValidatoresque declaration likemy @_id = $cgi->params('id'); error_exit("You must select at least one ID.") unless @_id; my @id; for(@_id) { my ($match) = /\A(\d{5,9}[ABC])\z/; error_exit("Invalid ID: $_") unless defined $match; push @id, $match; }
my $validator = Data::FormValidator->new({ delete_items_page => { required => [qw(id .. ..)], constraints => { id => '/\A(\d{5,9}[ABC])\z/', # .. }, }, });
While this doesn't compare favourably so far, adding more parameters to validate would be trivial and quick with the latter code. Adding another two dozen checks is easy and doesn't result in an unmanageable amount of code.
I do agree that the validator should not contain its own actual validation routines. That's why I don't like Data::FormValidator as is; I would prefer there being plugin modules that integrate other modules' own supplied validation routines - much the way File::Find::Rule works.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^2: Data Validation Tests
by Flame (Deacon) on Jan 26, 2003 at 15:32 UTC | |
by perrin (Chancellor) on Jan 26, 2003 at 17:58 UTC | |
by Flame (Deacon) on Jan 26, 2003 at 19:40 UTC |