Mixin::Event::Dispatch::Event - an event object
version 1.004
my $self = shift; my $ev = Mixin::Event::Dispatch::Event->new( name => 'some_event', instance => $self, ); $ev->dispatch;
Provides an object with which to interact with the current event.
Takes the following (named) parameters:
name - the name of this event
instance - the originating instance
parent - another Mixin::Event::Dispatch::Event object if we were invoked within an existing handler
handlers - the list of handlers for this event
We're assuming that time is of the essence, hence the peculiar implementation.
Returns $self.
Returns the name of this event.
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.
Returns true if this event has been stopped. This means no further handlers will be called.
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.
Returns the parent Mixin::Event::Dispatch::Event, if there was one. Usually there wasn't.
Returns a list of the remaining handlers for this event. Any that have already been called will be removed from this list.
Stop processing for this event. Prevents any further event handlers from being called.
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.
Continue the current event. Semantincs are subject to change so avoid this and consider "defer" instead. Currently does nothing anyway.
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"; }
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;
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.
Tom Molesworth <cpan@entitymodel.com>
Copyright Tom Molesworth 2012. Licensed under the same terms as Perl itself.
To install Mixin::Event::Dispatch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mixin::Event::Dispatch
CPAN shell
perl -MCPAN -e shell install Mixin::Event::Dispatch
For more information on module installation, please visit the detailed CPAN module installation guide.