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

John Napiorkowski jjn1056 at yahoo.com
Wed Oct 10 15:03:42 GMT 2007


--- 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.

--john


> > _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo:
>
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 



      ____________________________________________________________________________________
Shape Yahoo! in your own image.  Join our Network Research Panel today!   http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 





More information about the Catalyst mailing list