#!/opt/perl/bin/perl
use strict;
use AnyEvent::HTTPD;
use AnyEvent::HTTPD::Appgets;

my $httpd = AnyEvent::HTTPD->new (port => 9090);

my $t;

$httpd->reg_cb (
   '' => sub {
      my ($httpd, $req) = @_;
      set_request ($req);

      o capture {
         o "<html><body><h1>Hello World!</h1>";
         o "<a href=\"/test\">another test page</a>";
         o "</body></html>";
      };

      $req->respond;
   },
   '/test' => sub {
      my ($httpd, $req) = @_;
      $httpd->stop_request;

      $t = AnyEvent->timer (after => 2, cb => sub {
         my $o = capture {
            o "CPU info:\n\n";
            o `cat /proc/cpuinfo`;
         };
         $req->respond ([200, "ok", { 'Content-Type' => 'text/plain' }, $o]);
      });

      'delay'
   },
);

$httpd->run;
