rekoil (rekoil) wrote in perl,
rekoil
rekoil
perl

SOAP::Lite madness!

There's obviously something very fundamental I'm missing when if comes to object-oriented programming using SOAP::Lite.



First off, this is how I'm used to building objects locally - nothing fancy here:

/usr/bin/perl -w

BEGIN   {

   package TestClass;

   sub new {
       my $class = shift;
       my $self = {};
       $self->{testval} = "test";
       return (bless ($self, $class));
   }

   sub test    {
       my $self = shift;
       return $self->{testval};
   }
}

my $testobj = new TestClass;

print $testobj->test() . "\n";


Running this returns the "test" string as it should.

However, the same function adapted for a SOAP call using SOAP::Lite gives me errors with similar syntax:

Server side:

#!/usr/bin/perl -w

use strict;

use SOAP::Transport::HTTP;

my $daemon = new SOAP::Transport::HTTP::Daemon (LocalPort => 8080);
$daemon->dispatch_to('Test');
$daemon->handle;

BEGIN   {
       package Test;

       sub new {
               my $class = shift;
               my $self = {};
               $self->{testval} = "test";
               return (bless ($self, $class));
       }

       sub test        {
               my $self = shift;
               return $self->{testval};
       }

}


Client side:

#!/usr/bin/perl -w
use strict;
use SOAP::Lite;

my $testobj = new SOAP::Lite
   ->ns('http://test.server.com:8080/Test')
   ->proxy('http://test.server.com:8080');

my $query = $testobj->test();

if ($query->fault)  {
          print "Error: (" . $query->faultcode() . ") " . $query->faultstring() . "\n";
}

print $query->result . "\n";


When I run this I get:

Error: (soap:Server) Can't use string ("Test") as a HASH ref while "strict refs" in use at soaptestserver2.pl line 23.


Sure enough, if I add the line "print Data::Dumper($self) in the test() function, I get:

$VAR1 = 'Test';


So it's obvious that no actual object is getting passed around, just the class name.

I'm obviously missing something rather fundamental here. Is it even possible to do what I'm trying to do? If so, what am I doing wrong?


Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 6 comments