Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:44:04+00:00 2026-06-12T21:44:04+00:00

I am looking for a clean and simple example of how to use the

  • 0

I am looking for a clean and simple example of how to use the “under” functionality in a “Mojolicious” application. All the examples I find are dealing with “Mojolicious::Lite” (which I don’t use).
For example I listened to the screencast here http://mojocasts.com/e3 and I think I understand the concept of the under functionality. But I don’t use “Mojolicious::Lite”, so it seems that I can’t follow the example directly. I keep on failing trying to adopt the Lite-example for non-Lite style. (That’s probably also because I’m still kind of new to the framework)

The relevant code looks like this:

# Router
my $r = $self->routes;

# Normal route to controller
$r->get('/') ->to('x#a');
$r->get('/y')->to('y#b');
$r->any('/z')->to('z#c');

So all of this routes need to be protected by user/pass. I tried to do something like this:

$r->under = sub { return 1 if ($auth) };

But this does not compile and I just can’t find an example matching this code-style…
Can anybody give me the right hint or link here?
And please forgive me if this is somewhere in the docs… they might be complete, but they lack understandable examples for simple minded guys like me 😛

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:44:05+00:00Added an answer on June 12, 2026 at 9:44 pm

    The analogous code to the Lite-examples looks like this:

    # Router
    my $r = $self->routes;
    
    # This route is public
    $r->any('/login')->to('login#form');
    
    # this sub does the auth-stuff
    # you can use stuff like: $self->param('password')
    # to check user/pw and return true if fine
    my $auth = $r->under( sub { return 1 } );
    
    # This routes are protected
    $auth->get ('/') ->to('x#a');
    $auth->post('/y')->to('y#b');
    $auth->any ('/z')->to('z#c');
    

    Hopes this helps anybody!

    (Solution found here: http://mojolicio.us/perldoc/Mojolicious/Routes/Route#under)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am specifically looking for an example which use a) WCF & REST. After
I'm looking for a clean, simple way to update class-level dictionaries, which are inherited
I'm looking for (simple) examples of problems for which JMS is a good solution,
I have been looking around for hours trying to find a clear simple solution
I am looking for a clean vanilla example of the play framework with ajax.
I am looking for a clean way to combine variables into a single string
I am looking for a clean way to check if a registry key exists.
I'm looking for a clean way to import one git repository from another, where
I'm looking for a clean C++ idiom for the following situation: class SomeLibraryClass {
I've been looking at a clean way of implementing shut down logic for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.