[Catalyst] Making Controllers thin and Models thick

Kee Hinckley nazgul at somewhere.com
Wed Jul 18 18:24:55 GMT 2007


On Jul 18, 2007, at 10:49 AM, John Napiorkowski wrote:
> validating types for your columns.  I do this for very
> common things like email addresses.  Postgresql is
> nice for this since you can create custom types and
> domains using Perl as your procedural language.

<pet-peeve>
Please tell me you're either doing *real* email validation (e.g.  
Mail::Address), or something overly lax..  Aside from sites that  
won't let me enter valid email addresses (keep in mind that just  
about the only character not legal in an email address is NUL).  I've  
even had sites who "updated" their validation such that people who  
previously had accounts could no longer login.  ("+" is the really  
common one to get rejected, but I had a friend who had his email  
rejected once because it had a "-" in the domain name!)

My rule of thumb on email validation is "don't bother".  Or rather,  
if you really care, send mail to it and ask them to respond.  After  
all, just because it's valid doesn't mean it *works*.  I think a lot  
of sites do it "just because".  Originally it was done because people  
kept "making mistakes."  Of course the most of the mistakes were  
intentional attempts to avoid getting spammed (somewhere.com was  
*real* popular for fake addresses).

If you're just checking for typos "/.+\@.+\..+/" is probably  
sufficient.  (Assuming of course that you don't want me to enter  
"somewhere.com!nazgul" as my email address, even though it might well  
work, and is certainly "legal".)
</pet-peeve>

> I end up mirroring a lot of this in DBIC using
> DBIC::Validate since I'd rather catch syntactical
> errors in my code instead of throwing a database
> error.  For me that's the last line of defense.

Are you referring to DBIx::Class::Validation, or is there another  
module.  I looked at that, but it didn't seem to make any use of the  
actual schema data.

> I tend to think of this as 'spell checking versus
> grammar checking'.  Your domain code is the grammar
> for a particular business activity.  At least I think
> of it that way.

That's a good metaphor.



More information about the Catalyst mailing list