Skip to content

Commit

Permalink
Merge pull request #4 from vividsnow/master
Browse files Browse the repository at this point in the history
merged perl Plack from vividsnow/master
  • Loading branch information
Peter Corlett committed Apr 22, 2013
2 parents fc310d7 + 828baf8 commit 0ad7737
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions plack/app.psgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# plackup -s Starman --workers N -E deployment app.psgi
# -or-
# plackup -s Twiggy::Prefork --max_workers N -E deployment app.psgi
use v5.16;
use Plack::Builder;
use Plack::Request;
use JSON::XS 'encode_json';
use DBI;

my $dbh = DBI->connect('dbi:mysql:dbname=test', 'root') || die $!;
my $sth = $dbh->prepare('SELECT randomnumber FROM world WHERE id = ?');
my $header = ['Content-Type' => 'application/json'];

builder {
mount '/json' => sub { [ 200, $header, [ encode_json({ message => 'Hello, World!' })] ] },
mount '/dbi' => 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
]) ] ] }
};

0 comments on commit 0ad7737

Please sign in to comment.