Skip to content

Instantly share code, notes, and snippets.

@Logioniz
Created November 2, 2014 13:39
Show Gist options
  • Save Logioniz/82f53536af520aeb0f10 to your computer and use it in GitHub Desktop.
Save Logioniz/82f53536af520aeb0f10 to your computer and use it in GitHub Desktop.
UserAgent in controller
my $ua = Mojo::UserAgent->new();
my $result;
$self->render_later;
$ua->head( $location => sub {
my ($ua, $tx) = @_;
if ( $tx->res->code eq '200' ) {
$result = 'good';
}
else {
$result = 'bad';
}
$self->render( result => $result );
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
my $result;
$self->render_later;
$self->ua->head('http://ya.ru' => sub {
my ($ua, $tx) = @_;
print $self->dumper($ua);
if ( $tx->res->code eq '200' ) {
$result = 'good';
}
else {
$result = 'bad';
}
sleep 2;
$self->render( data => $result );
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment