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


In reply to Re^5: Why is mojolicious "routing to a callback" ? by Anonymous Monk
in thread Why is mojolicious "routing to a callback" ? by pcouderc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.