[Catalyst] Modelling the right way

Eden Cardim edencardim at gmail.com
Thu Sep 3 12:34:53 GMT 2009


On Thu, Sep 3, 2009 at 7:20 AM, Matthias Dietrich<mdietrich at cpan.org> wrote:
> Hi,
>
> the models in my past applications were quite small and if they need
> interaction with other models (like DBIC and stuff), I used ACCEPT_CONTEXT
> to either get the complete context object or part of it.  But all the models
> were related only to website parts and I didn't use them outside of
> catalyst.  But, one goal of models should be to be able to use them without
> catalyst, e.g. in cron jobs or other scripts.
>
> In a "proof of concept" app I'm building right now, I need the models to be
> usable outside, so I cannot rely on the context object to interact with
> other models and the database.  My idea is to build the modules with
> business logic completly independent from catalyst and use the models as
> thin wrappers around them.  With Catalyst::Component::InstancePerContext I'm
> able to construct these modules per request and pass the schema as parameter
> to new(), so the module could use the database for retrieving the required
> data.  As the other models are only wrappers, too, I could just 'use' the
> other modules inside one module and pass along the schema, too.
>
> I'm interested if this way of "modelling" is acceptable, how you achieved
> this and what is considered best practice.

Yes, you should be building your models as standalone modules and
using the catalyst component infrastructure merely for glueing those
into your web application. This also has the benefit of easing the
process of unit testing. Have a look at how Model::DBIC::Schema and
View::TT do it, and have a look at
http://www.catalystframework.org/calendar/2007/24

-- 
   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://edenc.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list