NAME
Bot::Backbone::Dispatcher - Simple dispatching tool
VERSION
version 0.161950
SYNOPSIS
my $dispatcher = Bot::Backbone::Dispatcher->new(
predicates => \@predicates,
also_predicates => \@also_predicates,
);
my $message = Bot::Backbone::Message->new(...);
$dispatcher->dispatch_message($message);
DESCRIPTION
A dispatcher is an array of predicates that are each executed in turn. Each predicate is a subroutine that is run against the message that may or may not take an action against it and is expected to return a boolean value declaring whether any action was taken.
ATTRIBUTES
predicates
Predicates in this list are executed sequentially and in order. The first predicate to return a true value causes execution to cease so that any further predicates are ignored.
also_predicates
This list of predicates are not guaranteed to execute sequentially or in any particular order. The return value of these predicates will be ignored and all will be executed on every message, even those that have already been handled by a predicate in the "predicates" list.
METHODS
dispatch_message
$dispatcher->dispatch_message($message);
Given a Bot::Backbone::Message, this will execute each predicate attached to the dispatcher, using the policies described under "predicates" and "also_predicates".
add_predicate_or_return
$dispatcher->add_predicate_or_return($predicate);
Chances are that you probably don't need this method. However, if you are creating a new kind of predicate, you will probably want this method.
This will do the right thing to either add a root level predicate to the dispatcher or return the predicate for chaining within another predicate. You probably want to read the code in Bot::Backbone::DispatchSugar for examples.
predicate_iterator
my $iterator = $dispatcher->predicate_iterator;
while (my $predicate = $iterator->next) {
# do something...
}
Returns a Bot::Backbone::Dispatcher::PredicateIterator for this dispatcher.
AUTHOR
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.