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

When dispatching to a perl sub, it seems like the perl sub needs to return it's values wrapped in SOAP objects (i.e. I need to return

return (SOAP::Data->name(version=>'123')->type('string'));

to get
<version>123</version>
(simplified)

Is there a way to make the wrapper itself to apply this to the return values?
The purpose is to keep my subroutines "clean", so that their return values work both with SOAP and "ordinary" function calls.

Replies are listed 'Best First'.
Re: SOAP::Lite server - returning non-SOAP values in sub
by i5513 (Pilgrim) on Aug 25, 2011 at 14:38 UTC
    If you know how to distinguish between "soap" and ordinary function, then
    sub mysub { my $result; fill the code to get $result ok if ($soap) # $soap is true if this function is called from a webser +vice { $result=SOAP::Data...($result)....; } return $result; }
    Maybe I lost something in your question..
      Hi, What I want is that the caller to wrap the return values in soap tags, so that i don't have to add logic in the subs themselves. In this way I can call existing subs without altering them. Of course I need some way to "name" the return values, but I thought that this maybe is possible?

      I guess I could wrap the subs up manually, using a "mysub_soap", whose only mission is to call mysub, wrap the return from mysub in tags, and return it.
        Its called a subclass, also, a serializer

        one way with Autoloading

        ->dispatch_to('MyModule::SOAPIFY'); ... package MyModule::SOAPIFY; @ISA = qw[ MyModule ]; sub thisMethodNeedsSpecificWrapping { ... } sub AUTOLOAD { ... GenericWrapper... }