| Path: | lib/mues/events/event.rb (CVS) |
| Last Update: | Sat Aug 18 22:54:10 -0700 2007 |
This file contains the MUES::Event class — an abstract base class for MUES events. All events in the MUES must inherit from this class in order to be recognized by the event dispatcher.
You probably shouldn‘t require this file directly unless you‘re subclassing MUES::Event directly, as you can load all event classes with:
require 'mues/events'
Events in MUES are dispatched via the dispatchEvents method of the Engine (the MUES::Engine instance) to an event queue (a MUES::EventQueue object). When a thread in the event queue‘s thread pool becomes available, the event is dispatched to any interested objects.
In order to register an object‘s interest in a class of events, it must register with the event class in question. It can do so either by calling the RegisterHandlers() method on the event class with itself as the argument, or by calling the registerHandlerForEvents() function (which is a private global method defined in MUES::Object) with the event classes of interest as arguments.
Objects which want to be able to receive events need to implement a public ‘handleEvent’ method. You can mix in a default multiple-dispatch handler method by includeing the MUES::Event::Handler module.
Event registration is hierarchal, so registering with one class also effectively registers the object with any events derived from it. So, for example, an object which wanted to get passed both MUES::InputEvents and MUES::OutputEvents would only need to register with MUES::IOEvent, as the former two inherit from the latter.
For more about the finer details of event dispatch from the event queue, see the MUES::EventQueue documentation.
require 'mues/events'
module MUES
class MyEvent < MUES::Event
:
end
class MySubEvent < MyEventType
:
end
end
class MyClass < MUES::Object
# Register all instances to recieve MyEvent and
# MySubEvent events:
def initialize
super
MyEvent::registerHandlers( self )
end
def handleEvents( *events )
:
end
end
$Id: event.rb 1206 2004-05-09 21:25:11Z deveiant $
Copyright (c) 2000-2003 The FaerieMUD Consortium. All rights reserved.
This module is free software. You may use, modify, and/or redistribute this software under the terms of the Perl Artistic License. (See language.perl.com/misc/Artistic.html)
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.