Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Inconsistent results trying to use parameters in prefix #966

sapphirecat opened this Issue Oct 4, 2013 · 1 comment


None yet
2 participants

sapphirecat commented Oct 4, 2013

Starting from Dancer 1.3118 and running dancer -a foo, then writing in foo/lib/foo.pm:

prefix '/:client' => sub {
    get '/' => sub {
        template 'index';
    get '/tickets' => sub {
        template 'index';

The second route can be reached via /MegaCorp/tickets but the first cannot be reached via /MegaCorp--in fact, it is only reachable by /:client; otherwise a 404 is generated because this fails to get the route:

[5014]  core @0.000516> [hit #4]Trying to match 'GET /MegaCorp' against /(?-xism:^(?-xism:^\/\:client(?:\/)?$)$)/ (generated from '(?-xism:^\/\:client(?:\/)?$)') in /usr/local/share/perl5/Dancer/Route.pm l. 84

It looks like this happens because Dancer::Route::_init_prefix wants to match the "/" pattern with or without the trailing slash, builds a regexp to do so, and sets it; later, _build_regexp sees that it already has a regexp, sets it as the compiled regexp, and does not actually parse the parameters from the string. When a pattern isn't "/", then a non-regexp route will end up in _build_regexp_from_string, which is called with the concatenation of prefix and pattern, and thus parses parameters anywhere in the string.

I haven't been able to find in the documentation any explicit confirmation/denial of whether the prefix is intended to be capable of holding parameters.


yanick commented Oct 5, 2013

At the moment the prefix can only be a string. I must say, though, it would be quite handy if it could hold parameters or be a regex, just like the regular route argument. Hmmm.... I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment