Skip to content

Instantly share code, notes, and snippets.

@Akron
Created May 1, 2012 12:54
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 Akron/2567746 to your computer and use it in GitHub Desktop.
Save Akron/2567746 to your computer and use it in GitHub Desktop.
Hynotoad Example
#!/usr/bin/env perl
use Mojolicious::Lite;
our $counter = 0;
app->secret('kashkgfsjgnscjzgang');
app->config({
hypnotoad => {
listen => ['http://*:8765'],
workers => 5
}
});
get '/' => sub {
my $c = shift;
$c->render(
template => 'index',
counter => $counter++,
);
};
app->start;
__DATA__
@@ index.html.ep
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Welcome</title></head>
<body>
<h1>Welcome</h1>
<p>This is perl version: <%= $] %> running as a service.</p>
<p>Counter: <%= $counter %></p>
<p>Process: <%= $$ %></p>
% my $started = stash('mojo.started');
% my $elapsed = sprintf '%f', Time::HiRes::tv_interval($started, [Time::HiRes::gettimeofday()]);
<p>Elapsed: <%= $elapsed %></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment