[Catalyst] Catalyst::Component/Model Instances and Attributes per Request

Derek Wueppelmann dwueppel at gmail.com
Mon Jul 12 14:34:36 GMT 2010


On Sat, 2010-07-10 at 13:37 -0400, Alejandro Imass wrote:
> If in a Catalyst::Component, say an extension of Catalyst::Model, the
> attributes of my instance are also per-request. In other words if I do
> $self->yuca($c->stash->{yuca}) in ACCEPT_CONTEXT and return $self,
> will $self->yuca in the Model _instance_ in a separate memory space
> for this request? I would suspect that a Catalyst::Controller instance
> is paired with a single Model instance for a specific request.... but
> I'm afraid that being an _instance_ instead of a class, the attributes
> may get overriden by a second request that could be running in a
> parallel process or thread, say in mod_perl running on Apache prefork
> or worker (threads). Then again, I guess I'm answering myself as one
> request will run in one process or thread and the data segment is
> protected by the underlying OS, so I see no way a second request can
> override the attributes of a model instance.

>From my understanding when you make a request to the system all the
variable and objects are localized to the scope of that request. So
making multiple requests open multiple scopes and the data does not mix
between them. If you require data to survive past a single request this
is where the session object comes in. You can then store data and
objects that are required to survive past a single request here, however
this are specific for the session so don't mix with other requests that
are not related to the session.

Hopefully that helps.

-- 
 o)   Derek Wueppelmann           (o
(D .   dwueppel at gmail.com          D).
((`     http://www.monkeynet.ca   ( ) `





More information about the Catalyst mailing list