App-Modular

 view release on metacpan or  search on metacpan

t/events/Events.mom  view on Meta::CPAN

#!/usr/bin/perl -w
#----------------------------------------------------------------------------
#   App::Modular::Module::Events - perl program modularization framewok
#                                 event handler class
#
#   Copyright (c) 2003-2004 Baltasar Cevc
#
#   This code is released under the L<perlartistic> Perl Artistic
#   License, which can should be accessible via the C<perldoc
#   perlartistic> command and the file COPYING provided with this
#
#   DISCLAIMER: THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND
#   COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
#   IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY
#   OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE
#   OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
#   TRADEMARKS OR OTHER RIGHTS.
#   IF YOU USE THIS SOFTWARE, YOU DO SO AT YOUR OWN RISK.
#
#   See this internet site for more details: http://technik.juz-kirchheim.de/
#
#   Creation:       30.07.04    bc
#   Last Update:    17.02.05    bc
#   Version:         0. 1. 1  
# ----------------------------------------------------------------------------

###################
###             ###
###    INIT     ###
###             ###
################### 
package App::Modular::Module::Events;
use base qw(App::Modular::Module);

###################
###    Pragma   ###
###################
use strict;
use warnings;

###################
### Dependencies###
###################
use 5.006_001;

###################
###  Version    ###
###################
our ($VERSION);
$VERSION = 0.001_001;

###################
### Constructor ###
###################
sub module_init {
   my ($type) = @_;

   my $self = $type->SUPER::module_init($type);

   $self->{'events'} = {};

   return $self;
};

t/events/Events.mom  view on Meta::CPAN

###             ###
###DOCUMENTATION###
###             ###
###################
=pod

=head1 NAME

B<App::Modular::Module::Events> - event handling for App::Modular compatible
applications

=head1 SYNOPSIS

	####################################################################
	package App::Modular::Module::Me;

	use base qw(App::Modular::Module);

	sub depends { return 'Events'; }

	sub start_listen {
	   my $self = shift;

	   $self->{'modularizer'}->module('Events')->
	      register('Listener', 'TelephoneRings');
	};

	sub event_handler {
	   my $self = shift;
	   my $event = shift;
	   print 'Yeah! Somebody thought about me!'
	      if ($event eq 'TelephoneRings');
	};

	####################################################################
	package App::Modular::Module::You;

	use base qw(App::Modular::Module);

	sub depends { return 'Events'; }

	sub call_me { 
	   $self->{'modularizer'}->module('Events')->
	      trigger('TelephoneRings');
	};

	####################################################################
	package main;

	use App::Modular;

	my $modul = instance App::Modular;

	$modul->module('Me')->start_listen();
	$modul->module('You')->callme();

	exit;

=head1 DESCRIPTION

App::Modular aims to provide a framework which should it make very
easy to programmes to create any kind of modular program.

This module provides basic event handling as a contribution to that toolkit.
Modules may register themselves as listeners for events, if an event is
triggered, all the modules are notified by calling 
C<$module-\>event_handler('event', @params)>.

The events are speciefied as simple strings.

=head1 REFERENCE

In this man page, you will only find the method descriptions fror hte App::Modular 
object; the standard functions of the application modules can be found in 
L<App::Modular::Module>.

=head2 Methods

=over 4

=item listeners (string event_name)

Return an array of all modules that listen for an given event.

Return value: (array of strings) module_name(s)

=item module_init (void)

Init the module -> nothing you have to worry about, App::Modular will take
care of everything needed.

Return value: (blessed hash reference) object 

=item deregister (string module_name, string event_name)

Stop listening to an event (deregister a module as listener).

Return value: (none)

=item deregister_byevent (string event_name)

Deregister all listeners for an event, effectively removing that event.

Return value: (void)

=item deregister_bymodule (string module_name)

Make a module stop listening to all events. Useful before unloading modules.

Return value: (none)

=item register (string module_name, string event_name)

Register a listener for a given event. (A module calls this function in
order to start listening to an event).

Return value: (array) module_name(s) of all listeners

=item trigger (string event_name, [argument1, [argument2, [...]]])

Trigger an event (call the funtion event_handler of all modules registered



( run in 0.589 second using v1.01-cache-2.11-cpan-df04353d9ac )