Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Model Instances vs. Model Classes - Round 2

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


alejandro.imass at gmail

May 17, 2011, 7:58 PM

Post #1 of 21 (1068 views)
Permalink
Model Instances vs. Model Classes - Round 2

Hi,

As a few may remember I brought this up a while ago and after working
with this for a while I just want to make sure we are really
understanding and using this correctly...

Postulates:
1) Ideally all the business code should be abstracted into models and
more ideally these models should be classes that are independent from
Catalyst. We shall call these business model classes to differentiate
them from Catalyst Model classes.
2) The Catalyst model as such (script/xx_create.pl model yyy) should
be a thin wrapper to the business model classes from postulate 1.
3) Catalyst Models may be classes or instances.

Design Patterns:
1) If the Catalyst model will be a class, the pattern is very simple:
The catalyst model class uses the business object class just like any
other library. As I understand it, the controller code would have to
invoke new() on the model class to create a new instance of the class
that will die with the request (will lose scope from the controller
method that created it).
2) If the Catalyst model will be an instance, the design pattern is a
per-request object factory. The fat code should be kept in the
instance class, and the ACCEPT_CONTEXT method should be used to
instantiate a leaner class and return _that_ to the controller. The
idea of an instance, is that most of the heavy duty code remain
instantiated and the code is purely functional.

Assumptions and Questions
1) Is the assumption that in the first design pattern the controller
has to call new() correct? (I have always worked with the second
pattern, so I don't know for sure).
2) For Catalyst instance models, the request classes should not
contain any heavy duty code. So forcibly the request class needs a
reference to the parent model class (the factory). This is so the
request class is able to use the methods of the factory class. Is this
assumption correct?
3) It is written somewhere (I couldn't find it before writing this but
I know is in the POD somewhere) that it is not a good idea to pass the
complete $c reference to the per-request object, but rather only the
necessary pieces of $c. What are the implications of passing the
complete $c ?

Any other comments greatly appreciated. I think this could make an
interesting article for the Wiki so I want to get all the real experts
opinions on this before I attempt to create it.

Thanks,

--
Alejandro Imass

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


octavian.rasnita at ssifbroker

May 17, 2011, 10:42 PM

Post #2 of 21 (1046 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

From: "Alejandro Imass" <alejandro.imass [at] gmail>
> 3) It is written somewhere (I couldn't find it before writing this but
> I know is in the POD somewhere) that it is not a good idea to pass the
> complete $c reference to the per-request object, but rather only the
> necessary pieces of $c. What are the implications of passing the
> complete $c ?



If you pass the context $c to the business model, and the business model
would need to access the attributes and methods offered by $c, then you
won't be able to use that business model outside of Catalyst because you
won't have the context variable available.

Octavian


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

May 18, 2011, 6:05 AM

Post #3 of 21 (1050 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Wed, May 18, 2011 at 1:42 AM, Octavian Rasnita
<octavian.rasnita [at] ssifbroker> wrote:
> From: "Alejandro Imass" <alejandro.imass [at] gmail>
>>
>> 3) It is written somewhere (I couldn't find it before writing this but
>> I know is in the POD somewhere) that it is not a good idea to pass the
>> complete $c reference to the per-request object, but rather only the
>> necessary pieces of $c. What are the implications of passing the
>> complete $c ?
>
>
>
> If you pass the context $c to the business model, and the business model
> would need to access the attributes and methods offered by $c, then you
> won't be able to use that business model outside of Catalyst because you
> won't have the context variable available.
>
> Octavian
>

Thanks for your prompt reply. Absolutely agree. For example, even
stuff like loggers, etc. should be kept independent of Catalyst, that
is clear to me. But my question is specific to the Catalyst Model
"Instance" (pattern #2 in my OP). That is, the the model instance is a
factory that spawns smaller per-request objects vis the ACCEPT_CONTEXT
method. This is all catalyst, since in this pattern it must be assumed
that the business model classes are instantiated as long-living
objects in the factory class, probably as attributes (Refs) of the
Catalyst Model Instance.

In other words, the business code should be instantiated by the
factory class, for example: a business model class would be
instantiated as an attribute (type Ref) of the Catalyst Model Instance
so the business logic is loaded only once, and does not have to be
loaded per every request and then thrown away. This also means two
things which is what I would like to verify with you here:

1) The per-request objects (the ones spawned by the Catalyst Model
Instance in ACCEPT_CONTEXT) forcibly need a reference to the factory
class so they can access the business model objects that were
instantiated upon start-up.

