[Catalyst] Wrrite your own Model-class

Brandon Black blblack at gmail.com
Mon Jun 19 18:21:56 CEST 2006


On 6/19/06, Karl.Moens at marsh.com <Karl.Moens at marsh.com> wrote:
> Unfortunately there is (yet) no Catalyst::Model::IMAP available, so I
> considered --most audaciously-- to start writing such a model myself. I had
> a look at various models (such as DBIC) but could not easily re-engineer
> the rules I must follow to write such a model-class.
>
> I did find the "Writing plug-ins" tutorial and wonder whether a "Model is
> just a kind of "Plugin" with another name. If not, is there somewhere a
> handy guide to start writing Models? I do agree to keep a log of my
> wanderings on the path of writing a Model and make it available once the
> Catalyst::Model::IMAP is finished.
>

The basic idea is this: a model class should "use base" on
Catalyst::Model, which in turn uses the base class
Catalyst::Component.  Catalyst::Component's source code is a
must-read.  It defines basic implementations of "new", "config", and
"COMPONENT" (ignore "process" for models).

If your new C::M::IMAP declares nothing else and just inherits the
defaults, a user will be able to "use base Catalyst::Model::IMAP" in
their own "MyApp::Model::FooBar", and set ->config entries for it, and
get a reasonable object returned to them when they call
$c->model('FooBar')

This "reasonable object" is basically an object of class
"MyApp::Model::FooBar" whose object data consists of whatever config
values were supplied (__PACKAGE__->config() in the model class itself,
and/or config->{'MyApp::Model::FooBar'}->.... in the main app config,
etc).



More information about the Catalyst mailing list