NAME

Bot::Net::Mixin - build complex objects my mixing components

SYNOPSIS

# Define your own mixin
use strict;
use warnings;

package MyBotNet::Mixin::Bot::Counter;
use base qw/ Bot::Net::Mixin /;

use Bot::Net::Mixin::Bot::Command;

# Add a counter command to a bot

sub setup {
    my $self  = shift;
    my $brain = shift;

    $brain->remember( [ 'counter' ] => 0 );
}

on bot command next => run {
    my $event = get ARG0;

    my $counter = recall 'counter' + 1;
    remember counter => $counter;

    yield reply_to_sender => $event => $counter;
};

1;

DESCRIPTION

This is the base class for all Bot::Net mixins. It basically provides for a way of cataloging which mixins a class has added, tools for mixin setup, and magic for pulling mixin stuff into the importing package.

METHODS

import

Exports anything the module lists in it's @EXPORT variable, if such a method exists.

default_configuration PACKAGE

This is used to build the default configuration file when creating a new bot or server using the botnet script and used by Bot::Net::Test to help build the base test bot or test server configuration.

A mixin should override this to return a reference to a hash containing any default values it recommends or requires for bot configuration. It will be called as a class level method and passed the name of the PACKAGE that the mixin is being used to build:

MyBotNet::Mixin::Bot::PasteBot->default_configuration('MyBotNet::Bot::FancyPaster');

MIXIN IMPLEMENTATIONS

A mixin may implement whatever POE states it wishes to using the POE::Declarative interface. Those states will be imported into the calling package.

If a mixin needs to perform any setup prior to POE::Kernel startup, it may be do so by implementing a setup method. It will be passed two arguments, the $self variable for the class stored with the session and the Data::Remember brain object that will be stored in the heap of the session being created.

sub setup {
    my $self  = shift;
    my $brain = shift;

    # Using the internal brain interface of Data::Remember, make sure to
    # be careful to use only array-based ques!
    $brain->remember( [ 'foo' ] => 'bar' );
}

In general, however, your mixins can probably get away with performing initial setup in the _start state.

AUTHORS

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2007 Boomer Consulting, Inc. All Rights Reserved.

This program is free software and may be modified and distributed under the same terms as Perl itself.