[Catalyst] Creating a thin Model
Christopher H. Laco
claco at chrislaco.com
Fri May 18 18:11:47 GMT 2007
Christopher H. Laco wrote:
> Jamie Neil wrote:
>> Can anyone tell me the best way of wrapping a non catalyst perl module
>> in a Catalyst Model?
>>
>> I'm trying to setup the following stack:
>>
>> MyApp::Controller::Widget
>> MyApp::Model::Widget
>> MyApp::Logic::Widget
>> MyApp::Schema::DB
>>
>> where MyApp::Model::Widget is based on Catalyst::Model, contains the
>> configuration information for MyApp::Logic::Widget, and makes the
>> methods in MyApp::Logic::Widget available in MyApp::Controller::Widget
>> as $c->Model('Widget')->mymethod(...);
>>
>> MyApp::Schema::DB is a DBIC Schema which I want MyApp::Logic::Widget to
>> use for storage, but not just passed through to the Model in the same
>> way that Catalyst::Model::DBIC::Schema does.
>>
>> There is obviously more than one way to do this from looking at all the
>> other models on CPAN, but is there some kind of best practice? Should I
>> use AUTOLOAD, ACCEPT_CONTEXT, COMPONENT, override new or something else?
>>
>> I did see a very promising thread on this issue a few months ago, but
>> this question
>> (http://lists.scsys.co.uk/pipermail/dbix-class/2007-January/003289.html)
>> was never really answered. I've been going round and round in circles on
>> this for a couple of weeks now, so some pointers (or even better example
>> code) would be most welcome.
>>
> =
> You're right. It depends on a few things.
> Does the module you're wrapping have a new? Is it statefull? stateless?
> Is it self creating, or is it a factory that creates other things.
> =
> Those are all factors.
> =
> Personally, I almost always do:
> =
> sub COMPONENT {
> my $self =3D NEXT::new
> =
> diddle config...return $self
> }
> =
Sorry...that pseudo code was too vague:
sub COMPONENT {
my $self =3D shift->NEW::new(@_);
$self->{'noncatclass'} =3D NonCatClass->new
return $self
}
Then, delegate via autoload, or use real methods to forward request to
the instance of the real class...
-=3DChris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070518/f418=
8266/signature.pgp
More information about the Catalyst
mailing list