Created
November 2, 2014 13:39
-
-
Save Logioniz/82f53536af520aeb0f10 to your computer and use it in GitHub Desktop.
UserAgent in controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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