in reply to Re^4: Why is mojolicious "routing to a callback" ?
in thread Why is mojolicious "routing to a callback" ?

Mm, no sorry, I do not know why you refer to MyApp. My application is Myapp. I am on linux which is case sensitive. Sorry, my problem is not so simple...

Can you guess why I refer to MyApp?

That is the default name for a new app -- thats me trying to complete/reproduce the problem, trying to do step 1 for you ( make it short and reproducible )

anyway, hint from ctilmes is spot on
https://metacpan.org/pod/Mojolicious::Guides::Growing#Simplified-application-class
https://metacpan.org/pod/Mojolicious::Routes::Route#under
https://metacpan.org/pod/Mojolicious::Guides::Tutorial#Under
https://metacpan.org/pod/Mojolicious::Guides::Routing#Under
https://metacpan.org/pod/Mojolicious::Routes::Route#name

I consider Routing to a callback a bug (in Mojolicious 6.14) since it could do something useful like mention a file and line number ; Maybe the latest version of Mojolicious 6.33 does this

Nope, it still only says "Routing to a callback" in Mojolicious 6.33 , even if you give it a name, thats two bugs :D

So here it is , self contained , based on doc example

#!/usr/bin/perl -- use Mojolicious::Lite; app->routes->under(sub{ my( $c ) = @_; return defined($c->session('userid')) })->get ( '/breaky' => 'index' ); app->routes->under(sub{ my( $c ) = @_; return defined($c->session('userid')) })->name('achey')->get ( '/breakyname' => 'index' ); # Authenticate based on name parameter under sub { my $c = shift; # Authenticated my $name = $c->param('name') || ''; return 1 if $name eq 'Bender'; # Not authenticated $c->render(template => 'denied'); return undef; }; # Only reached when authenticated get '/' => 'index'; app->start; __DATA__ @@ denied.html.ep You are not Bender, permission denied. @@ index.html.ep Hi Bender.

This is how it runs, first the working version from docs, then the breaky version

$ perl mojo-under-breaky.pl get / [Wed Nov 25 14:53:52 2015] [debug] GET "/" [Wed Nov 25 14:53:52 2015] [debug] Routing to a callback [Wed Nov 25 14:53:52 2015] [debug] Rendering template "denied.html.ep" + from DATA section [Wed Nov 25 14:53:52 2015] [debug] 200 OK (0.004443s, 225.073/s) You are not Bender, permission denied. $ perl mojo-under-breaky.pl get /?name=Bender [Wed Nov 25 14:54:17 2015] [debug] GET "/" [Wed Nov 25 14:54:17 2015] [debug] Routing to a callback [Wed Nov 25 14:54:17 2015] [debug] Rendering template "index.html.ep" +from DATA section [Wed Nov 25 14:54:17 2015] [debug] 200 OK (0.004540s, 220.264/s) Hi Bender. $ perl mojo-under-breaky.pl get /breaky [Wed Nov 25 14:55:33 2015] [debug] GET "/breaky" [Wed Nov 25 14:55:33 2015] [debug] Routing to a callback [Wed Nov 25 14:55:33 2015] [debug] Your secret passphrase needs to be +changed [Wed Nov 25 14:55:33 2015] [debug] Nothing has been rendered, expectin +g delayed response [Wed Nov 25 14:55:48 2015] [debug] Inactivity timeout Problem loading URL "http://127.0.0.1:2556/breaky": Premature connecti +on close $ perl mojo-under-breaky.pl get /breakyname [Wed Nov 25 14:56:45 2015] [debug] GET "/breakyname" [Wed Nov 25 14:56:45 2015] [debug] Routing to a callback [Wed Nov 25 14:56:45 2015] [debug] Your secret passphrase needs to be +changed [Wed Nov 25 14:56:45 2015] [debug] Nothing has been rendered, expectin +g delayed response [Wed Nov 25 14:57:00 2015] [debug] Inactivity timeout Problem loading URL "http://127.0.0.1:2565/breakyname": Premature conn +ection close

You see, you can't just return true or false from under, you have to render something or redirect somewhere

Replies are listed 'Best First'.
Re^6: Why is mojolicious "routing to a callback" ?
by pcouderc (Monk) on Nov 26, 2015 at 20:21 UTC
    Yes, particularly I missed https://metacpan.org/pod/Mojolicious::Guides::Growing#Simplified-application-class
    All is there.
    Thank you very much.
    PC
Re^6: Why is mojolicious "routing to a callback" ?
by pcouderc (Monk) on Nov 26, 2015 at 07:43 UTC
    Thank you very much! I study that.
    PC
Re^6: Why is mojolicious "routing to a callback" ?
by pcouderc (Monk) on Nov 26, 2015 at 11:35 UTC
    I thank you very much. You show how to reproduce my mistake under self contained minimal mojolicious example.
    But I know how to do under Mojolicious::Lite (just follow the example of the doc).
    My problem seems to me my failure to expand the exmple to "full" Mojolicious.
    ...But maybe, I am wrong myself about my mistake!