Web::Request::Role::AbsoluteUriFor - Construct an absolute URI honoring script_name
version 1.004
# Create a request handler package My::App::Request; use Moose; extends 'Web::Request'; with 'Web::Request::Role::AbsoluteUriFor'; # Make sure your app uses your request handler, e.g. using OX: package My::App::OX; sub request_class {'My::App::Request'} # in some controller action: # redirect $req->absolute_uri_for({ controller=>'foo', action=>'bar' }); # https://yoursite.com/mountpoint/foo/bar # don't use the base-uri from $req by passing an explit additional value $req->absolute_uri_for({ controller=>'foo', action=>'bar' }, 'https://example.com'); # https://example.com/mountpoint/foo/bar
Web::Request::Role::AbsoluteUriFor provides a method to calculate the absolute URI of a given controller/action, including the host name and handling various issues with SCRIPTNAME and reverse proxies.
Web::Request::Role::AbsoluteUriFor
SCRIPTNAME
$req->absolute_uri_for( '/some/path' ); $req->absolute_uri_for( $ref_uri_for ); $req->absolute_uri_for( '/some/path', $base-url );
Construct an absolute URI out of base_uri, script_name and the passed in string. You can also pass a ref, which will be resolved by calling uri_for on the request object.
base_uri
script_name
uri_for
If you pass a second argument, this value will be used as the base-uri instead of extracting it from the request. This can make sense when you for exampel host a white lable service and need to generate different links based on some value inside your app.
Thanks to
validad.com for supporting Open Source.
Thomas Klausner <domm@plix.at>
This software is copyright (c) 2017 - 2021 by Thomas Klausner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Web::Request::Role::AbsoluteUriFor, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::Request::Role::AbsoluteUriFor
CPAN shell
perl -MCPAN -e shell install Web::Request::Role::AbsoluteUriFor
For more information on module installation, please visit the detailed CPAN module installation guide.