Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Tying variables to remote objects

by Anonymous Monk
on Dec 19, 2001 at 15:33 UTC ( [id://133095]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to tie() a variable whose object will exist server-side (using SOAP). Any ideas? I don't know enough to know if this is possible. The application I'm thinking of is having a DBM file residing on a server which I can update easily from somewhere else on the network by just assigning key/values to a hash.

Replies are listed 'Best First'.
Re: Tying variables to remote objects
by simon.proctor (Vicar) on Dec 19, 2001 at 16:04 UTC
    I would suggest you consider something along the lines of a proxy object. You tie yourself to the proxy object and write the appropriate access methods to initiate the SOAP requests.

    The fetch and store commands would be the most likely candidiates for the actual SOAP requests. You would then provide additional logic for doing the useful stuff (like each(), keys() etc) which would operate on the data locally once it had been fetched.

    Suggest you look at the man page for tie or get the Advanced Perl Programming book. Either way - it should be a straightforward task. I would recommend that you build a comms object to actually initiate the SOAP comms and either inherit from it or use some form of aggregate relationship.

    You should have no problem doing either with tie.

    Hope that helps
      Cool idea! I don't see a reason why it can't be done. I've had some ideas of tying variables to CORBA objects. It would certainly make the CORBA interfaces much simpler, and would really give stuff like EJB a run for it's money.

      I think this concept could not only be used for SOAP or CORBA but also for POE. You'd need to do some serious planning and design to get this to work, but I'm sure it's feasible.

      -- Brett

      Go not to the Elves for counsel, for they will say both no and yes

        Oooo, This does raise some interesting options. Not long ago I was writing a CORBA system with Perl on the server and a Java client. Of course there are hashes all over on the server since the API is in Perl, but hashes aren't a basic type in Java, and they sure aren't in OMG IDL. My simple solution was to map hashes to multidimensional arrays in IDL, but then the client has to do a lot of nitpicking array handling (esp. since it's Java :P )

        A better idea might be a general IDL interface defining a set of hash functions. But on the server side it wouldn't work to tie the hash to the 'CORBAHash' b/c the tied hashes are just proxy objects, and the remote reference used by the client will necessarily point to the instance of CORBAHash, not the tied hash. So, on the server side, the CORBAHash would have to be a wrapper class around the hash with the data you want.

        What would be nice is to reverse the tie(), so that you could tie an instance of a class to a populated data structure, as in:

        tie($corba_hash, %$hash); return $corba_hash; # return to the client
        But then you might as well just pass the hash into the constructor of the remote implementation class. So, I think what you'd want is:
        bless($hash, 'CORBAHash'); $ORB->activate($hash); # register object with the ORB return $hash; # return to the client
        If the client were in Perl, you'd want to be able to say:
        tie(%hash, 'CORBAHash');
        To make this work I think you'd have to write the TIEHASH method to call a remote factory method, since the whole point is to tie the hash to a remote object. The factory method produces a remote object reference with the hash interface, and then it's just a matter of the local Perl interpreter to link the hash reference to the remote reference.

        Update: I'm using the COPE language binding for Perl.

Re: Tying variables to remote objects
by Hrunting (Pilgrim) on Dec 20, 2001 at 01:48 UTC
    SOAP is only worthwhile if you're using advanced features of SOAP and require the language-interoperability that comes with using XML. SOAP is necessarily slower than other forms for communication (because XML is a larger data type and because SOAP is so feature-bloated), and it also suffers from the overhead of encoding/decoding XML (if you were to do that, I'd use XML::LibXML, which is clearly the fastest perl XML parser so far).

    If you need the language-interoperability of XML but are only doing simple key-value interaction, use XML-RPC. XML-RPC is basically (very basically) cruft-less SOAP. Check CPAN for available modules (RPC::XML and Frontier::RPC come to mind). Even SOAP::Lite, the most feature-laden perl SOAP module comes with an XML-RPC version of its basic use.

    If you don't need the XML sort of interoperability (say, both ends of your application are perl-based), roll your own server-client app very simply using sockets and Storable. There are CPAN packages that enable you to setup very simple servers with minimal hassle, and Storable is very speedy for packaging up data and shipping it across networks.

    95% of the time, SOAP isn't needed. I used to know of a great article that outlined why XML-RPC should be used over SOAP most of the time, but I can't find it. Your case doesn't even sound like XML-RPC would be necessary.

      Another option which is possible (according to a previous poster) is to use CORBA. It also supplies language and architectural interoperability without the overhead of parsing XML. The speed should be very close to that of raw sockets given a decent IIOP (the CORBA on-the-wire protocol) implementation.
Re: Tying variables to remote objects
by Caelum (Acolyte) on Dec 19, 2001 at 22:05 UTC
    Don't know if this is practicable, but check out SOAP::Lite. Use it to export your module (GDBM_File or whatever). Then in the client connect with +autodispatch, the class will then be available to your code, and tie should work as well.

    One problem. GDBM_File and such are stateful modules, while SOAP servers generally expect to be stateless, although setting up a dedicated server with SOAP::Transport::HTTP might do the trick.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://133095]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found