Browse Source

I706 Fixed validation failure for Plack

Mike Smith 11 years ago
parent
commit
ed75edd644
1 changed files with 7 additions and 8 deletions
  1. 7 8
      plack/app.psgi

+ 7 - 8
plack/app.psgi

@@ -14,12 +14,11 @@ my $header = [qw(Content-Type application/json)];
 
 
 builder {
 builder {
     mount '/json' => sub { [ 200, $header, [ encode_json({ message => 'Hello, World!' })] ] },
     mount '/json' => sub { [ 200, $header, [ encode_json({ message => 'Hello, World!' })] ] },
-    mount '/db' => sub { [ 200, $header, [ encode_json([
-        map { id => $_->[0] + 0, randomNumber => $_->[1] },
-        grep exists $_->[1],
-        map [$_, $sth->execute($_) && $sth->fetchrow_array],
-        map int rand 10000 + 1,
-        1..Plack::Request->new(shift)->param('queries')//1
-    ]) ] ] } };
-
+    mount '/db' => sub {
+        my @rs = map { id => $_->[0] + 0, randomNumber => $_->[1] },
+            grep exists $_->[1],
+            map [$_, $sth->execute($_) && $sth->fetchrow_array],
+            map int rand 10000 + 1,
+            1..Plack::Request->new(shift)->param('queries')//1;
+        [ 200, $header, [ encode_json( @rs > 1 ? \@rs : $rs[0] ) ] ] } };