Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] SOAP::Lite tutorial comment

Expand Messages
  • Bryce Harrington
    ... I tend to agree. I found I needed to insert fault handling code between each of those. I ended up doing something like this... sub main { # Connect to
    Message 1 of 2 , Mar 4, 2005
    • 0 Attachment
      On Fri, 4 Mar 2005, Medi Montaseri wrote:
      > Here is a typical example, keep in mind that we have
      > a novice user who is trying to learn a new technology but is
      > confronted with short cuts and idioms of a language.
      >
      > print SOAP::Lite
      > -> service()
      > -> proxy()
      > -> someMethod()
      > -> result ;
      >
      > If it was me, I'd write my tutorials like this
      >
      > my $soap = SOAP::Lite->new();
      > my $svc = $soap->service();
      > my $proxy = $svc->proxy();
      > my $response = $proxy->someMethod();
      > my $result = $response->result();
      >
      > print "result = $result \n";
      >
      > In my opinion, the $obj->method()->method()->method() chaining
      > while sexy is not debugable as any of the nodes along the way
      > could've given away. And the interpreter would say line x has problem

      I tend to agree. I found I needed to insert fault handling code between
      each of those. I ended up doing something like this...


      sub main {
      # Connect to the server
      my $soap = create_soap_instance($opt_resource, $opt_server);

      # Create the test service object
      my $response = $soap->call(new => 1);
      soap_assert($response);
      my $testsys = $response->result;

      if (! $testsys) {
      die "Could not create testsys object\n";
      }

      $response = $soap->get_software_types($testsys);
      soap_assert($response);

      if (! $response->result) {
      warn "No results received\n";
      return -1;
      }

      foreach my $row (@{$response->result}) {
      print $row->{software_type}, "\n";
      }
      return 1;
      }


      sub create_soap_instance {
      my $resource = shift || return undef;
      my $server = shift || return undef;

      my $soap = SOAP::Lite
      -> uri($resource)
      -> proxy($server,
      options => {compress_threshold => 10000});
      return $soap;
      };

      sub soap_assert {
      my $response = shift;
      if ($response->fault) {
      print join ', ',
      $response->faultcode,
      $response->faultstring;
      return undef;
      }
      return 1;
      }


      I think the soap_assert() routine is quite valuable, since it allows
      ample use of fault handling without cluttering the main routine into
      unreadibility. I found with the tutorials that the way they were
      written made it especially difficult to figure out my own newbie
      mistakes, and that if fault handling code had been liberally included,
      such as above, I would have gotten error messages much more easily, and
      learned SOAP::Lite faster.

      Bryce
    Your message has been successfully submitted and would be delivered to recipients shortly.