Search code examples
perlmojolicious

Perl Mojolicious stash dump


How do I dump out the stash in perl

my $my_data =  {
    'me'    =>  {
        'admin' => 'rhaen',
        'desc'  => 'webserver'
    },
    'you' => {
        'admin' => 'hazel',
        'desc'  => 'mailserver'
    }
};
stash(mydata => $my_data);
print Dumper (stash 'mydata');

How do I print mydata me admin. I have tried print Dumper (stash 'mydata me'); print Dumper (stash 'mydata'=>['me']); Nothing seems to work. Trying to troubleshoot why data is changing.


Solution

  • I tried the following in Mojolicious::Lite:

    get '/' => sub {
        my $c = shift;
        $c->stash(mydata => $my_data);
        use Data::Dumper; print Dumper($c->stash('mydata')->{me}{admin});
    };
    

    The output was

    $VAR1 = 'rhaen';