[Catalyst] Models Inheriting from Catalyst::Base
Brandon Black
blblack at gmail.com
Thu Nov 17 21:56:30 CET 2005
On 11/17/05, Bill Moseley <moseley at hank.org> wrote:
> On Thu, Nov 17, 2005 at 11:29:08AM -0600, Brandon Black wrote:
> > AFAIK, the advantage of using Catalyst base classes in your model is
> > that your ::Loader configuration can come from Catalyst-derived
> > ->config() directives, which in turn means you can set your database
> > dsn, password, etc from your application YAML config, instead of
> > hardcoding it in the Model file.
>
> But, that's not a requirement -- if you don't mind hard-coding the
> name of the application.
>
> Here's my entire model class:
>
> package App::M::CDBI;
> use DB;
> DB->new( App->config->{database} );
> 1;
>
>
> Can someone point me to docs on what happens if you inherit from
> Catalyst? IIRC, Catalyst will call your new() method (which, IIRC,
> should call $self->NEXT::new($c)) and then you can store your object
> in $c->components hash.
>
> I have not had the need to use $c->component (or $c->model etc.) yet,
> so that's a hole in my understanding of Catalyst.
>
Inheriting your Model from Catalyst::Model::* does not give your Model
access to $c, but it does give your controllers access to your Model
via:
$c->comp('App::M::CDBI::MyTable')->a_table_method();
as opposed to otherwise just using:
App::M::CDBI::MyTable->a_table_method();
directly. I don't yet understand the advantage of using $c->comp() at
all, either. I suppose it's probably something doesn't become
apparent until you do something significantly more complicated and
dynamic than the simple examples we've been discussing.
-- Brandon
More information about the Catalyst
mailing list