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

MONKS!- I have packages I use for RPC, but I'd also like to use them locally... I don't want my RPC packages to use local packages via RPC -- they exists on the same machine (for now).

Using Apache session IDs as the 2nd parameter (1st is package name) for the methods, I can make them 'instances' over the network. But I don't need the session ID when called locally.

Also, my packages available via RPC have a superclass that handles all the session restoring/saving, error handling, authentication, common RPCish methods. But, I don't need locally used (or derived) packages to have this derivation.

Is there a compiling directive that would be able to tell what was calling a package: RPC or locally (forcing mod_perl to recomile)? Is there a better model out there to follow? Each of my methods will have to have logic to dermine if it's called 'static', 'instance', then 'static-rpc', 'instance-rpc'... uuf!

Replies are listed 'Best First'.
Re: XMLRPC Object Model?
by perrin (Chancellor) on Mar 29, 2002 at 05:54 UTC
    If you receive different parameters in the different situations, you can certainly load different modules, or dispatch calls to different methods. However, it sounds to me like you used inheritance when you shouldn't have. Maybe instead of this RPC superclass, what you need is a class that implements the actual functionality in a way that's independent of location, and then some other classes that act as wrappers around it and translate as necessary for RPC, local, etc.
      Doing a HAS-A probably would be better, or...

      I could provide two constructors in the base class, 1) that would return a blessed scalar (the apache session ID), and another for local use, determined by caller(), that returns a blessed hash... that sounds like fun!

      sub joe_method { my $self = ref ($_[0] eq 'SCALAR') ? getSessionHashRef(shift) : sh +ift; # getSessionHashRef exists in base class, or... # MyApacheSessionHelper->getSessionHashRef (shift) ... }
      Actually, calling by RPC, the 1st arg would be (for me) SOAP::Lite. So the above should be:

      sub joe_method { my $self = ref (shift eq 'SOAP::Lite') ? getSessionHashRef(shift) +: $_; ... }

      The blessed scaler (the sessionID) would be usefull for a proxy class -- wrapper for the RPC call -- client-side.