in reply to Re: Data Validation Tests
in thread Data Validation Tests

While your concern is valid, the idea is to have a way to summarize all validation in a declaration. The benefit is that you avoid manually writing the validation logistics, which is incredibly boring work. Something like
my @_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; }
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 like
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
    Well then you should be glad to hear that the current design does not have any 'built in' routines. It has some default checks, held in a seperate module that comes with the main verification package, but it is very easy to include checks from other places. Basically anything that returns true on sucess and false on failure can be used, via the 'custom' test declaration (which accepts coderef's and regex's.)



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS | GMS

      It sure would be cool if you took Data::FormValidator or one of the others and added the ability to plug in new tests, instead of creating a new module. Then lots of people would get access to it right away without having to discover your new module and change all of their code.
        I'll consider making it a drop-in replacement sort of module, who knows, someday it might...



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS | GMS