From hmepas at gmail.com Tue Jan 13 13:41:54 2015 From: hmepas at gmail.com (hmepas) Date: Tue, 13 Jan 2015 16:41:54 +0300 Subject: [Xml-compile] patch for treating { array => 'scalar' } explicitly as an error in Writer. Message-ID: Hey guys, Merry Xmas and Happy New Year! When I send soap-requests from XML::Compile i could use structres like { array_element => 'something' } Where array_element defined with maxOccur > 1. And XML::Compile will quietly treat it as [ 'something' ] provided. In my practice, if I as a programmer providing scalar where array ref expected it's most of the time just honest mistake, like @values beside \@values, and for me would be more expected behaviour is to just have errors then this happens. Patch could be something like this: --- /usr/share/perl5/XML/Compile/Translate/Writer.pm 2014-05-28 11:46:49.000000000 +0400 +++ XML/Compile/Translate/Writer.pm 2015-01-13 16:34:57.503130405 +0300 @@ -267,6 +267,11 @@ ## Element # +sub _undef_or_arrayref { + my $values = $_[1]; + return !defined $values || ref $values eq 'ARRAY'; +} + # see comment BlockHandler: undef means zero but success sub makeElementHandler { my ($self, $path, $label, $min,$max, $required, $optional) = @_; @@ -275,8 +280,10 @@ if($min==0 && $max eq 'unbounded') { return sub { my ($doc, $values) = @_; - my @values = ref $values eq 'ARRAY' ? @$values - : defined $values ? $values : (); + error '{tag} if defined must be an array at {path}', + tag => $label, path => $path + unless $self->_undef_or_arrayref($values); + my @values = defined $values ? @$values : (); @values ? map {$optional->($doc,$_)} @values : (undef); }; } @@ -284,8 +291,10 @@ if($max eq 'unbounded') { return sub { my ($doc, $values) = @_; - my @values = ref $values eq 'ARRAY' ? @$values - : defined $values ? $values : (); + error '{tag} must be an array at {path}', + tag => $label, path => $path + unless $self->_undef_or_arrayref($values); + my @values = defined $values ? @$values : (); my @d = ( (map { $required->($doc, shift @values) } 1..$min) , (map { $optional->($doc, $_) } @values) ); @d ? @d : (undef); @@ -298,10 +307,13 @@ return $required if $min==1 && $max==1; - sub { + sub { # min, max <> {0,1} and max <> unbounded my ($doc, $values) = @_; - my @values - = ref $values eq 'ARRAY' ? @$values : defined $values ? $values : (); + error '{tag} must be an array at {path}', + tag => $label, path => $path + unless $self->_undef_or_arrayref($values); + + my @values = defined $values ? $values : (); @values <= $max or error "too many elements for `{tag}', max {max} found {nr} at {path}" What do you think? -- Pavel S. Khmelinsky Jabber: hmepas at gmail.com Skype: hmepas -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at overmeer.net Sun Jan 18 20:26:19 2015 From: mark at overmeer.net (Mark Overmeer) Date: Sun, 18 Jan 2015 21:26:19 +0100 Subject: [Xml-compile] patch for treating { array => 'scalar' } explicitly as an error in Writer. In-Reply-To: References: Message-ID: <20150118202619.GA24478@moon.overmeer.net> * hmepas (hmepas at gmail.com) [150118 15:11]: > When I send soap-requests from XML::Compile i could use structres like > { array_element => 'something' } > Where array_element defined with maxOccur > 1. And XML::Compile will > quietly treat it as [ 'something' ] provided. In my practice, if I as a > programmer providing scalar where array ref expected it's most of the time > just honest mistake, like @values beside \@values, and for me would be more > expected behaviour is to just have errors then this happens. The writer offers a little more flexibility than the reader. In this case: the reader will always produce item => ['foo'] but the writer with accept both item => ['foo'] as item => 'foo' . Very very often, the schema permits to include more than one element, but it is never used with more than one element. Those additional array [] make the code less readible. . I have seen elements change over schema versions from default maxOccurs=1 into maxOccurs > 1. In this case, the offered flexibility helps: the old code works with the new schema. . It's quite confusing that the 'item' is signular, but you always have to give it an array. It has bitten me a few times until I had enough of it. So: the flexibility is on purpose and does help coders. It is not accidental. I will not change the code for the simple reason of backwards compatibility. I'll only break that when the code produces incorrect results. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark at Overmeer.net solutions at overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net From hmepas at gmail.com Sun Jan 18 21:15:50 2015 From: hmepas at gmail.com (hmepas) Date: Mon, 19 Jan 2015 00:15:50 +0300 Subject: [Xml-compile] patch for treating { array => 'scalar' } explicitly as an error in Writer. In-Reply-To: <20150118202619.GA24478@moon.overmeer.net> References: <20150118202619.GA24478@moon.overmeer.net> Message-ID: Well to avoid back-compability issues it could be an optional, with default state to be back compatible. On Sun, Jan 18, 2015 at 11:26 PM, Mark Overmeer wrote: > * hmepas (hmepas at gmail.com) [150118 15:11]: > > When I send soap-requests from XML::Compile i could use structres like > > { array_element => 'something' } > > Where array_element defined with maxOccur > 1. And XML::Compile will > > quietly treat it as [ 'something' ] provided. In my practice, if I as a > > programmer providing scalar where array ref expected it's most of the > time > > just honest mistake, like @values beside \@values, and for me would be > more > > expected behaviour is to just have errors then this happens. > > The writer offers a little more flexibility than the reader. In this > case: > the reader will always produce item => ['foo'] > but the writer with accept both item => ['foo'] as item => 'foo' > > . Very very often, the schema permits to include more than one element, > but it is never used with more than one element. Those additional > array [] make the code less readible. > > . I have seen elements change over schema versions from default > maxOccurs=1 into maxOccurs > 1. In this case, the offered > flexibility helps: the old code works with the new schema. > > . It's quite confusing that the 'item' is signular, but you always > have to give it an array. It has bitten me a few times until > I had enough of it. > > So: the flexibility is on purpose and does help coders. It is not > accidental. > > I will not change the code for the simple reason of backwards > compatibility. I'll only break that when the code produces > incorrect results. > -- > Regards, > > MarkOv > > ------------------------------------------------------------------------ > Mark Overmeer MSc MARKOV Solutions > Mark at Overmeer.net solutions at overmeer.net > http://Mark.Overmeer.net http://solutions.overmeer.net > > -- Pavel S. Khmelinsky Jabber: hmepas at gmail.com Skype: hmepas -------------- next part -------------- An HTML attachment was scrubbed... URL: From papowell at astart.com Sat Jan 31 17:51:02 2015 From: papowell at astart.com (Patrick Powell) Date: Sat, 31 Jan 2015 09:51:02 -0800 Subject: [Xml-compile] Updated XML::Compile::*, get wsdl-soap.xsd does not exist error Message-ID: <54CD1606.8020702@astart.com> Old Versions: XML-Compile-1.44 XML-Compile-Cache-1.02 XML-Compile-Dumper-0.13_1 XML-Compile-SOAP-2.38 XML-Compile-SOAP-Daemon-3.06 XML-Compile-SOAP-WSA-0.12 XML-Compile-Tester-0.90 New Versions: XML-Compile-1.48 XML-Compile-Cache-1.03 XML-Compile-Dumper-0.13_2 XML-Compile-SOAP-3.07 XML-Compile-SOAP-Daemon-3.11 XML-Compile-SOAP-WSA-0.12_1 XML-Compile-Tester-0.90_1 XML-Compile-WSDL11-3.03 With the new version I get the following error: [Sat Jan 31 08:55:00.507934 2015] [perl:error] [pid 1966] error: file /usr/local/lib/perl5/site_perl/XML/Compile/WSDL11/xsd/wsdl-soap.xsd does not exist\n\t...propagated at /usr/local/lib/perl5/site_perl/Log/Report.pm line 143.\nCompilation failed in require at (eval 2) line 1.\n Before I jump into an extended debugging session, did I miss some announcements about a new version/update? -- Patrick Powell Astart Technologies papowell at astart.com 1530 Jamacha Rd, Suite X Network and System San Diego, CA 92019 Consulting 858-874-6543 FAX 858-751-2435 Web: www.astart.com From papowell at astart.com Sat Jan 31 17:55:14 2015 From: papowell at astart.com (Patrick Powell) Date: Sat, 31 Jan 2015 09:55:14 -0800 Subject: [Xml-compile] Updated XML::Compile::*, get wsdl-soap.xsd does not exist error In-Reply-To: <54CD1606.8020702@astart.com> References: <54CD1606.8020702@astart.com> Message-ID: <54CD1702.9050208@astart.com> Ooops, I left out a bit of information: wsdl-soap.xsd was installed by package XML-Compile-SOAP-2.38 On 01/31/15 09:51, Patrick Powell wrote: > Old Versions: > > XML-Compile-1.44 > XML-Compile-Cache-1.02 > XML-Compile-Dumper-0.13_1 > XML-Compile-SOAP-2.38 > XML-Compile-SOAP-Daemon-3.06 > XML-Compile-SOAP-WSA-0.12 > XML-Compile-Tester-0.90 > > New Versions: > > XML-Compile-1.48 > XML-Compile-Cache-1.03 > XML-Compile-Dumper-0.13_2 > XML-Compile-SOAP-3.07 > XML-Compile-SOAP-Daemon-3.11 > XML-Compile-SOAP-WSA-0.12_1 > XML-Compile-Tester-0.90_1 > XML-Compile-WSDL11-3.03 > > With the new version I get the following error: > > [Sat Jan 31 08:55:00.507934 2015] [perl:error] [pid 1966] error: file > /usr/local/lib/perl5/site_perl/XML/Compile/WSDL11/xsd/wsdl-soap.xsd > does not exist\n\t...propagated at > /usr/local/lib/perl5/site_perl/Log/Report.pm line 143.\nCompilation > failed in require at (eval 2) line 1.\n > > Before I jump into an extended debugging session, did I miss some > announcements about a new version/update? > -- Patrick Powell Astart Technologies papowell at astart.com 1530 Jamacha Rd, Suite X Network and System San Diego, CA 92019 Consulting 858-874-6543 FAX 858-751-2435 Web: www.astart.com From mark at overmeer.net Sat Jan 31 22:07:37 2015 From: mark at overmeer.net (Mark Overmeer) Date: Sat, 31 Jan 2015 23:07:37 +0100 Subject: [Xml-compile] Updated XML::Compile::*, get wsdl-soap.xsd does not exist error In-Reply-To: <54CD1606.8020702@astart.com> References: <54CD1606.8020702@astart.com> Message-ID: <20150131220737.GA6190@moon.overmeer.net> * Patrick Powell (papowell at astart.com) [150131 17:51]: > [Sat Jan 31 08:55:00.507934 2015] [perl:error] [pid 1966] error: > file /usr/local/lib/perl5/site_perl/XML/Compile/WSDL11/xsd/wsdl-soap.xsd > does not exist\n\t...propagated at > /usr/local/lib/perl5/site_perl/Log/Report.pm line 143.\nCompilation > failed in require at (eval 2) line 1.\n > > Before I jump into an extended debugging session, did I miss some > announcements about a new version/update? Between your old and your new version collection, WSDL11 got split off from SOAP11. This file is part of SOAP11, because it defines the rules for SOAP11 inside the WSDL11. When I look in the package: http://cpansearch.perl.org/src/MARKOV/XML-Compile-SOAP-3.07/lib/XML/Compile/WSDL11/xsd/ You see that the file is present in the distribution. . Do you find the file of the location of that error? (is the error wrong or the file really missing?) . can you check the version of file /usr/local/lib/perl5/site_perl/XML/Compile/SOAP11.pm . Try reinstalling XML::Compile:SOAP11 and check in the output whether that xsd gets installed. I use this combination myself without problems. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark at Overmeer.net solutions at overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net