[dancer-users] Migrating from dancer to dancer2

Alfonso Pinto alfonso.pinto at gmail.com
Wed Apr 1 15:27:28 BST 2015

Dear all,

I'm in the process of migrating and cleaning an app using dancer to dancer2

I've almost everything working and covered, including splitting the
big monolithic app into several dancer2 apps using Plack::Builder like

return builder {
    mount '/app1' => My::App1->to_app;
    mount '/app2' => My::App2->to_app;

The only problem I'm not able to solve is this one:

# HOOKS (executed BEFORE and AFTER each route)
hook before => sub {
    $memd->incr( "stats.api." . request->{_route_pattern} . "." .
request->{method} );

hook after => sub {
    my $response = shift;
    $memd->incr( "stats.api." . request->{_route_pattern} . "." .
request->{method} . "." . $response->status );

We use hooks to store some statistics in memcached. The problem is
that I can't find a way to substitute request->{_route_pattern} to get
the route handler used
For the method I found I can use request->method and, as I'm mounting
the app using Plack::Builder, I can get the base of the url with

The idea is, having a request like this:
GET http://localhost:3000/app1/123456

and a route handler like:
get ':userid' => sub {...}

we should increment the value of this key in memcached:

so, my question is how to get the '/:userid' part in the hook to
compose the key I need to increment in memcached.

Thanks in advance and regards.

More information about the dancer-users mailing list