NAME

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

inherits:

Implementation of the pureMVC Proxy pattern.


SYNOPSIS

  package com::me::myapp::proxies::AProxy;
  use strict; use warnings;
  use org::puremvc::perl5::patterns::proxy::Proxy;
  our @ISA = qw( org::puremvc::perl5::patterns::proxy::Proxy );
  #**********************
  #**********************
  sub onRegister {
    my $self = shift;
  
    $self->sendNotification("ANotification");
  }
  #**********************
  sub onRemove {
    print "AProxy removed\n";
  
  }
  #**********************
  #**********************
  1;


DESCRIPTION

In PureMVC, Proxy implementors assume these responsibilities:

Additionally, proxies typically:


INTERFACE

Methods

new

sub new( $proxy_name, $data );

Constructor.

A Proxy might simply manage a reference to a local data object, in which case interacting with it might involve setting and getting of its data in synchronous fashion.

Proxy classes are also used to encapsulate the application's interaction with remote services to save or retrieve data, in which case, we adopt an asyncronous idiom; setting data (or calling a method) on the Proxy and listening for a notification to be sent when the Proxy has retrieved the data from the service.

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

  use constant NAME => "com::me::myapp::proxies::AProxy";

To register an instance of your Proxy class you can then do as follows:

  use com::me::myapp::proxies::AProxy;
  
  my $facade = org::puremvc::perl5::patterns::facade::Facade->getInstance();
  my $proxy = com::me::myapp::proxies::AProxy->new( com::me::myapp::proxies::AProxy::NAME );
  $facade->registerProxy($proxy);

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

  use com::me::myapp::proxies::AProxy;
  
  my $facade = org::puremvc::perl5::patterns::facade::Facade->getInstance();
  my $proxy = com::me::myapp::proxies::AProxy->new( com::me::myapp::proxies::AProxy::NAME );
  $facade->registerProxy($proxy);
  my $other_proxy = com::me::myapp::proxies::AProxy->new( "SOME_OTHER_NAME" );
  $facade->registerProxy($other_proxy);

Parameters

getProxyName

sub getProxyName();

Proxy name getter.

Returns

String - The proxy's name.

setData

sub setData( $data );

Proxy's local data setter.

Parameters

getData

sub getData( $data );

Proxy's local data getter.

Returns

* - Proxy's local data object or scalar.

onRegister

sub onRegister();

Called by the model when the Proxy is registered.

onRemove

sub onRemove();

Called by the model when the Proxy 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::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