Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Dancer2 get the raw uri

by perl_help27 (Acolyte)
on Mar 01, 2018 at 20:26 UTC ( #1210186=perlquestion: print w/replies, xml ) Need Help??

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


    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.


      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. :)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1210186]
Approved by haukex
Front-paged by Corion
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2023-12-03 11:42 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (20 votes). Check out past polls.