AnyEvent-Curl-Multi
view release on metacpan or search on metacpan
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: AnyEvent-Curl-Multi
version: 1.1
version_from: lib/AnyEvent/Curl/Multi.pm
installdirs: site
requires:
AnyEvent: 5
HTTP::Request: 0
HTTP::Response: 0
Object::Event: 1
Test::More: 0
WWW::Curl: 4.14
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
Makefile.PL view on Meta::CPAN
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
PREREQ_PM => {
'AnyEvent' => 5,
'Object::Event' => 1,
'WWW::Curl' => 4.14,
'Test::More' => 0,
'HTTP::Response' => 0,
'HTTP::Request' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'AnyEvent-Curl-Multi-*' },
);
# vim:syn=perl:ts=4:sw=4:et:ai
lib/AnyEvent/Curl/Multi.pm view on Meta::CPAN
my $client = AnyEvent::Curl::Multi->new;
$client->max_concurrency(10);
# Method 1: Object::Event pattern
#
# Schedule callbacks to be fired when a response is received,
# or when an error occurs.
$client->reg_cb(response => sub {
my ($client, $request, $response, $stats) = @_;
# $response is an HTTP::Request object
});
$client->reg_cb(error => sub {
my ($client, $request, $errmsg, $stats) = @_;
# ...
});
my $request = HTTP::Request->new(...);
$client->request($request);
# Method 2: AnyEvent::CondVar pattern
# Do not use this pattern in an existing event loop!
my $handle = $client->request($request);
eval {
my ($response, $stats) = $handle->cv->recv;
# $response is an HTTP::Request object
# ...
};
if ($@) {
my $errmsg = $@;
# ...
}
=head1 DESCRIPTION
This module is an AnyEvent user; you must use and run a supported event loop.
lib/AnyEvent/Curl/Multi.pm view on Meta::CPAN
Specifies which kind of IP address to select when resolving host names. This
is only useful when using host names that resolve to both IPv4 and IPv6
addresses. The allowed values are 4 (IPv4) or 6 (IPv6). The default is to
resolve to all addresses.
=back
=head2 Issuing requests
To dispatch HTTP requests to the client, use the request() method. request()
takes an HTTP::Request object as the first argument, and a list of
attribute-value pairs as the remaining arguments:
$handle = $client->request($request, ...);
The following attributes are accepted:
=over
=item timeout => PERIOD
lib/AnyEvent/Curl/Multi.pm view on Meta::CPAN
return bless $self, $class;
}
sub request {
my $self = shift;
my ($req, %opts) = @_;
my $easy_h;
if ($req->isa("HTTP::Request")) {
# Convert to WWW::Curl::Easy
$easy_h = $self->_gen_easy_h($req, %opts);
} else {
croak "Unsupported request type";
}
# Initialize easy curl handle
my $id = refaddr $easy_h;
my ($response, $header);
$easy_h->setopt(CURLOPT_WRITEDATA, \$response);
lib/AnyEvent/Curl/Multi.pm view on Meta::CPAN
libcurl's internal hostname resolution cache is disabled by this module (among
other problems, it does not honor DNS TTL values). If you need fast hostname
resolution, consider installing and configuring a local DNS cache such as BIND
or dnscache (part of djbdns).
SSL peer verification is disabled. If you consider this a serious problem,
please contact the author.
=head1 SEE ALSO
L<AnyEvent>, L<AnyEvent::Handle>, L<Object::Event>, L<HTTP::Request>,
L<HTTP::Response>
=head1 AUTHORS AND CONTRIBUTORS
Michael S. Fischer (L<michael+cpan@dynamine.net>) released the original version
and is the current maintainer.
=head1 COPYRIGHT AND LICENSE
(C) 2010-2011 Michael S. Fischer.
#!perl -T
use Test::More tests => 9;
BEGIN {
use_ok( 'AnyEvent' );
use_ok( 'AnyEvent::Curl::Multi' );
use_ok( 'HTTP::Request');
}
my $TEST_URL = 'http://www.perl.org';
my $cv = AE::cv;
my $client = new_ok('AnyEvent::Curl::Multi' => [timeout => 30]);
my $request = new_ok('HTTP::Request' => [GET => $TEST_URL]);
ok($client->request($request), "issued request");
$client->reg_cb(response => sub { $cv->(@_) });
$client->reg_cb(error => sub { $cv->(@_) });
my (undef, undef, $response, $stats) = $cv->recv;
isa_ok($response, 'HTTP::Response');
isa_ok($stats, 'HASH');
( run in 0.449 second using v1.01-cache-2.11-cpan-de7293f3b23 )