The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bot::ChatBots::Role::WebPoller - Bot::ChatBots Role for Web Pollers

SYNOPSIS

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;

DESCRIPTION

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 "build_tx" in Mojo::UserAgent.

You can optionally configure a specific Mojo::UserAgent as the ua parameter, e.g. if you want to set specific parameters like a timeout.

What Should You Provide/Override

Whatever needed by Bot::ChatBots::Role::Poller, except for "poll" that is provided.

METHODS

It should be safe to override the following methods in your classes composing this role.

poll

$obj->poll($callback, $args);

Fetches new data using the user agent "ua" and fetching data with the request contained in "tx_args".

tx_args

my $array_ref = $obj->tx_args;

Get an array ref with the "instructions" for fetching new data. Refer to "build_tx" in Mojo::UserAgent, because it is used like this:

my $tx = $ua->build_tx(@$array_ref);

ua

my $ua = $obj->ua;

Get the user agent object.

REQUIRED METHODS

See Bot::ChatBots::Role::Poller and Bot::ChatBots::Role::Source.

SEE ALSO

Bot::ChatBots, Bot::ChatBots::Role::Poller, Bot::ChatBots::Role::Source.

AUTHOR

Flavio Poletti <polettix@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2018 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.