<div dir="ltr"><div>Hey guys, Merry Xmas and Happy New Year!</div><div><br></div><div>When I send soap-requests from XML::Compile i could use structres like { array_element => 'something' } </div><div>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.</div><div><br></div><div>Patch could be something like this:</div><div><br></div><div>--- /usr/share/perl5/XML/Compile/Translate/Writer.pm 2014-05-28 11:46:49.000000000 +0400</div><div>+++ XML/Compile/Translate/Writer.pm 2015-01-13 16:34:57.503130405 +0300</div><div>@@ -267,6 +267,11 @@</div><div> ## Element</div><div> #</div><div><br></div><div>+sub _undef_or_arrayref {</div><div>+ my $values = $_[1];</div><div>+ return !defined $values || ref $values eq 'ARRAY';</div><div>+}</div><div>+</div><div> # see comment BlockHandler: undef means zero but success</div><div> sub makeElementHandler</div><div> { my ($self, $path, $label, $min,$max, $required, $optional) = @_;</div><div>@@ -275,8 +280,10 @@</div><div> if($min==0 && $max eq 'unbounded')</div><div> { return</div><div> sub { my ($doc, $values) = @_;</div><div>- my @values = ref $values eq 'ARRAY' ? @$values</div><div>- : defined $values ? $values : ();</div><div>+ error '{tag} if defined must be an array at {path}',</div><div>+ tag => $label, path => $path</div><div>+ unless $self->_undef_or_arrayref($values);</div><div>+ my @values = defined $values ? @$values : ();</div><div> @values ? map {$optional->($doc,$_)} @values : (undef);</div><div> };</div><div> }</div><div>@@ -284,8 +291,10 @@</div><div> if($max eq 'unbounded')</div><div> { return</div><div> sub { my ($doc, $values) = @_;</div><div>- my @values = ref $values eq 'ARRAY' ? @$values</div><div>- : defined $values ? $values : ();</div><div>+ error '{tag} must be an array at {path}',</div><div>+ tag => $label, path => $path</div><div>+ unless $self->_undef_or_arrayref($values);</div><div>+ my @values = defined $values ? @$values : ();</div><div> my @d = ( (map { $required->($doc, shift @values) } 1..$min)</div><div> , (map { $optional->($doc, $_) } @values) );</div><div> @d ? @d : (undef);</div><div>@@ -298,10 +307,13 @@</div><div> return $required</div><div> if $min==1 && $max==1;</div><div><br></div><div>- sub {</div><div>+ sub { # min, max <> {0,1} and max <> unbounded</div><div> my ($doc, $values) = @_;</div><div>- my @values</div><div>- = ref $values eq 'ARRAY' ? @$values : defined $values ? $values : ();</div><div>+ error '{tag} must be an array at {path}',</div><div>+ tag => $label, path => $path</div><div>+ unless $self->_undef_or_arrayref($values);</div><div>+</div><div>+ my @values = defined $values ? $values : ();</div><div><br></div><div> @values <= $max</div><div> or error "too many elements for `{tag}', max {max} found {nr} at {path}"</div><div><br></div><div>What do you think?</div><div><br></div>-- <br><div class="gmail_signature"><div>Pavel S. Khmelinsky <<a href="mailto:hmepas@gmail.com" target="_blank">hmepas@gmail.com</a>></div><div>Jabber: <a href="mailto:hmepas@gmail.com" target="_blank">hmepas@gmail.com</a></div><div>Skype: hmepas</div></div>
</div>