Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
Created September 26, 2018 09:28
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 jhthorsen/a7a7589dc17082a896a9efd3d204235d to your computer and use it in GitHub Desktop.
Save jhthorsen/a7a7589dc17082a896a9efd3d204235d to your computer and use it in GitHub Desktop.
Show how you need prevent the object from going out of scope
#!perl
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
my $ua = Mojo::UserAgent->new;
# Try keeping this object alive with http://localhost:3000?keep_alive=1
$c->stash(ua => $ua) if $c->param('keep_alive');
$c->render_later;
$ua->get('https://www.solfaktor.no/', sub {
my ($ua, $tx) = @_;
$c->render(text => $tx->res->code);
});
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment