http://qs1969.pair.com?node_id=11131488

rajaman has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

How can I do the following in the pseudocode below:

1. the URL '/user/1' should dynamically point and rewrite to '/user/John-H' in the browser address bar and in link mouseover on the page. I have mapped id to value in the 'users' cache.
2. the URL (with a trailing slash) '/user/1/' should dynamically point and rewrite to '/user/John-H'
3. restrict the value of id to be an even number and less than 10.

Thank you!

#!/usr/bin/env perl use Mojolicious::Lite my $users = Mojo::Cache->new(max_keys => 50); $users->set(1 => 'John H'); $users->set(2 => 'Sam A'); #my $user = $users->get('1'); get '/user/:id' => [id => qr/\d+/] => sub ($c) { $c->render(text => $users{$id}); }; app->start;