[Catalyst] General Web- and OO-question

Rodrigo rodrigolive at gmail.com
Fri Mar 27 17:53:22 GMT 2009


>
> But that' s my problem: One one web page I do not get all attributes I ne=
ed
> to instantiate the object correctly. Simple unrealistic example. One one
> page
> the user can enter a "name" on the second the "age". The object can be
> instatiated
> if you provide a valid name and age.


Well, just instantiate an empty object then use the accessors Moose creates
for you automagically. Accessors validate as well:

sub start_up : Local {
    $c->session->{obj} =3D new MyClass();
}
sub submit_name : Local {
    $c->session->{obj}->name( $c->req->params->{name} );
}
sub submit_age : Local {
    $c->session->{obj}->age( $c->req->params->{age} );
}


> 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 =3D> 1", no exception is thrown.


>
> > Catalyst::Model::Adaptor may also come in handy if
> > you feel you need to turn your class into a model.
>
> What do you mean with that?
>

First, read up on the Model part of MVC, that's where most of your
application storage should end up. Have you decided what are you going to do
with the object once it's filled up?

--rodrigo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090327/0dcc1=
ed6/attachment.htm


More information about the Catalyst mailing list