2) The business model classes need to receive all the information
needed, that-is the data structures of the per-request information
that live in the smaller per-instance objects. This pattern allows you
to pre-load all your business logic in the factory class and
effectively de-couple the business logic from Catalyst.

Anyway, that's whay I see as the whole point of Catalyst Instances,
mean that you can pre-load as much of the business code in RAM and
only spwan very small clases per-request that are basically all data:
that is the methods of these per-request objects should actually be
calling methods in the pre-instantiated code in the factory class (the
Catalyst Model instance).

This makes the Model Instance a wrapper of business class and itself
can be modelled in two ways:

1) The methods of the factory are wrappers of private business class objects.
2) The business classes are references modeled as attributes of the
factory class and invoked directly by the per-request objects.

I just want to make sure these suggested patterns are not doing
something horribly stupid that would make the app useless in a
multi-threaded env for example (i.e. *NIX mod_perl + mod_worker).

Maybe I should craft up some sample code of the three patterns identified:

1) Catalyst Models Classes: that completely instantiate per request.
2) Catalyst Model Instances: with wrapper methods
3) Catalyst Model Instances: with wrapper attributes

In both 2 and 3, business objects as such are instantiated when the
Catalyst Model is instantiated. The difference is how to expose the
business objects to the per-request objects spawned by ACCEPT_CONTEXT.

Why am I doing all this? Because if you look at the books that
currently exist about Catalyst, the POD and the Wiki, honestly there
are no simple and down to earth explanations on Catalyst models, just
a lot of blurb on "what" are the best practices but no so much "how"
they should be accomplished and with clear down to earth examples for
the mere mortal.

I'm willing to do the work but first I want to make sure my conceptual
framework is correct. I think there should be some clear code examples
with the different patterns to actually achieve these best practices.

Best,

--
Alejandro

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


edencardim at gmail

May 18, 2011, 9:48 AM

Post #4 of 21 (1042 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

>>>>> "Octavian" == Octavian Rasnita <octavian.rasnita [at] ssifbroker> writes:
Octavian> If you pass the context $c to the business model, and the business model
Octavian> would need to access the attributes and methods offered by $c, then you
Octavian> won't be able to use that business model outside of Catalyst because you
Octavian> won't have the context variable available.

Technically, that isn't true. Given this is perl, we don't have implicit
type-checking, so you can always use duck typing, ie, build a class that
mimics all the methods available to $c and sons. The real issue is that
your API will be laden with web-based semantics, not business
semantics. The focal point of me bringing this up is that the
implementation is barely what matter in a discussion like this, it's
always about the API semantics.

--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://blog.edencardim.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

May 19, 2011, 1:04 AM

Post #5 of 21 (1042 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Wed, May 18, 2011 at 12:48 PM, Eden Cardim <edencardim [at] gmail> wrote:
>>>>>> "Octavian" == Octavian Rasnita <octavian.rasnita [at] ssifbroker> writes:
>    Octavian> If you pass the context $c to the business model, and the business model
>    Octavian> would need to access the attributes and methods offered by $c, then you
>    Octavian> won't be able to use that business model outside of Catalyst because you
>    Octavian> won't have the context variable available.
>
> Technically, that isn't true. Given this is perl, we don't have implicit
> type-checking, so you can always use duck typing, ie, build a class that
> mimics all the methods available to $c and sons. The real issue is that
> your API will be laden with web-based semantics, not business
> semantics. The focal point of me bringing this up is that the
> implementation is barely what matter in a discussion like this, it's
> always about the API semantics.
>

