NAME
IO::Multiplex::Intermediary::Client - base controller for the server
SYNOPSIS
package Controller;
use Moose;
extends 'IO::Multiplex::Intermediary';
around build_response => sub {
my $orig = shift;
my $self = shift;
my $response = $self->$orig(@_);
return rot13($response);
};
around connect_hook => sub {
my $orig = shift;
my $self = shift;
my $data = shift;
$players{ $data->{data}{id} } = new_player;
return $self->$orig(@_);
};
around input_hook => sub {
my $orig = shift;
my $self = shift;
return $self->$orig(@_);
};
around disconnect_hook => sub {
my $orig = shift;
my $self = shift;
my $data = shift;
delete $player{ $data->{data}{id} };
return $self->$orig($data, @_);
};
DESCRIPTION
WARNING! THIS MODULE HAS BEEN DEEMED ALPHA BY THE AUTHOR. THE API MAY CHANGE IN SUBSEQUENT VERSIONS.
The flow of the controller starts when an end connection sends a command. The controller figures out who sent the command and relays it to the logic that reads the command and comes up with a response (Application).
Connections
|
v
Server
^
|
V
Client
^
|
v
Application
ATTRIBUTES
This module supplies you with these attributes which you can pass to the constructor as named arguments:
host
-
This attribute is for the host on which the server runs.
port
-
This attribute is for the host on which the server runs on.
METHODS
run
-
Starts the client, which connects to the intermediary and waits for input to respond to.
send($id, $message)
-
Tells the intermediary to output
$message
to the user with the ID$id
.
HOOKS
These are internal methods with the primary purposes of hooking from the outside for a more flexible and extensive use.
build_response
-
This hook is a method that you want to hook for doing your response handling and output manipulateion (see the "SYNOPSIS" section). As the method stands,
build_response
returns exactly what was input to the method, making the application a simple echo server. connect_hook
-
This hook runs after a user connects. It returns JSON data that tells the intermediary that it has acknowledge the user has connected.
input_hook
-
This hook runs after the intermediary sends an input request. It returns a JSON output request which contains the response build by
build_response
. disconnect_hook
-
This hook runs after a user disconnects. It has the same behavior as the
connect_hook
method, just with disconnect information. tick
-
This hook runs on the second every second. By itself, it is does not do anything. Hooking from other applications is its only purpose.
AUTHOR
Jason May <jason.a.may@gmail.com>
LICENSE
This library is free software and may be distributed under the same terms as perl itself.