AMF-Perl
view release on metacpan or search on metacpan
doc/code.html view on Meta::CPAN
style="font-weight: bold;">To use AMF::Perl, download it
and install in the usual way (perl Makefile.PL; make; make install).<br><br>
To build/export .swf files with "Flash Remoting" you need to install
<a href=http://www.macromedia.com/software/flashremoting/downloads/components/>
Flash Remoting MX Components </a> (free download).
This will install the files "NetServices.as" and "NetDebug.as" that are
used in the ActionScript.
</span></big><br>
<hr style="width: 100%; height: 2px;"><big><span
style="font-weight: bold;"></span></big>
<h2>Sample code that uses Flash Remoting <br>
</h2>
(See also examples that are distributed with the module).
<br>
<a href=encoding.html>Read this</a> if you want to send and receive strings in non-English encodings.
<br><br>
Client code:<br>
<br>
<textarea cols=50 rows=30>
//Obligatory includes
#include "NetServices.as"
#include "NetDebug.as"
//Get a connection object
NetServices.setDefaultGatewayURL("http://host/cpu.pl");
connection = NetServices.createGatewayConnection();
//Get a pointer to a service
remoteService = connection.getService("Foo", this);
//Call a remote method on that service
remoteService.bar();
//or... send arguments to the server:
remoteService.bar(arg1, arg2);
//This callback function will be invoked
function bar_result(value)
{
//do something with the value
}
</textarea>
<br>
<h3> Server code, option A - service registration.</h3><br>
Use in simple applications.<br>
<table>
<tr><th>Perl</th><th>Python</th></tr>
<tr>
<td valign=top>
<textarea cols=50 rows=40>
use AMF::Perl;
package Foo;
sub new
{
my ($proto)=@_;
my $self={};
bless $self, $proto;
return $self;
}
sub bar
{
my ($self, $arg1, $arg2) = @_;
my $value;
#Compute a return value
#...
return $value;
}
#Create the gateway object
my $gateway = AMF::Perl->new;
#Register a service that provides methods.
#You can register more than one service.
#This can happen during server startup (if running under mod_perl).
$gateway->registerService("Foo",new Foo());
#Let the gateway figure out who will be called.
$gateway->service();
</textarea>
</td>
<td valign=top>
File cpu.py:
<textarea cols=50 rows=10>
import AMF
import cpuUsage
import sys
gateway = AMF.AMFPython.AMFPython()
gateway.registerService("CpuUsage",cpuUsage.cpuUsage())
gateway.service()
</textarea>
File cpuUsage.py:
<textarea cols=50 rows=20>
import os
import sys
import string
class cpuUsage:
def getCpuUsage(self, arg):
child = os.popen("uptime")
output = child.read()
tokens = output.split()
#Remove commas.
map(lambda x: x.replace(',', ''), tokens)
array = []
doc/code.html view on Meta::CPAN
Use in complex applications.<br>
<br>
<h3>Part 1. The gateway script.</h3><br>
<br>
<table>
<tr><th>Perl</th><th>Python</th></tr>
<tr>
<td valign=top>
<textarea cols=50 rows=20>
use AMF::Perl;
#Create the gateway object
my $gateway = AMF::Perl->new;
#Set a directory that will contain Perl package.
#Each package will correspond to one service -
#there can be as many as you want!
#You can set only one class path, though.
$gateway->setBaseClassPath("./basicservices/");
#Let the gateway figure out who will be called.
$gateway->service();
</textarea>
</td>
<td valign=top>
<textarea cols=50 rows=20>
#!/usr/bin/python
from AMF import AMF
import sys
import os
gateway = AMF.AMF()
gateway.setRelativeBaseClassPath("/basicservices")
gateway.service()
</textarea>
</td></tr></table>
<br>
<h3>Part 2. Sample class in the registered directory.</h3>
<table>
<tr><th>Perl</th><th>Python</th></tr>
<tr>
<td valign=top>
<textarea cols=50 rows=40>
package DataEcho;
sub new
{
my ($proto)=@_;
my $self={};
bless $self, $proto;
return $self;
}
sub echoNormal
{
my ($self, $data) = @_;
return $data;
}
sub echoDate
{
my ($self, $data) = @_;
return $data;
}
sub echoXML
{
my ($self, $data) = @_;
return $data;
}
sub methodTable
{
return {
"echoNormal" => {
"description" => "Echoes the passed argument back to Flash (no need to set the return t
ype)",
"access" => "remote", # available values are private, public, remote
},
"echoDate" => {
"description" => "Echoes a Flash Date Object (the returnType needs setting)",
"access" => "remote", # available values are private, public, remote
"returns" => "date"
},
"echoXML" => {
"description" => "Echoes a Flash XML Object (the returnType needs setting)",
"access" => "private", # available values are private, public, remote
"returns" => "xml"
}
};
}
1;
</textarea>
</td>
<td valign=top>
<textarea cols=50 rows=40>
import sys
class DataEcho:
def echoNormal(self, arg):
return arg
def echoDate(self, arg):
return arg
def echoXML(self, arg):
return arg
def methodTable(self):
table = {}
table["echoNormal"]= {
( run in 2.660 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )