Browse Source

Merge branch 'master' of https://github.com/naturalist/FrameworkBenchmarks into kelp-1011

Conflicts:
	frameworks/Perl/kelp/app.pl
	frameworks/Perl/kelp/t/main.t
Hamilton Turner 11 years ago
parent
commit
6853a69862
2 changed files with 12 additions and 5 deletions
  1. 11 5
      frameworks/Perl/kelp/app.pl
  2. 1 0
      frameworks/Perl/kelp/t/main.t

+ 11 - 5
frameworks/Perl/kelp/app.pl

@@ -52,7 +52,7 @@ get '/fortunes/?db' => sub {
         $sth[1]->execute();
         @objects = @{ $sth[1]->fetchall_arrayref( {} ) };
     }
-    push @objects, { message => "Additional fortune added at request time." };
+    push @objects, { id => 0, message => "Additional fortune added at request time." };
     fortunes( \@objects );
 };
 
@@ -86,7 +86,8 @@ run;
 sub query {
     my ( $db, $count ) = @_;
     $count //= 1;
-    $count = 1 unless $count =~ /^\d+$/;
+    $count = 1 if ( $count !~ /^\d+$/ || $count < 1 );
+    $count = 500 if $count > 500;
     my @response;
     for ( 1 .. $count ) {
         my $id = int rand 10000 + 1;
@@ -96,9 +97,9 @@ sub query {
         }
         else {
             $sth[0]->execute($id);
-            $row = $sth[0]->fetchrow_hashref
+            $row = $sth[0]->fetchrow_hashref;
         }
-        if ( $row ) {
+        if ($row) {
             if ( $count == 1 ) {
                 return { id => $id, randomNumber => $row->{randomNumber} };
             }
@@ -117,8 +118,13 @@ sub fortunes {
     $res .= q[<body><table><tr><th>id</th><th>message</th></tr>];
 
     for my $item ( sort { $a->{message} cmp $b->{message} } @$objects ) {
-        my $id = $item->{id} // 1000;
+        my $id = $item->{id};
         my $message = escape_html( $item->{message} );
+
+        # HTML::Escape encodes apostrophe as &#39; because IE8 does not
+        # support &apos;. We forse an &apos; here in order to pass the
+        # test
+        $message =~ s/&#39/&apos/g;
         $res .= "<tr><td>$id</td><td>$message</td></tr>";
     }
 

+ 1 - 0
frameworks/Perl/kelp/t/main.t

@@ -31,6 +31,7 @@ subtest queries => sub {
         $t->request( GET $uri )->json_cmp($world);
         $t->request( GET "$uri?queries=3" )
           ->json_cmp( [ $world, $world, $world ] );
+        $t->request( GET "$uri?queries=0" )->json_cmp($world);
     }
 };