Re: [dfv] Constraints and scalar values
Status: Inactive
Brought to you by:
markjugg
|
From: Mark S. <ma...@su...> - 2008-07-30 21:59:42
|
On Wed, 30 Jul 2008 14:34:13 -0700
Amelia Ireland <ame...@gm...> wrote:
> Hello all,
>
> I've run into a problem with D::FV and I was wondering if there's a
> simple solution that I'm not seeing.
>
> I've got a set of tests that I'm using with both D::FV and other parts
> of my code to check parameters are OK. For the most part, these work
> fine, as I'm usually comparing two input parameters or checking a
> value is in a range. However, I am having a little problem with a test
> to check that an object is of a certain subclass, due to D::FV's
> assumption that scalars in the 'params' list are the names of input
> parameters. To illustrate:
>
> standard way of running the test:
>
> test($param_value, 'text string')
>
> This is what I'd like to have in the D::FV profile:
> { constraint => \&test,
> params => [ 'param_name', 'text string' ],
> }
>
> What I want D::FV to do is to pass 'text string' as a string to the
> test function. Instead, it's looking for a param named 'text string'.
> Is there an elegant way around this problem, or am I going to have to
> do some kludgy workaround, like having the text string stored in a
> hash, which is preprocessed before running the test function?
Amelia,
Using the "New School" method of writing constraints available with DFV for 4.0
will help address this issue, and look more attractive, too.
The result will be a constraint that is called just like you want it to look:
test($param_value, 'text string') ;
And you'll be able to implement it so that you process the first value
as a field name, and the second value as a string.
The docs are here:
http://search.cpan.org/~markstos/Data-FormValidator-4.61/lib/Data/FormValidator/Constraints.pm#WRITING_YOUR_OWN_CONSTRAINT_ROUTINES
Mark
--
. . . . . . . . . . . . . . . . . . . . . . . . . . .
Mark Stosberg Principal Developer
ma...@su... Summersault, LLC
765-939-9301 ext 202 database driven websites
. . . . . http://www.summersault.com/ . . . . . . . .
|