The reference to the remote SCALAR, $remote_ref, can be used as a normal reference, but all the changes made to it will be applied remotely too. And the alias, $local_scalar, make all the use easier, since all the changes done to this scalar, that seems to be a normal scalar, will be applied to the remote SCALAR returned by eval(). Note that the internal value of the remote SCALAR will never exists in the local interpreter, soo for each acces or change to a variable, a communication will exits between the RPO Server and the RPO Client.use RPO ; ## Remote Perl Objects ## Set the value of a SCALAR remotely: RPO::CLIENT->eval('$scalar = 123'); ## Get the reference to this SCALAR: my $remote_ref = RPO::CLIENT->eval('\$scalar') ; ## Use the SCALAR reference normally, but making changes remotely: $$remote_ref = 'xyz' ; ## Define $local_scalar as an alias to the remote scalar: my $local_scalar ; RPO::ALIAS(\$local_scalar , $remote_ref) ; ## Append some data to the previous scalar value ('xyz'): $local_scalar .= 'abc' ; ## The remote value now should be 'xyzabc': print RPO::CLIENT->eval('return $scalar') ;
Who make all the magic is the method RPO::CLIENT->eval(), where any reference that it returns, is transformed to a bridge between the RPO Server and the RPO Client. Soo, you don't need to care of how to create all this remote objects, you just return a reference, that also can be an object, and you have it working remotely.
For now I only have SCALAR, ARRAY and HASH working remotely. I still need to implement the GLOB and IO types, to after this can implement Objects and packages. I'm still thinking in the best way to do that, since the hard work starts now, soo I will appreciate suggestions about the architecture.
The main purpose of this module is to use Perl modules without need to install them, since with this resource you can use a remote object without actually have the class of this object locally. Also will be possible to make function calls that are holded remotely, actually will be possible to have a package that actually runs in other interpreter, since the main idea is to have everything transparent.
You can download the development code at:
http://www.inf.ufsc.br/~gmpassos/RPO-0.01-beta.tar.gz
Enjoy and send your comments. ;-P
UPDATE
Here's some complex usage with HASH and what happens in the backstages.
## Set the value of a HASH remotely: RPO::CLIENT->eval('%hash = ( a=>1 , b=>2 , c=>{ d=>3.1 , e=>3.2 } )' +); ## Get the reference to this HASH: my $ref = RPO::CLIENT->eval('\%hash') ; ## Define the alias: my %hash ; RPO::ALIAS(\%hash , $ref) ; ## store '11': $hash{a} = 11 ; ## fetch 'a': print "$hash{a}\n" ; ## fetch 'c', what returns a new remote HASH ## reference, and fetch 'd': print "$hash{c}{d}\n" ; my $scalar_ref = RPO::CLIENT->eval('\$scalar') ; RPO::ALIAS(\$scalar , $scalar_ref) ; ## fetch 'c', what returns a new remote HASH ## fetch $scalar and ## store into 'e' in the returned HASH in 'c'. $hash{c}{e} = $scalar ;
Graciliano M. P.
"Creativity is the expression of the liberty".
Edited by BazB shorted title slightly from "Using Objects and basic types (SCALAR, ARRAY, HASH...) from other Perl interpreters transparently (as a normal Perl variable and reference)"
|
|---|