From: Matt S Trout Date: Mon, 3 Sep 2018 21:13:36 +0000 (+0000) Subject: expression expansion pass, zeroth cut X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a2cd381d85ba3da6add5de91ac241d5ead4477e1;p=scpubgit%2FQ-Branch.git expression expansion pass, zeroth cut --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index f9ee1e5..3327db7 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...