[Catalyst] Form validation in insert() and update()?

mla maurice.aubrey at gmail.com
Tue May 15 23:20:47 GMT 2007


Matt S Trout wrote:
> On Tue, May 15, 2007 at 01:04:42PM -0700, mla wrote:
>> Okay, thanks very much for this. So in terms of the model constraints,
>> you will validate everything twice. Once at the controller layer (where
>> it leverages info from the model), and once in the model itself.
>>
>> So you can interrogate the model to find out, for example, that the
>> email column can't be longer than 100 characters and should match the
>> pattern /@/ (just to keep it simple here).
>>
>> Do you expose something like a Model->valid_email() method that can be
>> used both within the model and from the controller?
> 
> my $tc = Model->meta->get_attribute('email')->type_constraint;
> 
> my $error = $tc->validate($value); # undef for 'value ok'
> 
> Here lies the joy of Moose everywhere :)

Whew. Okay, Moose. New way to make objects. Wasn't familiar with that.

So you base your entire app on Moose. It's not a dependency for
either DBIx::Class or Catalyst... so when you say everywhere,
you mean everything in your particular app inherits from Moose?

Who implements the type_constraint object? I just grepped my
perl sources and didn't see it anywhere.

Thanks,

Maurice



More information about the Catalyst mailing list