Created
December 2, 2009 05:34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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