NAME

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

Singleton responsible for executing commands in response to a notification.


DESCRIPTION

In PureMVC, the Controller class follows the 'Command and Controller' strategy, and assumes these responsibilities:

Your application must register commands with the Controller.

The simplest way is to subclass Facade class, and use its initializeController method to add your registrations.


INTERFACE

Methods

getInstance

sub getInstance();

Returns the singleton instance of the Controller.

Returns

org::puremvc::perl5::core::Controller - The singleton instance of the Controller.

initializeController

sub initializeController();

Initialize the singleton instance of the Controller. This method is automatically called during singleton instantiation.

Note that if you are using a subclass of View in your application, you should also subclass Controller and override the initializeController method in the following way:

  # ensure that the Controller is talking to my View implementation
  sub initializeController {
    my $self = shift;
  
    $self->{_view} = com::me::myapp::MyView->getInstance() unless exists $self->{_view};
  }
registerCommand

sub registerCommand( $notification_name, $command_class_ref );

Register a particular command class as the handler for a particular notification.

$command_class_ref is a string holding the name of the command class, e.g. "com::me::myapp::MyCommand".

If a command has already been registered to handle notification with this name, it is no longer used, the new command is used instead.

The observer for the new command is only created if this the first time a command has been registered for this notification name.

Parameters

executeCommand

sub executeCommand( $notification );

If a command has previously been registered to handle a given notification, then it is executed.

Parameters

removeCommand

sub removeCommand( $notification_name );

Remove a previously registered command for a given notification name.

Parameters

hasCommand

sub hasCommand( $notification_name );

Check whether a command is registered for a given notification name.

Parameters

Returns

scalar - 1 if a Command class is registered with the Controller for notifications named $notification_name, "" otherwise.

Properties

_commands

Array reference on registered commands with the Controller. You should not have to access it and must not update it in normal usage.


SEE ALSO

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

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

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

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

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

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

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

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

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

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