org::puremvc::perl5::patterns::proxy::Proxy
inherits:
Implementation of the pureMVC Proxy
pattern.
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;
In PureMVC, Proxy
implementors assume these responsibilities:
Implement a common method which returns the name of the Proxy
.
Provide methods for setting and getting the data object.
Additionally, proxies typically:
Maintain references to one or more pieces of model data.
Provide methods for manipulating that data.
Generate notification when their model data changes.
Encapsulate interaction with local or remote services used to fetch and persist model data.
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
$proxy_name - String
Name by which any retrieval, removal, or existence checking will be achieved in your application.
$data - *
Object instance representing business data - Optional.
Proxy
name getter.
Returns
String
- The proxy's
name.
Proxy
's local data setter.
Parameters
$data - *
Object instance or scalar representing business data.
Proxy
's local data getter.
Returns
*
- Proxy
's local data object or scalar.
Called by the model when the Proxy
is registered.
Called by the model when the Proxy
is removed.
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