Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dancer2::Plugin::RootURIFor prototype
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