Yes. In fact there is a lot of stuff I forgot to mention in the
postulated patterns. What I have been doing is standardizing an
'entity' data structure that _is the api_ between the cat/web-based
semantics and the business logic. The concept of 'state' goes well
with business class and with Web/REST

The 'entity' is instantiated by the per-request object and accumulates
transactions and data during the execution of the request. It's a
pure-perl/Moose object that is passed back and forth and in the end is
returned to the controller for rendering. It has methods to return
itself ->as_hash for example so it can be digested by a TT view or
methods as_json if you are not using something like CC::REST.

Usually most business logic revolves around some sort of state
machine, workflow so it's basically tracking entering state,
intermediate states and transactions and a resulting state. As stated
This abstraction also pairs well with both EPC (Event Driven Process
Chains) and with REST ;-) (i.e. the entity is a whole and represents
it's state, the entity can be a data object or a business process
object).

What I'm not exactly sure is about the way we are using Catalyst Model
Instances. For us all this trouble of instances is mainly to load as
much business logic code as possible when starting the app and
minimizing the per-request loading and unloading of heavy-duty code.
The questions mainly revolve around this (see my OP).

--
Alejandro Imass

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


hitz at stanford

May 19, 2011, 4:06 PM

Post #6 of 21 (1029 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

>
> Maybe I should craft up some sample code of the three patterns identified:
>
> 1) Catalyst Models Classes: that completely instantiate per request.
> 2) Catalyst Model Instances: with wrapper methods
> 3) Catalyst Model Instances: with wrapper attributes

Would like to see that. Some of us don't follow all this abstract computer science jargon that well.

Also - can you comment on the following:

WARNING WARNING WARNING

Using this module is somewhat of a hack. Changing the state of your objects on every request is a pretty braindead way of doing OO. If you want your application to be brain-live, then you should use Catalyst::Component::InstancePerContext.

(appears in POD for Catalyst::Component::ACCEPT_CONTEXT - which I was reviewing because of your email... apparently I must have read this once and told my self "Never do this")


Ben
--
Ben Hitz
Senior Scientific Programmer ** Saccharomyces Genome Database ** GO Consortium
Stanford University ** hitz [at] genome




_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

May 20, 2011, 11:22 AM

Post #7 of 21 (1031 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Thu, May 19, 2011 at 7:06 PM, Benjamin Hitz <hitz [at] stanford> wrote:

[...]

> Would like to see that.  Some of us don't follow all this abstract computer science jargon that well.
>

Granted, after re-reading my posts _I_ don't even understand them

> Also - can you comment on the following:
>
> WARNING WARNING WARNING
>
> Using this module is somewhat of a hack. Changing the state of your objects on every request is a pretty braindead way of doing OO. If you want your application to be brain-live, then you should use Catalyst::Component::InstancePerContext.
>
> (appears in POD for Catalyst::Component::ACCEPT_CONTEXT - which I was reviewing because of your email... apparently I must have read this once and told my self "Never do this")
>

Ok. Why don't we start with a simple and plain definition of what is
meant by Class "Type" in Catalyst jargon:

- class
- instance


--
Alex

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

Jul 19, 2011, 11:25 PM

Post #8 of 21 (864 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Thu, May 19, 2011 at 7:06 PM, Benjamin Hitz <hitz [at] stanford> wrote:
>>
>> Maybe I should craft up some sample code of the three patterns identified:
>>
>> 1) Catalyst Models Classes: that completely instantiate per request.
>> 2) Catalyst Model Instances: with wrapper methods
>> 3) Catalyst Model Instances: with wrapper attributes
>
> Would like to see that.  Some of us don't follow all this abstract computer science jargon that well.
>

I tried to make it as practical as possible:

http://wiki.catalystframework.org/wiki/best_practices/models_definitive_guide

Maybe others can complement with more "M Patterns"

Best,

Alejandro Imass

> Also - can you comment on the following:
>
> WARNING WARNING WARNING
>
> Using this module is somewhat of a hack. Changing the state of your objects on every request is a pretty braindead way of doing OO. If you want your application to be brain-live, then you should use Catalyst::Component::InstancePerContext.
>
> (appears in POD for Catalyst::Component::ACCEPT_CONTEXT - which I was reviewing because of your email... apparently I must have read this once and told my self "Never do this")
>
>
> Ben
> --
> Ben Hitz
> Senior Scientific Programmer ** Saccharomyces Genome Database ** GO Consortium
> Stanford University ** hitz [at] genome
>
>
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

Jul 20, 2011, 7:00 AM

Post #9 of 21 (862 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Wed, Jul 20, 2011 at 2:25 AM, Alejandro Imass
<alejandro.imass [at] gmail> wrote:
> On Thu, May 19, 2011 at 7:06 PM, Benjamin Hitz <hitz [at] stanford> wrote:
>>>

[...]

> I tried to make it as practical as possible:
>
> http://wiki.catalystframework.org/wiki/best_practices/models_definitive_guide
>
> Maybe others can complement with more "M Patterns"
>

The Catalyst Wiki seems to be having some problems so i posted it on PM as well:

http://www.perlmonks.org/?node_id=915657



> Best,
>
> Alejandro Imass
>

[...]

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


apv at sedition

Jul 20, 2011, 7:07 AM

Post #10 of 21 (861 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Wed, Jul 20, 2011 at 7:00 AM, Alejandro Imass
<alejandro.imass [at] gmail> wrote:
> On Wed, Jul 20, 2011 at 2:25 AM, Alejandro Imass
> <alejandro.imass [at] gmail> wrote:
>> On Thu, May 19, 2011 at 7:06 PM, Benjamin Hitz <hitz [at] stanford> wrote:
> [...]
>> I tried to make it as practical as possible:
>>
>> http://wiki.catalystframework.org/wiki/best_practices/models_definitive_guide
>>
>> Maybe others can complement with more "M Patterns"
>>
>
> The Catalyst Wiki seems to be having some problems so i posted it on PM as well:
>
> http://www.perlmonks.org/?node_id=915657

You probably never saw it but I did a bunch of this a couple years
ago. It's a bit old but contains a lot of good stuff anyway:
http://sedition.com/a/2733

And the code with a couple other pieces I didn't really cover in the
articles is here: https://github.com/pangyre/p5-myapp-10in10

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

Jul 20, 2011, 7:14 AM

Post #11 of 21 (864 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Wed, Jul 20, 2011 at 10:07 AM, Ashley Pond V <apv [at] sedition> wrote:
> On Wed, Jul 20, 2011 at 7:00 AM, Alejandro Imass
> <alejandro.imass [at] gmail> wrote:
>> On Wed, Jul 20, 2011 at 2:25 AM, Alejandro Imass

[...]

> You probably never saw it but I did a bunch of this a couple years
> ago. It's a bit old but contains a lot of good stuff anyway:
> http://sedition.com/a/2733
>
> And the code with a couple other pieces I didn't really cover in the
> articles is here: https://github.com/pangyre/p5-myapp-10in10
>

Great! Let me go through it and combine all this info into a single
place. For now I will update the PM node until the Cat Wiki revives.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


pjf at roxsoft

Jul 20, 2011, 9:50 AM

Post #12 of 21 (862 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On 20/07/11 07:25, Alejandro Imass wrote:
>
> http://wiki.catalystframework.org/wiki/best_practices/models_definitive_guide
>

In this example

package Models::Model::HomeGrownModel;

use base 'Catalyst::Model';

use HomeGrown;

sub COMPONENT {
my ( $self, $app ) = @_;
my $dbic_schema = $app->model('ModelsDB')->schema;
return HomeGrown->new( schema => $dbic_schema );
}

how are you ensuring 'ModelsDB' has been instantiated before
'HomeGrownModel'?

--

Regards

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


bobtfish at bobtfish

Jul 20, 2011, 10:15 AM

Post #13 of 21 (862 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On 20 Jul 2011, at 17:50, Peter Flanigan wrote:
>
> how are you ensuring 'ModelsDB' has been instantiated before
> 'HomeGrownModel'?

