Net::Async::Webservice::Common::WithUserAgent - user_agent attribute, sync or async
version 1.0.0
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, });
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.
user_agent
loop
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).
do_request
GET
POST
request
get
post
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.
$sync_ua
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>
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.
To install Net::Async::Webservice::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::Webservice::Common
CPAN shell
perl -MCPAN -e shell install Net::Async::Webservice::Common
For more information on module installation, please visit the detailed CPAN module installation guide.