ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/eg/httpd
Revision: 1.2
Committed: Fri Dec 10 02:35:54 2010 UTC (15 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-0_92, rel-0_91, rel-1_11, rel-1_31, rel-1_1, rel-1_0, rel-1_3, rel-1_2, rel-1_5, rel-1_4, rel-0_911, rel-0_912, rel-1_21, rel-1_22, rel-1_46, rel-1_44, rel-1_45, rel-1_42, rel-1_43, rel-1_41, HEAD
Changes since 1.1: +22 -5 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 use AnyEvent::HTTPD;
4
5 my $httpd = AnyEvent::HTTPD->new (port => 9090);
6
7 warn "AnyEvent::HTTPD listening on: http://localhost:9090/\n";
8
9 $httpd->reg_cb (
10 '/' => sub {
11 my ($httpd, $req) = @_;
12
13 my $res = "<html><body><h1>files embedded in this staticperl</h1><table><tr><th align=\"left\">by name</th><th align=\"left\">by size</th></tr>";
14
15 my %size;
16
17 $size{$_} = length static::find $_
18 for static::list;
19
20 $res .= "<tr><td>";
21
22 for (sort keys %size) {
23 $res .= "<a href=\"$_\">$_ $size{$_}</a><br />";
24 }
25
26 $res .= "</td><td>";
27
28 for (sort { $size{$b} <=> $size{$a} or $a cmp $b } keys %size) {
29 $res .= "<a href=\"$_\">$size{$_} $_</a><br />";
30 }
31
32 $res .= "</tr></table></body></html>";
33
34 $req->respond ([200 => "OK", { 'Content-Type' => 'text/html' }, $res]);
35 },
36 '' => sub {
37 my ($httpd, $req) = @_;
38
39 my $file = static::find substr $req->url, 1;
40 $req->respond ([200 => "OK", { 'Content-Type' => 'text/plain; charset=utf-8' }, $file]);
41 },
42 );
43
44 $httpd->run;