Why not adopt me?
NAME
Net::Async::Webservice::Common::WithUserAgent - user_agent attribute, sync or async
VERSION
version 0.01_2
SYNOPSIS
package My::WS::Client {
use Moo;
with 'Net::Async::Webservice::Common::WithUserAgent';
}
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $c_with_default_async_ua = My::WS::Client->new({
loop => $loop,
});
my $async_ua = Net::Async::HTTP->new();
$loop->add($async_ua);
my $c_with_custom_async_ua = My::WS::Client->new({
user_agent => $async_ua,
});
my $sync_ua = LWP::UserAgent->new();
my $c_with_custom_async_ua = My::WS::Client->new({
user_agent => $sync_ua,
});
DESCRIPTION
This role provides a user_agent
attribute, guaranteed to work mostly like a Net::Async::HTTP. If a LWP::UserAgent-like object is passed in, Net::Async::Webservice::Common::SyncAgentWrapper is used to wrap it. You can also pass the loop
constructor parameter to get a default Net::Async::HTTP instance.
ATTRIBUTES
user_agent
A user agent object, looking either like Net::Async::HTTP (has do_request
, GET
, and POST
) or like LWP::UserAgent (has request
, get
, and post
).
METHODS
BUILDARGS
new
As you can see in the "SYNOPSIS", you can construct objects of classes consuming this role is a few different ways:
$class->new({
user_agent => $async_ua,
});
will just set the "user_agent".
$class->new({ loop => $loop });
will construct a Net::Async::HTTP, set it as "user_agent", and register it to the loop.
$class->new({
user_agent => $sync_ua,
});
will set the "user_agent" to an instance of Net::Async::Webservice::Common::SyncAgentWrapper wrapping the $sync_ua
.
AUTHOR
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Net-a-porter.com.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.