NAME
AnyEvent::UserAgent - AnyEvent::HTTP OO-wrapper
SYNOPSIS
use AnyEvent::UserAgent;
use Data::Dumper;
my $ua = AnyEvent::UserAgent->new;
my $cv = AE::cv;
$ua->get('http://example.com/', sub {
my ($res) = @_;
print(Dumper($res, $ua->cookie_jar));
$cv->send();
});
$cv->recv();
DESCRIPTION
AnyEvent::UserAgent is a OO-wrapper around AnyEvent::HTTP with cookies support by HTTP::Cookies. Also request callback receives response as HTTP::Response object.
ATTRIBUTES
agent
The product token that is used to identify the user agent on the network. The agent value is sent as the User-Agent
header in the requests.
cookie_jar
The cookie jar object to use. The only requirement is that the cookie jar object must implement the extract_cookies($req)
and add_cookie_header($res)
methods. These methods will then be invoked by the user agent as requests are sent and responses are received. Normally this will be a HTTP::Cookies object or some subclass. Default cookie jar is the HTTP::Cookies object.
max_redirects
Maximum number of redirects the user agent will follow before it gives up. By default, the value is 5.
timeout
The request timeout. See timeout
in AnyEvent::HTTP. Default timeout is 30 seconds.
METHODS
new
my $ua = AnyEvent::UserAgent->new;
my $ua = AnyEvent::UserAgent->new(timeout => 60);
Constructor for the user agent. You can pass it either a hash or a hash reference with attribute values.
request
$ua->request(GET 'http://example.com/', sub { print($_[0]->code) });
This method will dispatch the given request object. Normally this will be an instance of the HTTP::Request class, but any object with a similar interface will do. The last argument must be a callback that will be called with a response object as first argument. Response will be an instance of the HTTP::Response class.
This method is a wrapper for the AnyEvent::HTTP::http_request()
method. So you also can pass parameters for it, e.g.:
$ua->request(GET 'http://example.com/', want_body_handle => 0, sub { print($_[0]->code) });
Full parameter list see at the AnyEvent::HTTP documentation.
get
$ua->get('http://example.com/', sub { print($_[0]->code) });
This method is a wrapper for the request()
method and the HTTP::Request::Common::GET()
function. The last argument must be a callback.
head
This method is a wrapper for the request()
method and the HTTP::Request::Common::HEAD()
function. See get()
.
put
This method is a wrapper for the request()
method and the HTTP::Request::Common::PUT()
function. See get()
.
delete
This method is a wrapper for the request()
method and the HTTP::Request::Common::DELETE()
function. See get()
.
post
$ua->post('http://example.com/', [key => 'value'], sub { print($_[0]->code) });
This method is a wrapper for the request()
method and the HTTP::Request::Common::POST()
function. The last argument must be a callback.
SEE ALSO
AnyEvent::HTTP, HTTP::Cookies, HTTP::Request::Common, HTTP::Request, HTTP::Response.
SUPPORT
Repository
Bug tracker
AUTHOR
Denis Ibaev dionys@cpan.org
for AdCamp.ru.
CONTRIBUTORS
Andrey Khozov avkhozov@cpan.org
.
This module based on original AnyEvent::HTTP::Simple module by punytan punytan@gmail.com
.
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/ for more information.