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.
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.
get
$ua->get('http://example.com/', sub { print($_[0]->code) });
This method is a wrapper for the HTTP::Request::Common::GET(). The last argument must be a callback.
head
This method is a wrapper for the HTTP::Request::Common::HEAD(). See get().
put
This method is a wrapper for the HTTP::Request::Common::PUT(). See get().
delete
This method is a wrapper for the HTTP::Request::Common::DELETE(). See get().
post
$ua->post('http://example.com/', [key => 'value'], sub { print($_[0]->code) });
This method is a wrapper for the HTTP::Request::Common::POST(). The last argument must be a callback.
SEE ALSO
AnyEvent::HTTP, HTTP::Cookies, HTTP::Request::Common, HTTP::Response.
SUPPORT
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.