Created
August 21, 2014 22:02
-
-
Save pRiVi/0fd88461ef0551f457a3 to your computer and use it in GitHub Desktop.
Muesli Herausforderung im Kapf der Sprachen
This file contains hidden or 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
| use POE qw(Component::Client::HTTP Component::Server::HTTP ); | |
| use HTTP::Request; | |
| POE::Component::Client::HTTP->spawn(Alias => 'ua'); | |
| POE::Component::Server::HTTP->new( | |
| Port => 8000, | |
| ContentHandler => { | |
| '/' => sub { | |
| doHttp("FINDME:".time()); | |
| } | |
| }, | |
| ); | |
| POE::Session->create( | |
| inline_states => { | |
| _start => sub { | |
| $poe_kernel->yield("loop"); | |
| }, | |
| loop => sub { | |
| print "".time()."\n"; | |
| $poe_kernel->delay("loop" => 0.5); | |
| } | |
| } | |
| ); | |
| sub doHttp { | |
| my $param = shift; | |
| POE::Session->create( | |
| inline_states => { | |
| _start => sub { | |
| $poe_kernel->post('ua' => 'request' => 'on_done' => | |
| HTTP::Request->new(GET => "http://www.heise.de/newsticker/") => { data => $_[ARG0] }); | |
| }, | |
| on_done => sub { | |
| my ($kernel, $session, $heap, $request_packet, $response_packet) = @_[ KERNEL, SESSION, HEAP, ARG0, ARG1]; | |
| my $request_object = $request_packet->[0]; | |
| my $response_object = $response_packet->[0]; | |
| my $params = $request_packet->[1]; | |
| if ($response_object && ($response_object->code == 200)) { | |
| print $response_object->content(); | |
| print "Context was :'".$params->{data}."'\n"; | |
| } | |
| } | |
| }, | |
| args => [ $param ], | |
| ); | |
| } | |
| doHttp("findmeWithout"); | |
| $poe_kernel->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment