http://qs321.pair.com?node_id=1177718

Dallaylaen has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear esteemed monks,

After announcing my toy web framework to a local Perl mongers group, I received a request from fellow monger to add filters. He was citing sinatra.rb as reference. I promptly found both Mojolicious and Dancer to have similar functionality called hooks. Apache/mod_perl allows to hook into different stages of request processing as well, and I was planning to do something like that as well.

So I set myself on a quest to add hooks. However, the very first attempts turned out to be utterly over-engineered (almost everything I do is, see Implementing methods in a subclass or providing in-place callback: Is it overengineered?). It's easy to make a mistake, and it would be hard to correct it later.

Some background: the framework goes as follows:

use strict; use warnings; use MVC::Neaf; MVC::Neaf->route( '/some/uri/path' => sub { my $request = shift; # ... query request object for params, cookies, etc # a valid way to return configurable error page die 403 if $perm_denied; # result will be fed to View's render() method # the user-agent will get a 200 page with some headers # and rendered content return \%hash; }, view => 'TT'); # more handlers MVC::Neaf->run; # end of the application (as in PSGI or Dancer)

What I clearly want:

What I'm unsure about:

So before I proceed to answering these questions I would like to ask for example usage of this feature. Here's what I can think of:

What else did you encounter / think about doing via such hooks in real-life applications? Thank you.