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

Hello again, Monks of Perl.

I have an obscure question about SOAP::Lite and how it dispatches.

I have a package that reports information about a machine that it lives on. It has no new() method and cannot be used as an object (by design). I also have a separate SOAP service script that needs to invoke the functions in that package and send the data back to the client caller. The overall idea is that you can use the package locally as a normal package or remotely via a SOAP::Lite client.

Now for the problem. SOAP::Transport appears to only dispatch to the package as an object. As a result, $self needs to be shifted out of all of my functions. And since the package doesn't have a new() method, using it locally requires something like "Full::Package::Name->function()", which is undesirable.

So, finally, my question is: Is there a way to prevent SOAP::Transport from dispatching to a package/module as an object? I got a tip somewhere that I might need to write a custom dispatcher, but I'm not sure how to do that or where to look-up on how to do that. If anyone could give me some insight on this or point me in the right direction, it would much appriciated.

Let me know if any of that was unclear. Thanks in advance!

Replies are listed 'Best First'.
Re: SOAP object style method dispatching
by rhesa (Vicar) on Dec 07, 2006 at 17:45 UTC
    First off, I don't think there's a way to change the behavior of SOAP::Lite directly. Writing a custom dispatch class isn't all that hard, since the basic method pattern looks like this:
    sub some_function { my $self = shift; return Some::Other::Package::function( @_ ); }
    Besides writing them by hand, you can autogenerate those in a number of ways. One way is using string eval; another could be to mimick what modules such as Class::Accessor do for method generation.
Re: SOAP object style method dispatching
by jbert (Priest) on Dec 07, 2006 at 22:11 UTC
    Alternatively, wrap your package in a (presumably singleton) object. Do a traditional ->new based constructor with methods which proxy back to you object-free package methods.

    It could possibly be done with some AUTOLOAD or meta-programming fun, but doing it directly might not be too hard either.

Re: SOAP object style method dispatching
by timecatalyst (Acolyte) on Dec 08, 2006 at 13:51 UTC
    Thanks for the feedback, guys/gals. I was tinkering with AUTOLOADER for a bit, but haven't gotten it to do quite what I want yet. I'll keep plugging at it and possibly write something up if I get it working. Thanks again.