| 1 | package Bot::BasicBot::Pluggable::Module::Puppet; | ||
| 2 | { | ||
| 3 | $Bot::BasicBot::Pluggable::Module::Puppet::VERSION = '1.01'; | ||
| 4 | } | ||
| 5 | |||
| 6 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Bot::BasicBot::Pluggable::Module::Puppet - Ventriloquy via POE-flavored YAML over TCP | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | Bot::BasicBot::Pluggable::Module::Puppet enables talking in channels as | ||
| 16 | the bot by sending commands to it over a TCP socket. | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | You will need to load the module into your instance: | ||
| 21 | |||
| 22 | $bot->load('Puppet'); | ||
| 23 | |||
| 24 | The bot will listen on the address and port specified in the store via | ||
| 25 | the keys C<addr> and C<port>. If not specified, the bind address and | ||
| 26 | port will default to C<127.0.0.1> and C<28800>, respectively. | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | 0 | ▶ | use POE; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 31 | use POE::Component::Server::TCP; | ||
| 32 | |||
| 33 | use base 'Bot::BasicBot::Pluggable::Module'; | ||
| 34 | |||
| 35 | =head1 METHODS | ||
| 36 | |||
| 37 | =over 4 | ||
| 38 | |||
| 39 | =item init | ||
| 40 | |||
| 41 | This method is an initialization method called by the constructor | ||
| 42 | inherited from Bot::BasicBot::Pluggable::Module. The plugin object | ||
| 43 | itself is instantiated by the load method in Bot::BasicBot::Pluggable. | ||
| 44 | |||
| 45 | The initialization comprises the entire functionality of this plugin. | ||
| 46 | The real work is done by the POE pieces and the ClientInput callback. | ||
| 47 | |||
| 48 | We instantiate a new POE::Component::Server::TCP object that utilizes a | ||
| 49 | YAML serializer via POE::Filter::Reference. The TCP server expects to | ||
| 50 | receive a hashref that is passed directly to the bot's say method. | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | sub init | ||
| 55 | { | ||
| 56 | my $self = shift; | ||
| 57 | |||
| 58 | my $addr = $self->get('addr') || '127.0.0.1'; | ||
| 59 | my $port = $self->get('port') || 28800; | ||
| 60 | |||
| 61 | new POE::Component::Server::TCP | ||
| 62 | Address => $addr, | ||
| 63 | Port => $port, | ||
| 64 | ClientFilter => [ 'POE::Filter::Reference', 'YAML', 0 ], | ||
| 65 | ClientInput => sub { $self->say(%{ $_[ARG0] }) } | ||
| 66 | } | ||
| 67 | |||
| 68 | =back | ||
| 69 | |||
| 70 | =head1 BUGS | ||
| 71 | |||
| 72 | This plugin offers absolutely no access control, so be aware of | ||
| 73 | how/where you deploy it. | ||
| 74 | |||
| 75 | =head1 AUTHOR | ||
| 76 | |||
| 77 | Mike Eldridge <diz@cpan.org> | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | 1; | ||