Debian Codegraph @

samples/delayed_2_example

raw
1 #!/opt/perl/bin/perl
2 use common::sense;
3 use AnyEvent::HTTPD;
4
5 my $httpd = AnyEvent::HTTPD->new (port => 19090);
6
7 my $t;
8
9 $httpd->reg_cb (
10 '' => sub {
11 my ($httpd, $req) = @_;
12
13 my $html =
14 "<html><body><h1>Hello World!</h1>"
15 . "<a href=\"/test\">another test page</a>"
16 . "</body></html>";
17
18 $req->respond ({ content => ['text/html', $html] });
19 },
20 '/test' => sub {
21 my ($httpd, $req) = @_;
22 $httpd->stop_request;
23
24 $t = AnyEvent->timer (after => 2, cb => sub {
25 my $txt = "CPU info:\n\n" . `cat /proc/cpuinfo`;
26 $req->respond ([200, "ok", { 'Content-Type' => 'text/plain' }, $txt]);
27 });
28 },
29 );
30
31 $httpd->run;