#!/usr/bin/env perl
use Mojolicious::Lite;
app -> helper (mt => sub {
my $c = shift;
$c -> ua -> get ('http://mojolicio.us', sub {
my ($ua, $tx) = @_;
my $title = $tx -> res -> dom -> find ('title') -> first;
$c -> app -> log -> debug ('Got title', $title -> text);
return $title -> text;
});
});
app -> helper (mt_rl => sub {
my $c = shift;
$c -> ua -> get ('http://mojolicio.us', sub {
my ($ua, $tx) = @_;
my $title = $tx -> res -> dom -> find ('title') -> first;
$c -> app -> log -> debug ('Got title', $title -> text);
return $title -> text;
});
$c -> render_later;
});
app -> helper (mt_pre_rl => sub {
my $c = shift;
$c -> render_later;
$c -> ua -> get ('http://mojolicio.us', sub {
my ($ua, $tx) = @_;
my $title = $tx -> res -> dom -> find ('title') -> first;
$c -> app -> log -> debug ('Got title', $title -> text);
return $title -> text;
});
});
get '/' => sub {
my $c = shift;
my $title = $c -> mt;
#my $title = $c -> mt_rl;
#my $title = $c -> mt_pre_rl;
my $result = sprintf "Got: %s\nExpected: %s",
$title, 'Mojolicious - Perl real-time web framework';
$c->render(text => $result);
};
app->start;