Skip to content

Commit

Permalink
Try to illustrate a more common way to call back.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaputo committed Sep 29, 2012
1 parent 5f75559 commit 199cb74
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions eg/eg-24-client-http-callbacks.pl
@@ -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;

0 comments on commit 199cb74

Please sign in to comment.