ok, so basically I understand that Catalyst::Model::Adaptor is used to plug in a non-Catalyst module as a model in my Catalyst App. What I'm not so clear about is why it should be done in this way as opposed to just requiring the external module in the controller and using it directly.
For example, the book "Catalyst: Accelerating Perl Web Application Development..." shows in chapter 6 how to build a Filesystem-based model which is just a normal Perl module that is then integrated into the Catalyst App using Catalyst::Model::Adaptor.
But: what do I actually gain from that? Suppose I have a class NonCatalyst::MyClass, in the controller I could just do:
use NonCatalyst::MyClass; sub action :Local { my ( $self, $c ) = @_; $c->stash->{result} = NonCatalyst::MyClass->do_stuff($c->request->pa +rams->{some_param}; }
as opposed to
sub action :Local { my ( $self, $c ) = @_; $c->stash->{result} = $c->model('MyClass')->do_stuff($c->request->pa +rams->{some_param}; }
I would just like to understand it properly before using it. Thanks for any enlightenment you can provide...
Update OK, so after this discussion and a bit more reading I think I have a better understanding of this now.
I think it's fair to say that if the external class does not require any arguments for its constructor then the difference between using it directly and using it via an Adaptor is minimal. However, if some configuration of the external class is required, e.g. a base directory or something like that, then you gain a nice way of adding those constructor arguments to the Catalyst main configuration file if you use an Adaptor.
My main misunderstanding was that this would change the way in which the class is instantiated, thus interfering with it's use from other scripts or GUIs. That's not the case, so the class is not tightly bound to Catalyst at all, even when using the Adaptor.
In reply to Trying to understand Catalyst::Model::Adaptor by tospo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |