NAME

org::puremvc::perl5::patterns::mediator::Mediator

inherits:

Base pureMVC Mediator concept implementation.


SYNOPSIS

A concrete Mediator implementor usually looks something like this:

  package com::me::myapp::mediators::AMediator;
  use strict; use warnings;
  use org::puremvc::perl5::patterns::mediator::Mediator;
  our @ISA = qw( org::puremvc::perl5::patterns::mediator::Mediator );
  #**********************
  #**********************
  sub listNotificationInterests {
    return ["ANotification"];
  }
  #**********************
  sub handleNotification {
    my ( $self, $note ) = @_;
  
    my $note_name = $note->getName();
  
    return unless $note_name eq "ANotification";
  
    print "AMediator reacted to notification ANotification\n";
  }
  #**********************
  sub onRegister {
    print "AMediator registered\n";
  }
  #**********************
  sub onRemove {
    print "AMediator removed\n";
  }
  #**********************
  #**********************
  1;


DESCRIPTION

In PureMVC, Mediator implementors assume these responsibilities:

Additionally, mediators typically:

When a Mediator is registered with the View, the View will call the Mediator's listNotificationInterests method. The Mediator will return an array of notification names which it wishes to be notified about.

The View will then create an Observer object encapsulating that Mediator's (handleNotification) method and register it as an observer for each notification name returned by listNotificationInterests.


INTERFACE

Methods

new

sub new( $mediator_name, $view_component );

It is common to define a default name for your Mediator class implementation by mean of a constant:

  use constant NAME => "com::me::myapp::mediators::AMediator";

To register an instance of your Mediator class you can then do so:

  use com::me::myapp::mediators::AMediator;
  
  my $facade = org::puremvc::perl5::patterns::facade::Facade->getInstance();
  my $mediator = com::me::myapp::mediators::AMediator->new( com::me::myapp::mediators::AMediator::NAME );
  $facade->registerMediator($mediator);

It is possible to register several instances of the same Mediator class. You must then give different names to each instance registration in order to fully qualify them in your application:

  use com::me::myapp::mediators::AMediator;
  
  my $facade = org::puremvc::perl5::patterns::facade::Facade->getInstance();
  my $mediator = com::me::myapp::mediators::AMediator->new( com::me::myapp::mediators::AMediator::NAME );
  $facade->registerMediator($mediator);
  my $other_mediator = com::me::myapp::mediators::AMediator->new( "SOME_OTHER_NAME" );
  $facade->registerMediator($other_mediator);

Parameters

getMediatorName

sub getMediatorName();

Returns the name by which a Mediator was registered with the View.

Returns

String - The name by which a Mediator was registered with the View.

getViewComponent

sub getViewComponent();

Returns the Mediator's view component.

Returns

* - The view component.

setViewComponent

sub setViewComponent( $view_component );

Sets the Mediator's view component.

Parameters

listNotificationInterests

sub listNotificationInterests();

Returns an array reference holding the notification names the Mediator is interested in being notified of.

When your application will dispatch a notification whose name matches one of those in the array, the handleNotification method of the Mediator will be automatically called.

Returns

\ARRAY - The reference on the array holding the notifications' name.

handleNotification

sub handleNotification( $notification );

This method is automatically called by the view if $notification's name is one of those returned by listNotificationInterests method.

Parameters

onRegister

sub onRegister();

Called by the view when the Mediator is registered.

onRemove

sub onRemove();

Called by the view when the Mediator is removed.


SEE ALSO

org::puremvc::perl5::core::Model

org::puremvc::perl5::core::View

org::puremvc::perl5::core::Controller

org::puremvc::perl5::patterns::facade::Facade

org::puremvc::perl5::patterns::observer::Notification

org::puremvc::perl5::patterns::proxy::Proxy

org::puremvc::perl5::patterns::command::SimpleCommand

org::puremvc::perl5::patterns::command::MacroCommand

org::puremvc::perl5::patterns::observer::Notifier

org::puremvc::perl5::patterns::observer::Observer