[Catalyst] best practices - model or controller ?

Tobias Kremer list at funkreich.de
Sat Oct 4 09:27:19 BST 2008

On 04.10.2008, at 08:16, Yves Räber wrote:
> 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()).

When deciding where to put things (model vs. controller) I always  
imagine what would happen if I took the Catalyst part away. In most  
cases the model should be able to fulfill everything without Catalyst  
being involved (for instance, if you'd like to use your model from a  
cronjob script). Thus, in this case, I'd definitely put the logging  
into the model to have it log everything even when Catalyst is not  
involved. I assume that every logging action goes together with a  
create/update/delete of model objects and is rarely triggered alone.  
If that's the case, have you thought about overriding the create,  
update, delete methods DBIC provides to add the logging there? That  
way you'd have to do it only once and every (write) action on your  
model is automatically logged.


More information about the Catalyst mailing list