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

Hello, I have a Dancer2 app with this psuedo code:
#### Dancer app content get '/dosmth/:smth' => sub { #some code} hook after => sub { print "URI".request->uri; #This is printing /dosmth/123 and I want to +print /dosmth/:smth/ } ###test script $t->request(GET "/dosmth/123"); #where i issue the request
My problem is that in the hook after, I am getting the uri /dosmth/123 but I am interested in the raw path /dosmth/:smth. I printed the whole request and there is nothing inside of it indicative of my needs (no route inside). Any idea how to solve this? Thanks

Replies are listed 'Best First'.
Re: Dancer2 get the raw uri
by Discipulus (Canon) on Mar 01, 2018 at 21:19 UTC
    Hello perl_help27 and welcome to the monastery and to the wonderful world of Perl!

    I'm not an expert but as far i understand :smt it's not at all a part of the request: it's a part of the route definition. It says that something following /dosmth/ wil be interpreted as the value of the smth param.

    ps they are called tokens: see named matching

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Dancer2 get the raw uri
by Mr. Muskrat (Canon) on Mar 01, 2018 at 21:20 UTC

    I'd like to tell you to use request->route because it's documented in Dancer2::Core::Request; however, that method doesn't actually exist.

      however, that method doesn't actually exist.

      Hi,

      It exists if you upgrade your Dancer2

      sub route { $_[0]->{'route'} }
        This was it!! Thanks a lot!!

        Thanks. I guess it's time for me to upgrade too. :)