NAME
Black::Board::Subscriber - Subscriber class for Black::Board
VERSION
version 0.0001
SYNOPSIS
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}
})
)
};
DESCRIPTION
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.
ATTRIBUTES
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 = $_
}
);
METHODS
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()).
See "ATTRIBUTES/subscription" to see how the subscription is dispatched.
SEE ALSO
Black::Board::Message - object being delivered to Subscribers
Black::Board::Topic - delivers Messages to Subscribers
Black::Board - provides sugar syntax
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.