Use reserved words such as colons (:) in URLs
Mojolicious routers are very convenient because you can make detailed settings. However, when I try to use it, : , # , * and . are reserved words. You will notice.
If I want to use these symbols in the URL, I have no choice but to give up (except because # has a meaning as a fragment in the URL). Parameters cannot be acquired correctly with the following specifications.
#Wrong (/20101114: I can't get the parameters correctly in main) get'/ (: date): (: id)' => sub { my $self = shift; my $date = $self->param('date'); my $id = $self->param('id'); $self->render(text => "$date $id"); };;
Since the colon is a reserved word, specifying a route like this doesn't work.
Use regular expression constraints as a solution
However, Mojolicious routers are so flexible that you can combine regular routers with regular expressions.
In other words, if you write a part that includes reserved words with a regular expression, it will not be neat, but it can be solved.
#Correct (You can get the parameters correctly with / 20101114: main) get'/: date_id'=> [date_id => qr / [^:] +?: [^:] + /] => sub { my $self = shift; my $date_id = $self->param('date_id'); my ($date, $id) = $date_id = ~ / ([^:] +?) :( [^:] +) /; $self->render(text => "$date $id"); };;
I've named the placeholder $data_id and used a regular expression to describe the constraint. You have written a route that matches / 20101114: main .
All you have to do now is split it using the same regular expression.