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

  • SEARCH
  • Home
  • 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 7505115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:48:05+00:00 2026-05-29T21:48:05+00:00

In a Mojolicious app I have a route in my Controller code like the

  • 0

In a Mojolicious app I have a route in my Controller code like the following:

/account/:id/users

The /account/:id part of the route has the following data in it when I get to the
users part of the chain:

$VAR1 = { 
    'signup_ip' => '172.17.5.146', 
    'z_id' => '382C58D8-529E-11E1-BDFB-A44585CCC763', 
    'signup_date' => '2012-03-12T12:11:10Z', 
    'name' => 'Some Cool Account Name', 
    'users' => [ 
        { 
            'user_id' => '382C67EC-529E-11E1-BDFB-A44585CCC763' 
        } 
    ], 
    'account_id' => '382C67EC-529E-11E1-BDFB-A44585CCC763',
}; 

In the users part of the chain I’m getting the above hash using
$self->tx->res->content->get_body_chunk(0)

sub users { 
    my $self = shift; 
    my $user_list = from_json( $self->tx->res->content->get_body_chunk(0) );    
    $self->respond_to( json => $user_list->{users} );
} 

The problem I’m having is that I want to overwrite the response with only
the users arrayref. The code above in sub users(){} doesn’t do that. That is,
when I dump the result in the test, I still getting the entire hash.
The $user_list is the arrayref I’m looking for in users() but I’m unable to overwrite it.

Anyone have an idea how to do that?

  • 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-05-29T21:48:06+00:00Added an answer on May 29, 2026 at 9:48 pm

    Hrm I think I put my previous answer in the wrong place. So here it is:

    In the application I added the following routes:

    my $base = $r->bridge('/account/:id')->to('account#read');
    $base->route('/')->via('get')->to('account#index');
    $base->route('/users')->via('get')->to('account#users');
    

    In Acount.pm

    sub read {
        my $self = shift;
        # do stuff
    
        $self->stash->{account} = $data;   # set the stash
    
        return 1;     #return 1.  Don't render.
    }
    
    sub index {
        my $self = shift;
        my $data = $self->stash('account');  #get the stash 
    
         $self->render_json( $data );
    }
    
    sub users {
        my $self = shift;
        # do stuff
    
        my $data = $self->stash('account');
        $self->render_json( $data );
    }
    

    Doing this sets the result of /account/:id into the stash in the read sub.
    Setting a route to $base->route(‘/’)->via(‘get’)->to(‘account#index’);
    causes calls to /account/:id to be rendered from the index sub.

    The route $base->route(‘/users’)->via(‘get’)->to(‘account#users’) causes
    the calls to /account/:id/users to be rendered from the users sub.

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

Sidebar

Related Questions

I’d like to match any GET request in Mojolicious::Lite. The code looks like this:
We have created the following simple Mojolicious controller: package SampleApp::Pages; # $Id$ use strict;
I use the mojolicious framework to write Web-App. Mojo::Base has a nice feature to
I setup a quick Mojolicious server like this: use Mojolicious::Lite; get '/' => sub
In my Mojolicious perl code I handle a jobs created and watched from a
I am currently working on a Mojolicious app using TDD on my Mac and
I have some Mojolicious-based apps which happily run under Apache2 with mod_cgi and mod_fastcgi.
#!/usr/local/bin/perl use warnings; use 5.014; use Mojolicious::Lite; use DBI; # ... get '/choose' =>
I am using Rose::DB::Object , SQLite , and Chinese text. My classes look like
Does mojolicious working under the lighttpd web-server? How to cofigure? Does I need setup

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.