Random chance? :)

Cheers
t0m


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


hitz at stanford

Jul 22, 2011, 8:46 AM

Post #14 of 21 (841 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

Alejandro -
thanks for this, it's quite clear.... I had forgotten that I asked for it even.

Ben
On Jul 19, 2011, at 11:25 PM, Alejandro Imass wrote:

> On Thu, May 19, 2011 at 7:06 PM, Benjamin Hitz <hitz [at] stanford> wrote:
>>>
>>> Maybe I should craft up some sample code of the three patterns identified:
>>>
>>> 1) Catalyst Models Classes: that completely instantiate per request.
>>> 2) Catalyst Model Instances: with wrapper methods
>>> 3) Catalyst Model Instances: with wrapper attributes
>>
>> Would like to see that. Some of us don't follow all this abstract computer science jargon that well.
>>
>
> I tried to make it as practical as possible:
>
> http://wiki.catalystframework.org/wiki/best_practices/models_definitive_guide
>
> Maybe others can complement with more "M Patterns"
>
> Best,
>
> Alejandro Imass
>
>> Also - can you comment on the following:
>>
>> WARNING WARNING WARNING
>>
>> Using this module is somewhat of a hack. Changing the state of your objects on every request is a pretty braindead way of doing OO. If you want your application to be brain-live, then you should use Catalyst::Component::InstancePerContext.
>>
>> (appears in POD for Catalyst::Component::ACCEPT_CONTEXT - which I was reviewing because of your email... apparently I must have read this once and told my self "Never do this")
>>
>>
>> Ben
>> --
>> Ben Hitz
>> Senior Scientific Programmer ** Saccharomyces Genome Database ** GO Consortium
>> Stanford University ** hitz [at] genome
>>
>>
>>
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/

--
Ben Hitz
Senior Scientific Programmer ** Saccharomyces Genome Database ** GO Consortium
Stanford University ** hitz [at] stanford




_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


orasnita at gmail

Jul 24, 2011, 5:41 AM

Post #15 of 21 (812 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

From: "Ashley Pond V" <apv [at] sedition>

> On Wed, Jul 20, 2011 at 7:00 AM, Alejandro Imass
> <alejandro.imass [at] gmail> wrote:
>> On Wed, Jul 20, 2011 at 2:25 AM, Alejandro Imass
>> <alejandro.imass [at] gmail> wrote:
>>> On Thu, May 19, 2011 at 7:06 PM, Benjamin Hitz <hitz [at] stanford> wrote:
>> [...]
>>> I tried to make it as practical as possible:
>>>
>>> http://wiki.catalystframework.org/wiki/best_practices/models_definitive_guide
>>>
>>> Maybe others can complement with more "M Patterns"
>>>
>>
>> The Catalyst Wiki seems to be having some problems so i posted it on PM as well:
>>
>> http://www.perlmonks.org/?node_id=915657
>
> You probably never saw it but I did a bunch of this a couple years
> ago. It's a bit old but contains a lot of good stuff anyway:
> http://sedition.com/a/2733

This address cannot be found.


Octavian


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

Jul 28, 2011, 8:11 AM

Post #16 of 21 (781 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Fri, Jul 22, 2011 at 11:46 AM, Benjamin Hitz <hitz [at] stanford> 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

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

Jul 28, 2011, 12:22 PM

Post #17 of 21 (780 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Wed, Jul 20, 2011 at 12:50 PM, Peter Flanigan <pjf [at] roxsoft> wrote:
> On 20/07/11 07:25, Alejandro Imass wrote:
>>
>> http://wiki.catalystframework.org/wiki/best_practices/models_definitive_guide
>>
>
> In this example
>
>    package Models::Model::HomeGrownModel;
>
>    use base 'Catalyst::Model';
>
>    use HomeGrown;
>
>    sub COMPONENT {
>      my ( $self, $app ) = @_;
>      my $dbic_schema = $app->model('ModelsDB')->schema;
>      return HomeGrown->new( schema => $dbic_schema );
>    }
>
> how are you ensuring 'ModelsDB' has been instantiated before
> 'HomeGrownModel'?
>

