AMF-Perl

 view release on metacpan or  search on metacpan

doc/code.html  view on Meta::CPAN

//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>
&nbsp; <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-&gt;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-&gt;registerService("Foo",new Foo());

#Let the gateway figure out who will be called.
$gateway-&gt;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 = []
        hash = {'Name' : 'L 1', 'Value' : tokens[9]}
        array.append(hash)
        hash = {'Name' : 'L 5', 'Value' : tokens[10]}
        array.append(hash)
        hash = {'Name' : 'L 15', 'Value' : tokens[11]}
        array.append(hash)
        return array

</textarea>
</td>
</tr></table>
<h3> Server code, option B - limited service discovery.</h3><br>
Use in complex applications.<br>
      <br>
<h3>Part 1.&nbsp; The gateway script.</h3><br>
      <br>
<table>
<tr><th>Perl</th><th>Python</th></tr>
    <tr>
<td valign=top>



( run in 1.452 second using v1.01-cache-2.11-cpan-39bf76dae61 )