PerlDancer/Dancer2 — Issue #33: make uri_for receive a name for a route
Author: tmueller
Created: 2012-01-26 23:20:17+00:00
State: open

This is something for the wishlist, not an issue itself.

Right now uri_for converts a relative path to an absolute path and attaches parameters if necessary.

In case you have to change a path in your controller, you have to search all your templates, to find where this path was used and change your templates accordingly.

My idea would be to provide a name for a route and use that name to identify the route to generate a uri. Something along the lines:

# in the controller
get '/product/:id' as 'product' => sub { ... }

# OR
get '/product/:id' called 'product' => sub { ... }

# meanwhile in the template ...
...
...

# ... becomes
...
...

The Benefit would be, that we can change the route in our controller without having to search our templates for where this route was used. Like so:

# in the controller
get '/product/:id/:special_price?' as 'product' => sub { ... }

# no change in the template is required, but now ...
...

# ... would yield
...

The idea is, to decouple the uris in templates from routing in the controller, so that you are more flexible to change your routes. And to make uri generation more comfortable.