GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Event::Notify(3) User Contributed Perl Documentation Event::Notify(3)

Event::Notify - Simple Observer/Notifier

  use Event::Notify;

  my $notify = Event::Notify->new;
  $notify->register( $observer );
  $notify->register_event( $event, $observer );
  $notify->notify( $event, @args );

Event::Notify implements a simple Observer pattern. It's not really intended to be subclassed, or a fancy system. It just registers observers, and broadcasts events, that's it. The simplicity is that it can be embedded in a class that doesn't necessarily want to be a subclass of a notifier.

Simply create a slot for it, and delegate methods to it:

  package MyClass;
  use Event::Notify;

  sub new {
    my $class = shift;
    my $self = shift;
    $self->{notify} = Event::Notify->new;
  }

  # This interface doesn't have to be this way. Here, we're just making
  # a simple delegation mechanism 
  sub register_event { shift->{notify}->register_event(@_) }
  sub unregister_event { shift->{notify}->unregister_event(@_) }
  sub notify { shift->{notify}->notify(@_) }

Voila, you got yourself a observable module without inheritance!

Creates a new instance

Registers a new observer. The observer must implement a notify() method.

When called, the observer's register() method is invoked, so each observer can register itself to whatever event the observer wants to subscribe to.

So your observer's register() method could do something like this:

  package MyObserver;
  sub register {
    my ($observer, $notify) = @_;
    $notify->register_event( 'event_name1', $observer );
    $notify->register_event( 'event_name2', $observer );
    $notify->register_event( 'event_name3', $observer );
    $notify->register_event( 'event_name4', $observer );
  }

Think of it as sort of an automatic initializer.

Registers an observer $observer as observing a particular event $event The $observer can be either an object or a subroutine reference.

In case $observer is an object, the object must implement a method named "notify()", or the method name specified the "method" parameter in the optional third parameter %opts

Calling

  $notify->register_event($event, $observer);

is the same as saying

  $notify->register_event($event, $observer, { method => 'notify' });

If the object does not implement the named method (or "notify()", if you don't specify one), then it will croak

Unregisters an observer.

Notifies all of the observers about a particular event. @args is passed directly to the observers' notify() event

Clears all observers from this object.

Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

2007-11-29 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.