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.


In reply to Cool uses for Dancer/Mojo hooks by Dallaylaen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.