|Think about Loose Coupling|
Better way to catch Class::DBI constraint failures?by Hero Zzyzzx (Curate)
|on Aug 12, 2004 at 15:57 UTC||Need Help??|
Hero Zzyzzx has asked for the
wisdom of the Perl Monks concerning the following question:
What I REALLY want to do is find a more elegant way of catching specific CDBI::constraint failures- I've overridden CDBI::_croak in my base class, but the info I get back isn't all that useful.
The %info hash returns a reference to the Namespace object and an example error message is:Namespace namespace fails 'list' constraint with 'page'
Where "Namespace" is a CDBI subclass, the field is "namespace" and the constraint was: Namespace->constrain_column(namespace=>[qw/foo/]);
I can parse this error message, but I fear that I can't rely on the text of the error message in perpetuity and that different constraints may throw different errors now or at some other point in time.
The reason I want to catch constraint failures is because I want the constraint checking to act as my HTML form validation check: If the constraint check barfs, I want to re-output the form with an error message on the field that failed. Without an easy way to know which field failed, this won't be easy. Using CDBI constraints to check form values seems like a pretty good way to not repeat myself. . . but I need to give the user specific feedback about the failure.
Ideas? Thanks in advance.
* Assuming that perl modules can be cool in the first place. :)
-Any sufficiently advanced technology is