From: Matt S Trout Date: Mon, 3 Sep 2018 21:13:36 +0000 (+0000) Subject: expression expansion pass, zeroth cut X-Git-Tag: v2.000000~3^2~508 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=705eac5c30af2b7a3c332750a68ec0f1801f5937;p=dbsrgits%2FSQL-Abstract.git expression expansion pass, zeroth cut --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 42e1e63..c5b9d19 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -535,14 +535,26 @@ sub where { return wantarray ? ($sql, @bind) : $sql; } +sub _expand_expr { + my ($self, $expr, $logic) = @_; + if (ref($expr) eq 'HASH' and keys %$expr > 1) { + $logic ||= 'and'; + return +{ "-${logic}" => [ + map +{ $_ => $expr->{$_} }, sort keys %$expr + ] }; + } + return $expr; +} sub _recurse_where { my ($self, $where, $logic) = @_; + my $where_exp = $self->_expand_expr($where, $logic); + # dispatch on appropriate method according to refkind of $where - my $method = $self->_METHOD_FOR_refkind("_where", $where); + my $method = $self->_METHOD_FOR_refkind("_where", $where_exp); - my ($sql, @bind) = $self->$method($where, $logic); + my ($sql, @bind) = $self->$method($where_exp, $logic); # DBIx::Class used to call _recurse_where in scalar context # something else might too...