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

SOAP::Lite tutorial comment

Expand Messages
  • Medi Montaseri
    One of the problems my peers often point out against Perl is that there are 25 different ways of doing things, from $$ to $PID. from key, value to key =
    Message 1 of 2 , Mar 3, 2005
    • 0 Attachment
      One of the problems my peers often point out against Perl is that
      there are 25 different ways of doing things, from $$ to $PID.
      from "key, value" to "key => value", etc.

      So I say to them, that is Perl's strength...

      However, I fail to see the author's motivation for using
      object-message-sequencing approach in his SOAP::Lite's tutorials
      and man pages. IMHO, the author should've chosen easy-perl
      over cool-perl style.

      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 ;

      I'll not bore you with the dereferencing operator and when
      () should be used and when not and how white spaces are cleaned up
      by the interpreter (including newline chars).
      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

      If there is some technical reason for coding like this, I'd like
      to learn, other wise, may I ask the author to consider this input.


      Thank you
    • 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 2 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.