codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#!/usr/bin/env perl use Mojolicious::Lite; app -> helper ('get_title', sub { my ($c, $dom) = @_; return $dom -> at ('title') -> text; }); app -> helper ('async_title', sub { my ($c, $cb) = @_; $c -> ua -> get ('http://mojolicio.us', $cb); }); get '/' => sub { my $c = shift; my $cb = sub { my ($ua, $tx) = @_; my $info = $c -> get_title ($tx -> res -> dom); $c -> render ( template => 'index', info => $info, ); }; $c -> async_title ($cb); $c -> render_later; }; get '/second' => sub { my $c = shift; my $cb = sub { my ($ua, $tx) = @_; my $info = $c -> get_title ($tx -> res -> dom); $info = sprintf "Extra processing on info to get: %s", scalar reverse $info; $c -> render ( template => 'index', info => $info, ); }; $c -> async_title ($cb); $c -> render_later; }; app -> start; __DATA__ @@ index.html.ep % layout 'default'; % title 'Welcome'; %= $info @@ layouts/default.html.ep <!DOCTYPE html> <html> <head><title><%= title %></title></head> <body><%= content %></body> </html>
Private
[
?
]
Run code
Submit