NAME
Black::Board::Topic - Topic module for Black::Board, meshes Messages with Subscribers
VERSION
version 0.0001
SYNOPSIS
my $logger = new Log::Dispatch(
outputs => [
[ Screen => ( 'min_level' => 'debug' ) ]
]
);
topic LogDispatch => sub {
$logger->log( %{ $_->params } );
return $_->cancel_bubble;
};
subscriber LogDispatch => sub {
return $_->clone_with_params(
message => '[Prefix] ' . $_->params->{message}
)
};
publish LogDispatch =>
message => "Something that needs logging",
level => "alert";
DESCRIPTION
A topic has a list of subscribers. It also has a say in what kinds of messages will be going to said subscribers. A topic is registered to a specific Publisher. The publisher takes care of finding which topic to publish to and passes off the Message to the individual Topic objects. If the message is modified by the subscriber, a clone of the message with the modifications is expected to be returned.
This is one of the pieces in the puzzle.
ATTRIBUTES
name
Each topic must have a name and this attribute contains the name. The name is used to identify the Topic for message dispatch and subscription.
subscribers
This attribute holds an array of subscribers which have subscribed to this topic.
initializers
List of registered initializers, code that is ran the first time a message is published to this topic. Subclasses can not override this due to optimizations.
message_class
This is the class of the message object this topic's subscribers expect to get. This defaults to Black::Board::Message::Simple, a message with a param() interface.
METHODS
wants_message
This method is usually called by "METHODS/deliver". It takes one parameter, the current Black::Board::Message object. Returning false from this method will cause "METHODS/deliver" to skip the current Message. The default implementation returns true.
This is a place for subclasses to override. The default method only returns true. You can override this in your custom topic to do some complex checking. You can skip the current message by returning false or you can throw an exception if things are really scary!
deliver
This method is usually called by "METHODS/publish" in Black::Board::Publisher. It takes two positional arguments. The first is the Black::Board::Subscriber object to deliver to. The second argument is the Black::Board::Message object which is being delivered.
This method returns the message passed in if a call to <Topic-wants_message( Message )>> returns false. Otherwise this method returns it's call to Subscriber->deliver( Message ). The Message object has it's current topic set to this Topic instance.
SEE ALSO
Black::Board::Publisher - publishes Messages to Topics
Black::Board::Subscriber - the object a Topic delivers a message to
Black::Board - provides sugar syntax to do all this
AUTHOR
Scott Beck <sabeck@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Scott Beck <sabeck@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.