POEx::PubSub::Event - An event abstraction for POEx::PubSub


POEx-PubSub documentation Contained in the POEx-PubSub distribution.

Index


Code Index:

NAME

Top

POEx::PubSub::Event - An event abstraction for POEx::PubSub

VERSION

Top

version 1.102740

DESCRIPTION

Top

POEx::PubSub::Event is a simple abstraction for published and subscribed events within PubSub. When using the find_event method or the listing method from PubSub, you will receive this object.

PUBLIC_ATTRIBUTES

Top

name

    is: rw, isa: Str, required: 1

The name of the event.

subscribers

    traits: Hash, is: rw, isa: HashRef[Subscriber]

subscribers holds all of the subscribers to this event. Subscribers can be accessed via the following methods: { all_subscribers => 'values', has_subscribers => 'count', add_subscriber => 'set', remove_subscriber => 'delete', get_subscriber => 'get', }

publisher

    is: rw, isa: Str

The event's publisher.

publishtype

    is: rw, isa => PublishType

The event's publish type. Defaults to +PUBLISH_OUTPUT.

input

    is: rw, isa: Str

If the publishtype is set to PUBLISH_INPUT, this will indicate the input handling event that belongs to the publisher

AUTHOR

Top

Nicholas Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE

Top


POEx-PubSub documentation Contained in the POEx-PubSub distribution.

package POEx::PubSub::Event;
BEGIN {
  $POEx::PubSub::Event::VERSION = '1.102740';
}

#ABSTRACT: An event abstraction for POEx::PubSub

use MooseX::Declare;

class POEx::PubSub::Event {
    use POEx::PubSub::Types(':all');
    use MooseX::Types::Moose(':all');


    has name =>
    (
        is          => 'rw',
        isa         => Str,
        required    => 1,
    );


    has subscribers =>
    (
        traits      => ['Hash'],
        is          => 'rw', 
        isa         => HashRef[Subscriber], 
        default     => sub { {} },
        lazy        => 1,
        clearer     => 'clear_subscribers',
        handles     => {
            all_subscribers => 'values',
            has_subscribers => 'count',
            add_subscriber => 'set',
            remove_subscriber => 'delete',
            get_subscriber => 'get',
        }
    );


    has publisher =>
    (
        is          => 'rw',
        isa         => Str,
        predicate   => 'has_publisher',
    );


    has publishtype =>
    (
        is          => 'rw',
        isa         => PublishType,
        default     => +PUBLISH_OUTPUT,
        trigger     => 
        sub { 
            my ($self, $type) = @_;
            confess 'Cannot set publishtype to INPUT if there is no publisher' 
                if $type == +PUBLISH_INPUT and not $self->has_publisher;
        }
    );


    has input =>
    (
        is          => 'rw',
        isa         => Str,
        predicate   => 'has_input',
        trigger     => 
        sub {
            my ($self) = @_;
            confess 'Cannot set input on Event if publishtype is OUTPUT'
                if $self->publishtype == +PUBLISH_OUTPUT;
            confess 'Cannot set inout if there is no publisher'
                if not $self->has_publisher;
        },
    );
}

1;




__END__