[Catalyst] Model Instances vs. Model Classes - Round 2

Alejandro Imass alejandro.imass at gmail.com
Thu Jul 28 15:11:06 GMT 2011


On Fri, Jul 22, 2011 at 11:46 AM, Benjamin Hitz <hitz at stanford.edu> wrote:
>
> Alejandro -
> thanks for this, it's quite clear.... I had forgotten that I asked for it even.
>
> Ben


Yeah I had this pending because I think it's very frustrating for many
people that, even by buying commercial Catalyst books, they tell them
__what__ to do with models but now exactly __how__.

There is a potential bug in the example code as Peter Flanigan pointed
out, but it works every sigle time I've tested it. It seems to
coincide with this thread from jerome.eteve at gmail May 29, 2010,
5:08 AM, that nobody answered. I am getting the same "Surprisingly,
this works...." result as he explained:

http://www.gossamer-threads.com/lists/catalyst/users/26974?search_string=order;#26974

In this other thread:

http://www.gossamer-threads.com/lists/catalyst/users/27169?search_string=order;#27169

There is a recomendation by Thomas Doran to delay the instantiation of
the model using Moose after with something like this:

after setup_components => sub {
my $app = shift;
for (keys %{ $app->components }) {
$app->components->{$_}->initialize_after_setup($app) if $app-
>components->{$_}->can('initialize_after_setup');
}
};

I am still trying to understand the different instatiation-order
options and to modify my sample code accordingly. In any case, the
point of these examples are to give some guide on the different
options that people have when designing and constructing their M layer
for catalyst applications. I will post the revised article and update
the sample code when I get a chance....

--
Alejandro



More information about the Catalyst mailing list