I updated the Perlmonks article and the code in SVN to reflect this fix.

http://www.perlmonks.org/?node_id=915657

Thanks for pointing this out.
I will proceed to update the Catalyst Wiki as well....

--
Alejandro

> --
>
> Regards
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

Aug 2, 2011, 3:23 AM

Post #18 of 21 (757 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Thu, Jul 28, 2011 at 3:22 PM, Alejandro Imass
<alejandro.imass [at] gmail> wrote:
> On Wed, Jul 20, 2011 at 12:50 PM, Peter Flanigan <pjf [at] roxsoft> wrote:
>> On 20/07/11 07:25, Alejandro Imass wrote:
>>>

[...]

> I updated the Perlmonks article and the code in SVN to reflect this fix.
>
> http://www.perlmonks.org/?node_id=915657
>
> Thanks for pointing this out.
> I will proceed to update the Catalyst Wiki as well....
>

FYI there was still another bug in the initialization code for
modelthree, so I re-wrote it to make it clearer and more elegant.

Best,

--
Alejandro Imass


> --
> Alejandro
>
>> --
>>
>> Regards
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>>
>

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


darius.jokilehto at net-a-porter

Aug 2, 2011, 3:45 AM

Post #19 of 21 (752 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On 20/07/11 15:00, Alejandro Imass wrote:
>
> The Catalyst Wiki seems to be having some problems so i posted it on PM as well:
>
> http://www.perlmonks.org/?node_id=915657
In your first example,

$c->model('Models::People')->all()

and

$c->model('Models')->schema->resultset('People');


are not (necessarily) equivalent. The former always returns an array,
the latter only in array context.
>
>
>> Best,
>>
>> Alejandro Imass
>>
>


NET-A-PORTER.COM
Irresistible fashion at your fingertips

______________________________________________________________________

CONFIDENTIALITY NOTICE
The information in this email is confidential and is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, you must not read, use or disseminate the information. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Net a Porter Ltd.

Net A Porter Ltd is a company registered in England & Wales Number: 3820604 Registered Office: 1 The Village Offices, Westfield, Ariel Way, London, W12 7GF
_____________________________________________________________________

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


darius.jokilehto at net-a-porter

Aug 2, 2011, 3:48 AM

Post #20 of 21 (752 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On 02/08/11 11:45, Darius Jokilehto wrote:
>
> are not (necessarily) equivalent. The former always returns an array,
> the latter only in array context.
Oops, *list* context


NET-A-PORTER.COM
Irresistible fashion at your fingertips

______________________________________________________________________

CONFIDENTIALITY NOTICE
The information in this email is confidential and is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, you must not read, use or disseminate the information. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Net a Porter Ltd.

Net A Porter Ltd is a company registered in England & Wales Number: 3820604 Registered Office: 1 The Village Offices, Westfield, Ariel Way, London, W12 7GF
_____________________________________________________________________

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alejandro.imass at gmail

Aug 2, 2011, 4:16 AM

Post #21 of 21 (752 views)
Permalink
Re: Model Instances vs. Model Classes - Round 2 [In reply to]

On Tue, Aug 2, 2011 at 6:45 AM, Darius Jokilehto
<darius.jokilehto [at] net-a-porter> wrote:
> On 20/07/11 15:00, Alejandro Imass wrote:
>>
>> The Catalyst Wiki seems to be having some problems so i posted it on PM as
>> well:
>>
>> http://www.perlmonks.org/?node_id=915657
>
> In your first example,
>
>  $c->model('Models::People')->all()
>
> and
>
>  $c->model('Models')->schema->resultset('People');
>
>
> are not (necessarily) equivalent. The former always returns an array, the
> latter only in array context.
>>

Yes, thanks for pointing this out. Assigning to @array saves a lot of
explaining. My idea is to focus the guide on the design patterns of
the M layer, not the details of DBIC workings, so I tried to keep the
examples "equivalent" to make the point.

Thanks,

--
Alejandro Imass

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.