From: Matt S Trout Date: Fri, 7 Sep 2018 23:44:57 +0000 (+0000) Subject: expand top level arrays X-Git-Tag: v2.000000~3^2~497 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=495fb7ce707f33784bf1f3057ae420359527e1a5;p=dbsrgits%2FSQL-Abstract.git expand top level arrays --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index b4b7c06..de447fa 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -549,6 +549,32 @@ sub _expand_expr { } return $self->_expand_expr_hashpair(%$expr, $logic); } + if (ref($expr) eq 'ARRAY') { + $logic = lc($logic || $self->{logic}); + $logic eq 'and' or $logic eq 'or' or puke "unknown logic: $logic"; + + my @expr = @$expr; + + my @res; + + while (my ($el) = splice @expr, 0, 1) { + puke "Supplying an empty left hand side argument is not supported in array-pairs" + unless defined($el) and length($el); + my $elref = ref($el); + if (!$elref) { + push(@res, $self->_expand_expr({ $el, shift(@expr) })); + } elsif ($elref eq 'ARRAY') { + push(@res, $self->_expand_expr($el)) if @$el; + } elsif (is_literal_value($el)) { + push @res, $el; + } elsif ($elref eq 'HASH') { + push @res, $self->_expand_expr($el); + } else { + die "unimplemented" + } + } + return { '-'.$logic => \@res }; + } return $expr; }