Black::Board::Subscriber - Subscriber class for Black::Board
version 0.0001
use Black::Board::Subscriber; use Black::Board::Topic; $topic = Black::Board::Topic->new( name => "Logging" ); $topic->add_subscriber( Black::Board::Subscriber->new( subscription => sub { $logger->log( %{ $_->params } ); return $_->cancel_bubble; } ) ); $topic->add_subscriber( Black::Board::Subscriber->new( subscription => sub { return $_->clone( params => $_->params->merge({ message => '[Prefix1] ' . $_->params->{message} }) ) } ) ); $topic->add_subscriber( Black::Board::Subscriber->new( subscription => sub { return $_->clone( params => $_->params->merge({ message => '[Prefix2] ' . $_->params->{message} }) ) } ) ); # --- OR --- # use Black::Board; topic "Logging"; subscriber Logging => sub { $logger->log( %{ $_->params } ); return $_->cancel_bubble; }; subscriber Logging => sub { my %args = @_; return $args{message}->clone( params => $args{message}->params->merge({ message => '[Prefix1] ' . $args{message}->params->{message} }) ) }; subscriber Logging => sub { return $_->clone( params => $_->params->merge({ message => '[Prefix2] ' . $_->params->{message} }) ) };
This is the Subscriber class for Black::Board. This is the class that represents a subscription to a specific Topic. It provides a delivery interface for dispatching a Message to a CodeRef.
CodeRef
subscription
subscription is an attribute which contains the CodeRef called to deliver a message. This CodeRef should expect the Black::Board::Message object as it's only argument. This object will also be localized into $_.
$_
Black::Board::Subscriber->new( subscription => sub { my $message = shift; # -or- my $message = $_ } );
deliver
This method is usually called by "METHODS/deliver" in Black::Board::Topic. It takes the Black::Board::Message object to be delivered.
This method sets the current Subscriber in the Message instance to this Subscriber until this delivery is over (local()).
Subscriber
See "ATTRIBUTES/subscription" to see how the subscription is dispatched.
Black::Board::Message - object being delivered to Subscribers
Black::Board::Topic - delivers Messages to Subscribers
Black::Board - provides sugar syntax
Scott Beck <sabeck@cpan.org>
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.
To install Black::Board::Subscriber, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Black::Board::Subscriber
CPAN shell
perl -MCPAN -e shell install Black::Board::Subscriber
For more information on module installation, please visit the detailed CPAN module installation guide.