Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to illustrate a more common way to call back.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env perl | ||
# vim: ts=2 sw=2 noexpandtab | ||
|
||
use warnings; | ||
use strict; | ||
use lib qw(../lib); | ||
|
||
# HttpClient is a wrapper for POE::Component::Client::HTTP. | ||
use HttpClient; | ||
|
||
### Main usage. | ||
|
||
use HTTP::Request; | ||
|
||
# 1. Create a user-agent object. | ||
|
||
my $ua = HttpClient->new( | ||
on_response => sub { | ||
my ($self, $event) = @_; | ||
print $event->response()->code(), " = ", $event->request->uri(), "\n"; | ||
}, | ||
); | ||
|
||
# 2. Send a request. | ||
|
||
$ua->request( HTTP::Request->new( GET => $_ ) ) foreach ( | ||
'http://poe.perl.org', | ||
'http://duckduckgo.com/', | ||
'http://metacpan.org/', | ||
'http://perl.org/', | ||
'http://twitter.com/', | ||
); | ||
|
||
# 3. Wait for stuff. | ||
|
||
Reflex->run_all(); | ||
|
||
exit; |