Tom Molesworth > Mixin-Event-Dispatch-1.004 > Mixin::Event::Dispatch::Event

Download:
Mixin-Event-Dispatch-1.004.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 1.004   Source   Latest Release: Mixin-Event-Dispatch-1.006

NAME ^

Mixin::Event::Dispatch::Event - an event object

VERSION ^

version 1.004

SYNOPSIS ^

 my $self = shift;
 my $ev = Mixin::Event::Dispatch::Event->new(
   name => 'some_event',
   instance => $self,
 );
 $ev->dispatch;

DESCRIPTION ^

Provides an object with which to interact with the current event.

METHODS ^

new

Takes the following (named) parameters:

We're assuming that time is of the essence, hence the peculiar implementation.

Returns $self.

READ-ONLY ACCESSORS ^

name

Returns the name of this event.

is_deferred

Returns true if this event has been deferred. This means another handler is active, and has allowed remaining handlers to take over the event - once those other handlers have finished the original handler will be resumed.

is_stopped

Returns true if this event has been stopped. This means no further handlers will be called.

instance

Returns the original object instance upon which the "invoke_event" in Mixin::Event::Dispatch method was called.

This may be different from the instance we're currently handling, for cases of event delegation for example.

parent

Returns the parent Mixin::Event::Dispatch::Event, if there was one. Usually there wasn't.

handlers

Returns a list of the remaining handlers for this event. Any that have already been called will be removed from this list.

stop

Stop processing for this event. Prevents any further event handlers from being called.

dispatch

Dispatches this event. Takes the parameters originally passed to "invoke_event" in Mixin::Event::Dispatch (with the exception of the event name), and passes it on to the defined handlers.

Returns $self.

play

Continue the current event. Semantincs are subject to change so avoid this and consider "defer" instead. Currently does nothing anyway.

Returns $self.

defer

Defers this event.

Causes remaining handlers to be called, and marks as "is_deferred".

 sub {
  my $ev = shift;
  print "Deferring\n";
  $ev->defer(@_);
  print "Finished deferring\n";
 }

Returns $self.

unsubscribe

Unsubscribes the current handler from the event that we're processing at the moment.

Can be used to implement one-shot or limited-lifetime event handlers:

 my $count = 0;
 $obj->subscribeto_event(
   som_event => sub {
     my $ev = shift;
     return $ev->unsubscribe if ++$count > 3;
     print "Current count: $count\n";
   }
 );
 $obj->invoke_event('some_event') for 1..5;

Returns $self.

debug_print

Show a debug message, should only be called if the appropriate (compile-time) flag is set:

 $self->debug_print(...) if DEBUG;

rather than expecting

 $self->debug_print(...);

to check for you.

Returns $self.

AUTHOR ^

Tom Molesworth <cpan@entitymodel.com>

LICENSE ^

Copyright Tom Molesworth 2012. Licensed under the same terms as Perl itself.

syntax highlighting: