Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[web-druid] changed to use the new simple regime

For some reason, though, it doesn't work. I will have to investigate
further. Getting this error when hitting the page:

$ perl6 bin/web-druid
Druid now runs on http://127.0.0.1:8888/
No applicable candidates found to dispatch to for 'trait_mod:of'
in method HTTP::Daemon::accept (lib/HTTP/Daemon.pm:218)
called from method Web::Handler::HTTPDaemon::run (/Users/masak/gwork/web/lib/Web/Handler/HTTPDaemon.pm:8)
called from Main (bin/web-druid:9)
  • Loading branch information...
commit 16afaed5a864b5047ba8bb87d26fb96df6a6dc33 1 parent 79bc10a
Carl Mäsak authored September 06, 2009
63  bin/web-druid
... ...
@@ -1,64 +1,9 @@
1 1
 #!/usr/local/bin/perl6
2 2
 use v6;
3  
-use HTTP::Daemon;
4 3
 use Druid::Webapp;
5 4
 
6  
-defined @*ARGS[0] && @*ARGS[0] eq '--request' ?? request() !! daemon();
  5
+use Web::Handler::HTTPDaemon;
7 6
 
8  
-# Serve one page
9  
-sub request($c) {
10  
-    my $r = $c.get_request;
11  
-    if $r.req_method eq 'GET' {
12  
-        # log request info to the standard error stream
13  
-        warn "{hhmm} GET {$r.url.path} {$r.header('User-Agent')}";
14  
-        if $r.url.path eq '/board.svg' {
15  
-            $c.send_response( svg-board() );
16  
-        }
17  
-        else {
18  
-            my $qs = $r.url.path ~~ / '?' (.*) $/
19  
-                        ?? $0
20  
-                        !! '';
21  
-            $c.send_response( Druid::Webapp.page($qs) );
22  
-        }
23  
-    }
24  
-    else {
25  
-        warn "{hhmm} rejected {$r.req_method} {$r.url.path}";
26  
-        $c.send_error('RC_FORBIDDEN');
27  
-    }
28  
-    warn ' '; # blank line
29  
-}
30  
-
31  
-# Executed as main parent process with an endless loop that re-starts
32  
-# netcat after every page request.
33  
-sub daemon {
34  
-    my HTTP::Daemon $d .= new( host=> '127.0.0.1', port=> 8888 );
35  
-    say "Browse this Perl 6 (Rakudo) web server at {$d.url}";
36  
-    $d.daemon();
37  
-}
38  
-
39  
-# give the current time in hh:mm format
40  
-sub hhmm {
41  
-    my $t = int(time);
42  
-    my $m = int( $t / 60 ) % 60;
43  
-    my $h = int( $t / 3600 ) % 24;
44  
-    my $hhmm = "{$h.fmt('%02d')}:{$m.fmt('%02d')}";
45  
-    return $hhmm;
46  
-}
47  
-
48  
-sub svg-board() {
49  
-    return '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
50  
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
51  
-   "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
52  
-<svg xmlns="http://www.w3.org/2000/svg"
53  
-   version="1.0"
54  
-   width="400"
55  
-   height="400">
56  
-    <rect
57  
-        width="400"
58  
-        height="400"
59  
-        x="0"
60  
-        y="0"
61  
-        style="opacity:1;fill:none;stroke:#000000;stroke-width:2;"
62  
-    />
63  
-</svg>';
64  
-}
  7
+my $port = 8888;
  8
+say "Druid now runs on http://127.0.0.1:$port/";
  9
+Web::Handler::HTTPDaemon.run( Druid::Webapp.new );
32  lib/Druid/Webapp.pm
... ...
@@ -1,29 +1,23 @@
1 1
 use v6;
2  
-use Tags; 
  2
+
  3
+use Web::Request;
  4
+use Web::Response;
  5
+
3 6
 use Druid::Game; 
4 7
 use Druid::View::Text;
5 8
 
6  
-class Druid::Webapp {
7  
-
8  
-    method page(Str $query-string) {
  9
+class Druid::Webapp does Callable {
  10
+    method postcircumfix:<( )>($env) {
9 11
         my $board-size = 8;
10 12
         my Druid::Game $game .= new(:size($board-size));
11 13
         my Druid::View $view = Druid::View::Text.new(:$game);
12 14
 
13  
-        return
14  
-            show {
15  
-                html {
16  
-                    head { title { 'Druid' } }
17  
-                    body {
18  
-                        pre { $view }
19  
-                        object :type<image/svg+xml>, :data</board.svg>, {
20  
-                            'alternate text'
21  
-                        }
22  
-                        ul {
23  
-                            for $game.possible-moves() -> $move {
24  
-                                li {
25  
-                                    a :href("?moves=$move"), { $move }
26  
-            }}}}}};
  15
+        my Web::Response $res .= new;
  16
+        $res.write($_) for
  17
+            '<title>Druid</title>',
  18
+            '<pre>',
  19
+            $view,
  20
+            '</pre>';
  21
+        $res.finish();
27 22
     }
28  
-
29 23
 }

0 notes on commit 16afaed

Please sign in to comment.
Something went wrong with that request. Please try again.