[Catalyst] Catalyst::Model::Adaptor - because models shouldn't *do* anything

Matt S Trout dbix-class at trout.me.uk
Thu Oct 11 21:07:25 GMT 2007


On Wed, Oct 10, 2007 at 07:03:42AM -0700, John Napiorkowski wrote:
> 
> --- Jonathan Rockway <jon at jrock.us> wrote:
> 
> > John Napiorkowski wrote:
> > > One thing that I've done a lot with these kinds of
> > > adapters is use AUTOLOAD or use Moose's built in
> > > attribute delegation to make calling the adapted
> > > classes methods easier.  Would you take a patch
> > for
> > > something like this and how might you envision it
> > > working.  As a plugin, for example?
> > >   
> > 
> > If your model is:
> > 
> >    package MyApp::Model::Foo;
> >    use base 'Catalyst::Model::Adaptor';
> >    __PACKAGE__->config( class => 'YourClass' );
> > 
> > Then, in
> > 
> >   my $yourclass = $c->model('Foo')
> > 
> > ref $yourclass is YourClass, not MyApp::Model::Foo. 
> > Whatever
> > YourClass->new returns is what $c->model returns.
> > 
> > So, adding anything to Model::Adaptor or a subclass
> > of it would be
> > pointless, since there's no way you can get at those
> > methods.  (You
> > could get them at COMPONENT time, but not after
> > that.)
> > 
> > Let me know if this is what you were talking about.
> > 
> > Regards,
> > Jonathan Rockway
> 
> This is exactly what I was thinking about, since it
> negates the need for using AUTOLOAD to delegate method
> calls to the model back to the wrapped class.  I think
> your approach is better since AUTOLOAD has a
> performance penalty.
> 
> The other thing I was thinking is that Moose
> Attributes have this great feature that allows you to
> easily delegate methods to a composed class.  I was
> thinking something like this could be nice here, but
> maybe it would be best to just use Moose for this in
> the first place, rather than try to reinvent it.

There's no -need- for delegation.

The adaptor's COMPONENT method returns an object of the -actual- class, no
the adaptor itself.

So $c->model returns a Whatever::Class object, not a Catalyst::Model::Adaptor
object.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list