File: myapp2.pl

package info (click to toggle)
libmojolicious-perl 8.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,720 kB
  • sloc: perl: 12,099; makefile: 14
file content (36 lines) | stat: -rw-r--r-- 759 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env perl

use Mojolicious::Lite;
use Mojo::IOLoop;

# Default for config file tests
app->defaults(secret => 'Insecure too!');

# Helpers sharing the same name in different embedded applications
helper same_name => sub {'myapp2'};

# Caching helper for state variable test
helper my_cache => sub { state $cache = shift->param('cache') };

# Delay dispatching
hook around_dispatch => sub {
  my ($next, $c) = @_;
  Mojo::IOLoop->next_tick(sub { $next->() });
};

get '/' => sub {
  my $c = shift;
  $c->render(text => $c->render_to_string('menubar') . app->defaults->{secret});
};

get '/cached' => sub {
  my $c = shift;
  $c->render(text => $c->my_cache);
};

app->start;
__DATA__

@@ menubar.html.ep
%= same_name
%= stash('message') || 'works 4!'