Skip to content

Instantly share code, notes, and snippets.

@jbarrett
Created April 14, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarrett/e568195bbb6fe5aec9ae to your computer and use it in GitHub Desktop.
Save jbarrett/e568195bbb6fe5aec9ae to your computer and use it in GitHub Desktop.
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