[Catalyst] General Web- and OO-question

Scott McWhirter scott+catalyst at konobi.co.uk
Fri Mar 27 18:26:33 GMT 2009


2009/3/27 Cory Watson <jheephat at gmail.com>:
> 2009/3/27 Rodrigo <rodrigolive at gmail.com>
>>
>>
>>>
>>> But I can't instatiate
>>> the object because it throws an exception because age is not valid, isn't
>>> it?
>>
>>
>>>
>>> Or does Moose check constraints only on provided attributes. This can't
>>> be true
>>> with "required" attributes, can it?
>>
>> As long as the attribute is not "required => 1", no exception is thrown.
>
> I think you are missing his point.  He wants to instantiate an object from
> the form, but if he uses his Moose object then the things he wants to
> validate (errors) will prevent him from getting an instance of his class.
>  If "name" is required or isa 'Str' then if it gets an arrayref, he can't
> use the object (as either it missing or being the wrong type throws an
> exception).
> I don't know if this is a good idea yet, but it's fairly easy to create a
> "proxy" object for a given class, less all the validation:
> http://www.pastie.org/429140
>
> YMMV, but it would do what you want, as you could "promote" it to a real
> value iteratively after validation...

Why try to make your objects work harder than they have to?

If you have a multi-step process, collect all your data along each
step then initialize your object with the data at the end. If you need
to do validation along the way, you could reuse the moose type
constraints in the classes meta information without constructing an
object.


-- 
-Scott McWhirter- | -Technology Consultant-
[ Cloudtone Studios - http://www.cloudtone.ca ]



More information about the Catalyst mailing list