I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-11-19 05:08:42-08 by mbrf
Returning array references with only one entry
Hi all, I have several complex types which are added as ARRAY references to the main data %hash. If there is only one entry, not several, perl internally uses only a HASH, not an array, and the generated XML looks different. Without this code here I get perl errors in the client like "Not an ARRAY reference at" ... Any elegant ways to solve this so I could skip thoses checks ? Other SOAP-Kits contain options like "forcearray = 1" to force this.
my $type = ref( $response->{'List'} ); if ($type eq "ARRAY") { foreach my $userentry (@{$response->{'List'}}) { $user = $userentry->{'Item'}->{'User'}; [...] } else { $user = $response->{List}->{'Item'}->{'User'}; [...] }
-- Martin
Direct Responses: 11783 | Write a response
Posted on 2009-11-20 04:19:54-08 by noah in response to 11776
Re: Returning array references with only one entry

AFAIK, there's no way to force this; indeed, SOAP::WSDL::Deserializer::Hash explicitly states that this is the behavior.

When I've encountered this issue, I've done something like the following:

my $list = ref( $response->{'List'} ) eq 'ARRAY' ? $response->{'List'} : [$response->{'List'}];

This ensures I always have an arrayref with which to work.

--noah
Direct Responses: 11785 | Write a response
Posted on 2009-11-20 05:02:14-08 by noah in response to 11783
Re: Returning array references with only one entry

Following up to myself, I'm obviously on crack by referencing SOAP::WSDL::Deserializer::Hash in this context, since the XSD deserializer is obviously in play. I may have time to poke at this a bit more over the weekend, but time is limited.

--noah
Direct Responses: 11795 | Write a response
Posted on 2009-11-21 04:48:36-08 by mbrf in response to 11785
Re: Returning array references with only one entry
Hi, Nope, you were right, I've used SOAP::WSDL::Deserializer::Hash, but found out
that SOAP::WSDL::Deserializer::XSD does it right. Something like this works
there without error:

foreach $flag (@$flagsref) { $flags .= $flag->get_Item() . ","; } $flags =~ s/,$//;

Looks like the following code in SOAP::WSDL::Expat::Message2Hash may be the problem ...
>if (ref $list->[-1]->{ $_element } eq 'ARRAY') { > $list->[-1]->{ $_element }->[-1] = $characters ; >} >else { > $list->[-1]->{ $_element } = $characters; >}
I've converted now everthing to SOAP::WSDL::Deserializer::XSD and the problem is solved for me.

-- Martin
Direct Responses: Write a response