Created
April 14, 2015 17:48
-
-
Save jbarrett/e568195bbb6fe5aec9ae to your computer and use it in GitHub Desktop.
Dancer2::Plugin::RootURIFor prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Dancer2::Plugin::RootURIFor; | |
use strict; | |
use warnings; | |
my $VERSION = 0; | |
use URI::Escape; | |
use Dancer2::Plugin; | |
# See Dancer2::Core::Request::uri_for | |
register root_uri_for => sub { | |
my ( $dsl, $part, $params, $dont_escape ) = @_; | |
my $request = $dsl->app->request; | |
my $uri = $request->base; | |
$part =~ s{^/*}{/}; | |
$uri->path("$part"); | |
$uri->query_form($params) if $params; | |
return $dont_escape | |
? uri_unescape( ${ $uri->canonical } ) | |
: ${ $uri->canonical }; | |
}; | |
register_plugin; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment