Snippets

Brian Medley Attempt to render page with externally gathered values

Created by Brian Medley last modified
use Mojolicious::Lite;

get '/' => sub {
    my $c = shift;
    
    $c->delay(
        sub {
            my $delay = shift;

            $c->ua->get('http://mojolicio.us' => $delay->begin);
        },
        sub {
            my ($delay, $tx) = @_;

            $c->render("index", title => $tx->res->dom->at('title')->text);
        }
    );
};

app->start;

__DATA__

@@ index.html.ep

<!DOCTYPE html>
<html>
  <head><title><%= stash('title') %></title></head>
  <body>Welcome to <%= stash('title') %></body>
</html>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.