Data Validation (Again, sorry)
[prev]
[thread]
[next]
[Date index for 2004/06/29]
Hi,
I've just added constraints to my code via 'add_constraint' and
'constrain_column.' They work fantastic. Problem is that I cannot figure out
what I'm supposed to do now. What I want to happen is for an exception to be
thrown and be "...stored in an exception object, via a custom _croak()
method, and then caught and used to redisplay the form with error messages
next to each field which failed validation." Right, that's exactly what I
need but after reading the instructions on 'Exceptions' I don't exactly
understand how the exception is to be retrieved from my CGI::Application
class.
-snip-
"The _croak() method is expected to trigger an exception and not return."
So let's say I have:
package Music;
use Error;
...
sub _croak {
my ($self, $message, %info) = @_;
Error->throw(-text => $message, %info);
}
package Music::CD;
...
__PACKAGE__->constrain_column( price => qr/\d{2}\.\d{2}/ );
package SOME_CGI_APP
use base 'CGI::Application'
...
sub create_cd {
...
my $cd = Music::CD->create( ..., price => '$14' );
}
Okay so the _croak method in package Music::CD is called after failing the
regex test. It then throws the exception, but how could I retrieve this from
SOME_CGI_APP? Does the exception have to be stored in the Music class and is
the Error package one that I need to write (or is it the Ewan Birney >
bioperl-1.4 > Error package at CPAN, though it didn't look like it). Sorry
if this has been long winded but many thanks for your time and thoughts!
-Bryon Bean
|
Data Validation (Again, sorry)
Bryon Bean 00:58 on 29 Jun 2004
|