From 50c8d5b31fcccaceb14d06ed8c3a67143bc358f9 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Thu, 21 Aug 2014 07:26:30 -0400 Subject: [PATCH] oh, look, ComplexType.pm has cut and paste hash reversing code from SimpleType.pm. that means that we can cut and paste the fix from SimpleType.pm into ComplexType.pm. how many wrongs make a right? I forget. --- lib/SOAP/WSDL/XSD/ComplexType.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/SOAP/WSDL/XSD/ComplexType.pm b/lib/SOAP/WSDL/XSD/ComplexType.pm index e6a3f44..b130417 100644 --- a/lib/SOAP/WSDL/XSD/ComplexType.pm +++ b/lib/SOAP/WSDL/XSD/ComplexType.pm @@ -98,9 +98,18 @@ sub serialize { if ( $opt->{ autotype }) { my $ns = $self->get_targetNamespace(); # reverse namespace by prefix hash - my %prefix_of = reverse %{ $opt->{ namespace } }; - my $prefix = $prefix_of{ $ns } - || die 'No prefix found for namespace '. $ns; + + # build a list of hash keys (eg '#default', 'tns') whose values match our namespace (eg 'urn:myNamespace') + (my @possible_namespace_names) = grep { $opt->{ namespace }->{$_} eq $ns } keys %{ $opt->{ namespace } }; + + # put any '#default' option last + @possible_namespace_names = sort { $a eq '#default' ? 1 : $b eq '#default' ? -1 : $a cmp $b } @possible_namespace_names; + + if( grep( $_ ne '#default', @possible_namespace_names ) > 1 or ! @possible_namespace_names ) { + die "no or too many possible names for our namespace of ``$ns'': ``@possible_namespace_names''; there should be just one and maybe a '#default' entry"; + } + my $prefix = $possible_namespace_names[0]; + $xml .= join q{}, " type=\"$prefix:", $self->get_name(), '" ' if ($self->get_name() ); }