[Catalyst] Begginer's question about application structure
Martin Bendix
martinbendix at yahoo.co.uk
Mon Nov 22 15:47:57 GMT 2010
----- Original Message ----
> From: Ben van Staveren <benvanstaveren at gmail.com>
> To: The elegant MVC web framework <catalyst at lists.scsys.co.uk>
> Sent: Mon, 22 November, 2010 15:13:00
> Subject: Re: [Catalyst] Begginer's question about application structure
>
> Personally (and this does mean personally), I'd do it as follows:
>
> Your actual "logic" code (e.g. the whole deal of storing and retrieving things
>from the database) should be in a separate set of modules. Call those the
>'backend' stuff. The main module here should be able to connect to the database
>on it's own, given the location of a config file, and it should be able to take
>an existing configuration and DB handle from Catalyst;
>
> e.g.
> my $backend = My::Backend->new(config_file => 'foo.cfg');
>
> or
>
> my $backend = My::Backend->new(config => $c->config, database => $c->model);
>
> (the above isn't quite correct but forgot what I used myself).
>
> Then you can easily wrap that into a Model; and do things like:
>
> $c->model('Backend')->get_me_an_artist()
>
> The advantage here being that you can also use your backend outside of
>Catalyst, so writing a console app becomes trivial at that point.
>
> Sorry for the slightly disjointed reply but doing about 234413 things at the
>same time :D
>
Hi Ben,
Thank you for your reply. I was leaning towards that approach myself, and have
written a couple of modules which allow me to grab the config and database
connections from an external model.
Martin
More information about the Catalyst
mailing list