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 = NEXT::new
> 
>  diddle config...return $self
> }
> 

Sorry...that pseudo code was too vague:


sub COMPONENT {
  my $self = shift->NEW::new(@_);
  $self->{'noncatclass'} = NonCatClass->new
  return $self
}

Then, delegate via autoload, or use real methods to forward request to
the instance of the real class...

-=Chris

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to