Created
January 12, 2012 17:37
-
-
Save olegwtf/1601965 to your computer and use it in GitHub Desktop.
IO::Lambda::HTTP
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 strict; | |
use URI; | |
use HTTP::Request; | |
use IO::Lambda qw(:all); | |
use IO::Lambda::HTTP qw(http_request); | |
sub request($) { | |
my $url = URI->new($_[0]); | |
my $req = HTTP::Request->new(GET => $url, [Host => $url->host]); | |
$req->protocol('HTTP/1.1'); | |
$req; | |
} | |
par->wait( | |
map { | |
my $request = request $_; | |
lambda { | |
context $request; | |
http_request { | |
my $response = shift; | |
if (ref $response) { | |
print $request->url, ': ', $response->status_line, "\n"; | |
} | |
else { | |
print $request->url, ': ', $response, "\n"; | |
} | |
} | |
} | |
} qw(http://perlmonks.org http://www.google.ru/ http://perl.org/ http://perl.com) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment