vividsnow 12 years ago
parent
commit
5fc9f4fd6a
1 changed files with 6 additions and 7 deletions
  1. 6 7
      plack/app.psgi

+ 6 - 7
plack/app.psgi

@@ -1,7 +1,8 @@
-# starman --workers N app.psgi
+# starman --workers N myapp.psgi
 use v5.16;
 use v5.16;
 use Plack::Builder;
 use Plack::Builder;
 use Plack::Request;
 use Plack::Request;
+use Plack::Response;
 use JSON::XS 'encode_json';
 use JSON::XS 'encode_json';
 use DBI;
 use DBI;
 
 
@@ -10,18 +11,16 @@ my $sth = $dbh->prepare('SELECT id, randomnumber FROM world WHERE id = ?');
 my $header = HTTP::Headers->new('Content-Type' => 'application/json');
 my $header = HTTP::Headers->new('Content-Type' => 'application/json');
 
 
 builder {
 builder {
-    mount '/json' => sub { 
-        Plack::Request->new(shift)->new_response(
-            200, $header, encode_json({ message => 'Hello, World!' }) 
-        )->finalize 
-    },
+    mount '/json' => sub { Plack::Response->new(
+        200, $header, encode_json({ message => 'Hello, World!' })
+    )->finalize },
     mount '/dbi' => sub {
     mount '/dbi' => sub {
         my $r = Plack::Request->new(shift);
         my $r = Plack::Request->new(shift);
         $r->new_response( 200, $header, encode_json([ 
         $r->new_response( 200, $header, encode_json([ 
             map { id => $_->[0], randomnumber => $_->[1] }, 
             map { id => $_->[0], randomnumber => $_->[1] }, 
             grep exists $_->[1], 
             grep exists $_->[1], 
             map [$_, $sth->execute($_) && $sth->fetchrow_array], 
             map [$_, $sth->execute($_) && $sth->fetchrow_array], 
-            map int rand 10000 + 1, 
+            map int rand 10000 + 1,
             1..$r->param('queries')//1 
             1..$r->param('queries')//1 
         ]) )->finalize
         ]) )->finalize
     }
     }