Hello, 

I want to implement something really simple : log some events into a
database. And I already can think of three way to do it, but because
this will be used very frequently I'd like to know what's the best
solution. For me the best solution would be to have little overhead, and
a really short command (like $c->logdb()).

1/ In the DBIC Model
--------------------
package MyApp::Model::AppDB

sub add() {
  my $self = shift;
  my $message = shift;

  my $log  = $self->resultset('Log');
  $log->create( { 
    message => $message 
  });
}

And then call $c->model('AppDB')->add('Hello World');

This seems ok, but $c->model('AppDB')->add('Hello World') ... too much
characters.

2/ In the controller
--------------------
(in Root.pm)
sub log : Private {
  my ($self, $c, $message) = @_;
  $c->model('AppDB::Log')->create({
    message => $message;
  });
}

And then call $c->forward('/log', [ 'Hello World' ]);

This doesn't seem really elegant to me.

3/ As a plugin

This seems really overkill, but I like the idea of having a really short
command like $c->logdb(...);

So could someone tell be what is best practice is ? 

Thanks.

Yves.


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

Reply via email to