perlmason

Get the request URL in HTML::Mason


How we can find the GET request URL in a perl website using HTML::Mason. I have tried using $m object from Mason.


Solution

  • In addition to the $m Mason request object you also have $r the Apache request object. The uri method will return the path component of the requested URL:

    my $url = $r->uri;
    

    You can read more in the Mason Developer's Manual.

    If you want the requested URL including the query string, you can use the unparsed_uri method:

    my $url_with_qs = $r->unparsed_uri;
    

    You can read more in the mod_perl documentation for Apache2::RequestRec.