[Catalyst] best practices - model or controller ?

Eden Cardim edencardim at gmail.com
Sat Oct 4 14:20:50 BST 2008


On Sat, Oct 4, 2008 at 9:31 AM, Peter Karman <peter at peknet.com> wrote:
> You don't need a real plugin unless you need to override the dispatch process.
> But I often put convenience methods in my MyApp.pm base class. So implement your
> idea #1 and then add:
>
> package MyApp;
>
> sub logdb {
>    my $c = shift;
>    my $msg = shift or croak "msg required";
>    $c->model('AppDB')->add($msg);
> }

I would set up a config key for the model to make things flexible:

sub log_model {
  my($c) = @_;
  return $c->model($c->config->{log_model});
};

sub logdb {
   my $c = shift;
   my $msg = shift or croak "msg required";
   $c->log_model->add($msg);
}

you can do this with controllers too, if you decide you need different
models per controller

-- 
edenc.vox.com



More information about the Catalyst mailing list