[Dancer-users] Modular approach without anonymous subrefs

David Cantrell david at cantrell.org.uk
Tue Sep 25 16:34:57 CEST 2012


On Mon, Sep 24, 2012 at 02:24:31PM +0100, Alex C wrote:
> On 23 September 2012 01:27, gvim <gvimrc at gmail.com> wrote:
> > I'm converting a CGI::Application web app to Dancer and have always used a
> > modular approach so am I missing something if I prefer to do it this way:
> I think this is a very nice technique. My Routes.pm is growing to
> 3000 lines and I think I will refactor it using this same technique
> you have suggested.

The one change I'd suggest is that instead of having things like this
...

get   '/register'     => \&Register::run;

do this:

get '/register' => sub {
    # stuff to extract parameters from Dancer
    Register::run(
        named_param1 => ...
	named_param2 => ...
    )
}

as this make it quite a bit easier to test your routes' code in
isolation*.  The ideal that I'm working towards (very slowly) at work is
for those modules to have no Dancer-specific code in them at all.  I'm
still trying to figure out a nice way of coping with routes which can
return failure (eg HTTP codes for "forbidden") without lots of code
duplication in each route, but I've not thought that hard about it yet.

Dancer is great at route creation and dispatch, session management etc -
the web-specific bits of an app.  But that's *all* it's good at (which is
a good thing).  I want to keep it the hell out of my application code!

* I worship Christ the Unit Tester, which, with a bit of trickery, has
  a very rude abbreviation

-- 
David Cantrell | Official London Perl Mongers Bad Influence

What plaything can you offer me today?


More information about the Dancer-users mailing list