http skeleton using AnyEvent::HTTPD
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 7 Sep 2010 12:55:14 +0000 (12:55 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 7 Sep 2010 12:55:14 +0000 (12:55 +0000)
Makefile.PL
scripts/mqr-httpd.pl [new file with mode: 0755]

index 9d14f9e..2b84212 100644 (file)
@@ -11,6 +11,7 @@ requires 'AnyEvent::XMPP';
 requires 'AnyEvent::Redis' => 0.19; # need PubSub!
 requires 'AnyEvent::IRC';
 requires 'AnyEvent::SMTP';
+requires 'AnyEvent::HTTPD';
 
 requires 'Data::Dump';
 requires 'XML::Twig';
diff --git a/scripts/mqr-httpd.pl b/scripts/mqr-httpd.pl
new file mode 100755 (executable)
index 0000000..25202a9
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+use common::sense;
+use AnyEvent;
+use AnyEvent::HTTPD;
+
+my $cvar = AnyEvent->condvar;
+
+my $httpd = AnyEvent::HTTPD->new (port => 19090);
+
+$httpd->reg_cb (
+   '' => sub {
+      my ($httpd, $req) = @_;
+      $req->respond ({ content => ['text/html', <<'CONT']});
+         <html><body><h1>Hello World!</h1>
+         <a href="/test">another test page</a>
+         </body></html>
+CONT
+   },
+   '/test' => sub {
+      my ($httpd, $req) = @_;
+      $httpd->stop_request;
+
+      $req->respond ({ content => ['text/html', <<'CONT']});
+         <html><body><h1>Test page</h1>
+         <a href="/">Back to the main page</a>
+         </body></html>
+CONT
+   },
+);
+
+$cvar->wait;