in reply to Re: first steps with Mojolicious::Lite
in thread first steps with Mojolicious::Lite
it is not exactly the cleaner replication of mine: infact i suspect that you used the client I proposed in the original post, and if so, the client does not send username and password in the second request because it received back a valid cookie. You never get ove il mio corpo fanciulletto giacque, printed. My get_second only checks this cookie, not credentials. The third request made by the client was there only to check the cookie corectly expired, so it has to fail. But these are details and your code is clean and a good example to show.
About under : it shows to be a powerful tecnique but, if I'm permitted, even too much. I mean: the code will result shorter and cleaner and very DRY, but imagine what happens if you have two or three screenful of routes: then after one month you get back at the code to review route_105 which is affected by under one but you dont see it.. Is the typical situation I will hate, like a no warnings put in the middle of a long code, with global effect..
So I'd probably go for something like (DRY code at the cost of WET comments.. ;)
# see UNDER above get 'get_first' => sub { my $c = shift; return $c->render(text => $text_a); }; # see UNDER above get 'get_second' => sub { my $c = shift; return $c->render(text => $text_b); };
Or put them in a group like shown in the tutorial:
# Admin section group { # Local logic shared only by routes in this group under '/admin' => sub { my $c = shift; return 1 if $c->req->headers->header('X-Awesome'); $c->render(text => "You're not awesome enough."); return undef; }; # GET /admin/dashboard get '/dashboard' => {text => 'Nothing to see here yet.'}; };
But the last example raise another question in my mind: why the comment # GET /admin/dashboard ?? Is not /dashboard the route defined? Or... under means: all routes logically under the specified one ( like in under '/admin' ) and, if not specified logically under the root like under '/'?
If the above assumption is correct I'd really like to know where it is explained.
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: first steps with Mojolicious::Lite -- under again
by Anonymous Monk on Jun 17, 2020 at 07:59 UTC |