Hi Monks,
I'm trying to create a webservices wrapper for a module whose structure doesn't seem to be compatible with direct dispatching. I need to build up a bunch of state before executing the module calls from the server, but there seems to be concurrency issues with the approach I'm taking, and wonder if anyone can spot my mistake in the following stub.
Server:
#!perl -w
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::Daemon
->new(LocalPort=>1111,ReuseAddr=>1)
-> dispatch_to('TestWrapper')
-> handle;
package TestWrapper;
use Data::Dumper;
sub new {
my $self = shift;
my $class = ref($self) || $self;
return bless {} => $class;
}
sub put {
my ($self, $key, $val) = @_;
$self->{_HASH}{$key} = $val;
}
sub get {
my ($self, $key) = @_;
return $self->{_HASH}{$key};
}
1;
Client:
use strict;
use warnings;
use SOAP::Lite;
my $soap = SOAP::Lite
-> uri('http://localhost:1111/TestWrapper')
-> proxy('http://localhost:1111/');
my $t1 = $soap->new();
$t1->put('element1', 'value1');
my $t2 = $soap->new();
$t2->put('element1', 'value2')->result;
printf("t1 : %s\n", $t1->get('element1')->result);
printf("t2 : %s\n", $t2->get('element1')->result);
I'm currently getting the following output from the client:
$ perl client.pl
t1 : value2
t2 : value2
Both references seem to end up pointing at the same object, causing the hash entry to get overwritten, and this even happens if I create the objects in two separate scripts and run them concurrently. However, if I create the objects directly (i.e. not via SOAP), everything works as expected:
use TestWrapper;
my $t1 = new TestWrapper;
$t1->put('element1', 'value1');
my $t2 = new TestWrapper;
$t2->put('element1', 'value2');
printf("t1 : %s\n", $t1->get('element1'));
printf("t2 : %s\n", $t2->get('element1'));
output:
$ perl standalone.pl
t1 : value1
t2 : value2
Any input would be most appreciated. I'm using ActivePerl 5.14 and SOAP::Lite 0.714.