Skip to content

Instantly share code, notes, and snippets.

@jberger
Created May 22, 2013 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/5624349 to your computer and use it in GitHub Desktop.
Save jberger/5624349 to your computer and use it in GitHub Desktop.
Example, counter to https://gist.github.com/tempire/5621542, which shows how when the ua is prevent from going out of scope, the warning is not encountered and the process succeeds.
#!/usr/bin/env perl
use Mojolicious::Lite;
app->attr( ua => sub { Mojo::UserAgent->new } );
get '/' => sub {
my $self = shift;
$self->render_later;
$self->app->ua->get( 'http://tempi.re' => sub {
my ($ua, $tx) = @_;
warn $tx->error; # premature connection close
$self->render(text => $tx->res->body);
} );
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment