Bot::ChatBots::Role::WebPoller - Bot::ChatBots Role for Web Pollers
package Something; use Moo; with 'Bot::ChatBots::Role::WebPoller'; sub parse_response { my ($self, $data) = @_; ... } sub normalize_record { my ($self, $record) = @_; ... } 1; # later that night... my $something = Something->new( interval => 30, # polling interval, from Poller ua => Mojo::UserAgent->new, # optional, with your options tx_args => [qw< get http://example.com/whatever >], processor => \&process_record, ); Mojo::IOLoop->start;
This is a poller role for bots, polling from URLs. This role is actually a derivation of Bot::ChatBots::Role::Poller, adding a "poll" method that implements what needed for fetching data via HTTP/HTTPS asynchronously.
You MUST provide tx_args upon construction, pointing to an array reference containing all parameters for fetching data. The contents of the array is a list compatible with "Mojo::UserAgent::build_tx".
tx_args
You can optionally configure a specific Mojo::UserAgent as the ua parameter, e.g. if you want to set specific parameters like a timeout.
ua
Whatever needed by Bot::ChatBots::Role::Poller, except for "poll" that is provided.
It should be safe to override the following methods in your classes composing this role.
$obj->poll($callback, $args);
Fetches new data using the user agent "ua" and fetching data with the request contained in "tx_args".
my $array_ref = $obj->tx_args;
Get an array ref with the "instructions" for fetching new data. Refer to "Mojo::UserAgent::build_tx", because it is used like this:
my $tx = $ua->build_tx(@$array_ref);
my $ua = $obj->ua;
Get the user agent object.
See Bot::ChatBots::Role::Poller and Bot::ChatBots::Role::Source.
Bot::ChatBots, Bot::ChatBots::Role::Poller, Bot::ChatBots::Role::Source.
Flavio Poletti <polettix@cpan.org>
Copyright (C) 2016 by Flavio Poletti <polettix@cpan.org>
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Bot::ChatBots, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::ChatBots
CPAN shell
perl -MCPAN -e shell install Bot::ChatBots
For more information on module installation, please visit the detailed CPAN module installation guide.