[Dancer-users] prefix + uri_for - not working

Assaf Gordon gordon at cshl.edu
Fri Dec 16 18:07:13 CET 2011


Hi,

I'm using uri_for()/uri_base() in my code, and I've noticed sadly that they ignore the "prefix" settings.
While changing this in Dancer1 will wreak havoc :), perhaps this can be improved in Dancer2 ?

Simple Example:
======
package uri_for_test;
use Dancer ':syntax';

our $VERSION = '0.1';

get '/' => sub {
    my $url_base = request->uri_base;
    my $url = request->uri_for("/verify");
    print STDERR "URL = $url\n";
    print STDERR "URL-BASE = $url_base\n";
    template 'index';
};

true;
======

Running it (with ./bin/app.pl) prints (as expected):
======
>> Dancer 1.3090 server 28846 listening on http://0.0.0.0:3000
== Entering the development dance floor ...
URL-BASE = http://localhost:3000
URL = http://localhost:3000/verify
======

Then, adding just the "prefix" statement before the "get":
===
prefix "/foo" ;
===

Makes the application respond to "http://localhost:3000/foo", but the printed output is still:
===
URL-BASE = http://localhost:3000
URL = http://localhost:3000/verify
===

Whereas I would expect it to be:
===
URL-BASE = http://localhost:3000/foo
URL = http://localhost:3000/foo/verify
===

This makes the "prefix" statement only partially useful, because changing prefix of an entire application/module still requires manually changing all the "uri_for/uri_base" calls.

Regards,
 -gordon


More information about the Dancer-users mailing list