The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::Curl::UserAgent - UserAgent based on libcurl

VERSION

version 0.9.0

SYNOPSIS

use HTTP::Request;
use WWW::Curl::UserAgent;

my $ua = WWW::Curl::UserAgent->new(
    timeout         => 10,
    connect_timeout => 1,
);

$ua->add_request(
    request    => HTTP::Request->new('http://search.cpan.org/'),
    on_success => sub {
        my ( $request, $response ) = @_;
        if ($response->is_success) {
            print $response->content;
        }
        else {
            die $response->status_line;
        }
    },
    on_failue  => sub {
        my ( $request, $error_msg, $error_desc ) = @_;
        die "$error_msg: $error_desc";
    },
);
$ua->perform;

DESCRIPTION

WWW::Curl::UserAgent is a web user agent based on libcurl. It can be used easily with HTTP::Request and HTTP::Response objects and handler callbacks. For an easier interface there is also a method to map a single request to a response.

WWW::Curl is used for the power of libcurl, which e.g. handles connection keep-alive, parallel requests, asynchronous callbacks and much more. This package was written, because WWW::Curl::Simple does not handle keep-alive correctly and also does not consider PUT, HEAD and other request methods like DELETE.

There is a simpler interface too, which just returns a HTTP::Response for a given HTTP::Request, named request(). The normal approach to use this library is to add as many requests with callbacks as your code allows to do and run perform afterwards. Then the callbacks will be excecuted sequentially when the responses arrive beginning with the first received response. The simple method request() does not support this of course, because there are no callbacks defined.

CONSTRUCTOR METHODS

The following constructor methods are available:

ATTRIBUTES

SEE ALSO

See HTTP::Request and HTTP::Response for a description of the message objects dispatched and received. See HTTP::Request::Common and HTML::Form for other ways to build request objects.

See WWW::Curl for a description of the settings and options possible on libcurl.

AUTHORS

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by XING AG.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.