in reply to Re^6: Trying to understand Catalyst::Model::Adaptor
in thread Trying to understand Catalyst::Model::Adaptor
Me personally? Nope :) Generally the only case I'd agree it would be best to skip the model is the case where the code will only ever be used once in a single Controller. Forever and ever. I could see that sort of functionality being in several Controllers and methods (though if you do write something like that use Path::Class::File->new(path)->slurp or something similar instead of invoking shell commands). These lines-
use NonCatalyst::FileCat; my $fc = NonCatalyst::FileCat->new($c->config->{file_directory}); my $file_name = $c->request->params->{file}; $c->stash->{result} = $fc->cat($file_name);
-become-
$c->stash->{result} = $c->model("FileCat")->cat($c->request->params- +>{file});
Granted you have cost yourself up front with setting up the adaptor and configuration for the model. But it really is trivial effort and it allows you to change the file_directory in config related to the functionality -- Model::FileCat -> file_directory: /some/place -- instead of in the "global" app config. Theoretical win but better namespacing nevertheless.
I'm not trying to preach; thinking in MVC instead of scriptese is a really good way to save yourself misery over time. I wish someone had hit me with this particular cluebat much earlier. Your own use case and preference matters, of course. Do what thou wilt.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Trying to understand Catalyst::Model::Adaptor
by tospo (Hermit) on Apr 08, 2010 at 08:48 UTC | |
by Your Mother (Archbishop) on Apr 08, 2010 at 23:17 UTC |