SOAP::Lite is a suite of Perl modules for doing SOAP RPC. SOAP::Lite was originally written by mad Russians. Its incredible flexibility is also it’s main drawback. Debugging isn’t as obvious as it could be with this library.

Most of the time you the would-be SOAP scripter want to know what the request and response XML messages look like. The SOAP::Trace doc doesn’t make this clear (since the sample code is filled with mistakes). Here is one way to get SOAP to spew the XML messages to STDOUT they way you’d expect from a more humble module like Frontier::Client.

use SOAP::Lite "trace" => ["transport" => \&log_it];
sub log_it {
  my ($in) = @_;

  if (ref $in && $in->can("content")) {
    printf "**GOT: %sn", (ref $in);
    print "-"x60, "n";
    print $in->content, "n";
    print "-"x60, "n";
  }

}

There’s a lot of fun things going on in the log_it() subroutine.
Notice the use of the oft-forgotten can() method, which all Perl objects have. Yes, this is a very special code review.

Should SOAP::Lite have a simple flag like “trace_xml” which does all this for you? Sure it should. But until then, you’ve got this humble blog and your old Uncle jjohn to help you.

Now get the hell off my lawn, you kids!