Bot::Cobalt::Plugin::WWW - Asynchronous HTTP requests from Cobalt plugins
## Send your request, specify an event to handle response: use HTTP::Request; my $request = HTTP::Request->new( 'GET', 'http://www.cobaltirc.org' ); broadcast( 'www_request', $request, 'myplugin_resp_recv', [ $some, $args ] ); ## Handle the response: sub Bot_myplugin_resp_recv { my ($self, $core) = splice @_, 0, 2; ## Content: my $content = ${ $_[0] }; ## HTTP::Response object: my $response = ${ $_[1] }; ## Attached arguments array reference: my $args_arr = ${ $_[2] }; return PLUGIN_EAT_ALL }
This plugin provides an easy interface to asynchronous HTTP requests; it bridges Cobalt's plugin pipeline and POE::Component::Client::HTTP to provide responses to Bot_www_request events.
The request should be a HTTP::Request object.
Inside the response handler, $_[1] will contain the HTTP::Response object; $_[0] is the undecoded content if the request was successful or some error from HTTP::Status if not.
Arguments can be attached to the request event and retrieved in the handler via $_[2] -- this is usually an array reference, but anything that fits in a scalar will do.
Plugin authors should check for the boolean value of $core->Provided->{www_request} and possibly fall back to using LWP with a short timeout if they'd like to continue to function if this plugin is not loaded.
POE::Component::Client::HTTP
HTTP::Request
HTTP::Response
Jon Portnoy <avenj@cobaltirc.org>
http://www.cobaltirc.org
To install Bot::Cobalt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::Cobalt
CPAN shell
perl -MCPAN -e shell install Bot::Cobalt
For more information on module installation, please visit the detailed CPAN module installation guide.