in reply to RFC: Data::FormValidator params interface enhancement

How about marking the validation routine rather than the parameters, so you would have:

constraints => {    image_name => [    {        constraint_method => 'file_format',    },    {        constraint_method => 'file_max_bytes',        params => [\100],    },    {        constraint_method => 'image_max_dimensions',        params => [\200,\200],    },    ],

you could either add a method to D::FV that allows you to find out the name of the field whose contraints are currently being checked (which would involve rewriting the validation subroutines), or make it a convention that the first two args are always the D::FV object and the name of the field being checked.

So:

   foo => { constraint_method => 'bar', params => \@args },

would translate to either:

   foo => { constraint => 'bar', params => [$dfv, @args]] },

or

   foo => { constraint => 'bar', params => [$dfv, 'foo', @args] },

(where $dfv is the D::FV object in question)

I'd prefer the former since you would then have a direct mapping to the Perl method calling convention:

bar($dfv, @args); $dfv->bar(@args);

Replies are listed 'Best First'.
Re: Re: RFC: Data::FormValidator params interface enhancement
by markjugg (Curate) on Apr 21, 2003 at 13:30 UTC

    adrianh,

    Thanks for your response. I think we may have a winner here. I think your solution could be both intuitive to a user as well as sensible to implement. I like the combination of "constraint_method" paired with a new function to get the name of the routine currently be validated.

    I hope I'll discover that I only need to add code to the new routines I'm creating and not all the existing ones.

    -mark