Skip to content

Instantly share code, notes, and snippets.

@spazm
Created December 2, 2009 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spazm/246971 to your computer and use it in GitHub Desktop.
Save spazm/246971 to your computer and use it in GitHub Desktop.
package MyEnginePlackPrototype;
use strict;
use warnings;
use Plack::Request;
use JSON::XS;
use MyEngineLogic;
sub send_response
{
my ( $req, $response ) = @_;
my $json = JSON::XS::encode_json $response;
my $res = $req->new_response(200);
$res->content_type('text/html');
$res->body($json);
return $res->finalize;
}
my $coderef = sub {
my $req = Plack::Request->new(shift);
#do something to get params, in the real case
my $choices = MyEngineLogic::get_choices();
my $winning_choice = MyEngineLogic::pick_winning_choice( undef, $choices );
send_response( $req, $winning_choice );
};
__END__
=head1 NAME
MyEnginePlackPrototype - A prototype server for the MyEngine system using plack
=head1 SYNOPSIS
#Run via Standalone::Prefork:
plackup --server Standalone::Prefork --port 8080 MyEnginePlackPrototype.pm
#Run via Coro:
plackup --server Coro --port 8080 MyEnginePlackPrototype.pm
C<plackup> is in the the L<Plack> cpan module.
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment