Re: Better handling of constraint failures?

[prev] [thread] [next] [Date index for 2004/08/12]

From: Clayton L. Scott
Subject: Re: Better handling of constraint failures?
Date: 19:29 on 12 Aug 2004
On Thu, 12 Aug 2004, Drew Taylor wrote:

> But I also have constraints for some columns in a few CDBI classes. So
> now I have constraints in 2 places: my D::FV profiles and my CDBI class.
> It would be nice if there were a way to "export" the constraints with my
> CDBI classes so that I can easily integrate that with D::FV. Something like:
>
> my $cdbi_cons = Class->export_constraints;
> my $dfv_profiles = {runmode1=>{required=>['foo'],
>                                 constraints=>$cdbi_cons,
>                                }};
> # do actual D::FV validation here
>
> The idea here is that it's MUCH easier for me to have the D::FV failures
> integrated with my forms than CDBI constraints. I already have glue code
> setup so that all failures are caught and properly displayed to the
> user. Thoughts? Did I explain myself properly?

What makes it easier? The error reporting mechanism?

Sitting on my harddrive at home is a suite of modules I call Data::Form
that allows you to set up multiple validators per field in the following
form:

$field = new Field (
    name     => 'street',
    label    => 'Street Address',
    untaint  => qr/^((\w+|\s+)+)$/,
    validate => { 'between 2 and 100 characters' => qr/^.{2,100}$/,
                  'cannot contain V' => sub { shift =~ /V/ ? 0 : 1 },
                 }
);

$field->fill_in('25 rue Vanier');

unless ( $field->is_valid ){
  @errors = $field->errors; #cannot contain V
};


I could easily excise the validating routine if anyone wants if for CDBI
constraints. I just read that Tony added sub-based constraints to
constrain_column based but custom error messages per constraint would also help.

#Film->constrain_column(year => qr/\d{4}/);
Film->constrain_column(year => [ 'Year must be four digits' => qr/\d{4}/]);

My further plans on this module is to build a CDBI::Form clone that
intgrates Class::DBI with my Data::Form module

Clayton

Re: Better handling of constraint failures?
Drew Taylor 17:27 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 19:29 on 12 Aug 2004

Re: Better handling of constraint failures?
Drew Taylor 19:54 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 19:53 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 20:01 on 12 Aug 2004

Re: Better handling of constraint failures?
Perrin Harkins 19:51 on 12 Aug 2004

Re: Better handling of constraint failures?
Daniel Collis Puro 20:01 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 20:04 on 12 Aug 2004

Re: Better handling of constraint failures?
Daniel Collis Puro 20:42 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton Scott 21:49 on 12 Aug 2004

Re: Better handling of constraint failures?
Tony Bowden 13:52 on 24 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52