[dancer-users] Migrating from dancer to dancer2

Sawyer X xsawyerx at gmail.com
Sun Apr 19 12:54:01 BST 2015


Hi Alfonso,

I hope it's not too late to reply to this.

On mounted paths, Plack::App::URLMap plays with PATH_INFO to remove
the mounted path. However, it's still available in SCRIPT_NAME, so you
can get it from there. A combination of the both gives you the full
path, including mounting point.

Hope it helps,
Sawyer. :)

On Wed, Apr 1, 2015 at 4:27 PM, Alfonso Pinto <alfonso.pinto at gmail.com> wrote:
> 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
> this:
>
> 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
> request->base.
>
> 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:
> stats.api./app1/:userid.GET
>
> 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.
> Alfonso
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users


More information about the dancer-users mailing list