[Xml-compile] patch for treating { array => 'scalar' } explicitly as an error in Writer.
hmepas
hmepas at gmail.com
Tue Jan 13 13:41:54 GMT 2015
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 <hmepas at gmail.com>
Jabber: hmepas at gmail.com
Skype: hmepas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20150113/a98f17a3/attachment.htm>
More information about the Xml-compile
mailing list