arrayref logic can just use $self
[scpubgit/Q-Branch.git] / lib / SQL / Abstract.pm
index 6fabda2..c2570bf 100644 (file)
@@ -193,6 +193,7 @@ sub new {
     -bool => '_expand_bool',
     -and => '_expand_andor',
     -or => '_expand_andor',
+    -nest => '_expand_nest',
   };
 
   $opt{expand_op} = {
@@ -208,6 +209,7 @@ sub new {
         $self->_expand_expr({ '-'.$op => $arg }),
       ] };
     }), qw(ident value)),
+    'nest' => '_expand_nest',
   };
 
   $opt{render} = {
@@ -557,8 +559,7 @@ sub _expand_expr {
   if (ref($expr) eq 'HASH') {
     return undef unless my $kc = keys %$expr;
     if ($kc > 1) {
-      $logic ||= 'and';
-      return $self->_expand_andor("-${logic}", $expr);
+      return $self->_expand_andor(-and => $expr);
     }
     my ($key, $value) = %$expr;
     if ($key =~ /^-/ and $key =~ s/ [_\s]? \d+ $//x ) {
@@ -571,7 +572,7 @@ sub _expand_expr {
     return $self->_expand_expr_hashpair($key, $value, $logic);
   }
   if (ref($expr) eq 'ARRAY') {
-    my $logic = lc($logic || $self->{logic});
+    my $logic = lc($self->{logic});
     return $self->_expand_andor("-${logic}", $expr);
   }
   if (my $literal = is_literal_value($expr)) {
@@ -595,22 +596,8 @@ sub _expand_expr_hashpair {
     }
     puke "Supplying an empty left hand side argument is not supported";
   }
+  $self->_assert_pass_injection_guard($k =~ /^-(.*)$/s) if $k =~ /^-/;
   if ($k =~ /^-/) {
-    $self->_assert_pass_injection_guard($k =~ /^-(.*)$/s);
-    if ($k eq '-nest') {
-      # DBIx::Class requires a nest warning to be emitted once but the private
-      # method it overrode to do so no longer exists
-      if ($self->{is_dbic_sqlmaker}) {
-        unless (our $Nest_Warned) {
-          belch(
-            "-nest in search conditions is deprecated, you most probably wanted:\n"
-            .q|{..., -and => [ \%cond0, \@cond1, \'cond2', \[ 'cond3', [ col => bind ] ], etc. ], ... }|
-          );
-          $Nest_Warned = 1;
-        }
-      }
-      return $self->_expand_expr($v);
-    }
     if (my ($rest) = $k =~/^-not[_ ](.*)$/) {
       return +{ -op => [
         'not',
@@ -709,13 +696,10 @@ sub _expand_expr_hashpair {
       return +{ -op => [ $op.' null', $self->_expand_ident(-ident => $k) ] };
     }
     if ($op =~ /^(and|or)$/) {
-      if (ref($vv) eq 'HASH') {
-        return +{ -op => [
-          $op,
-          map $self->_expand_expr({ $k, { $_ => $vv->{$_} } }),
-            sort keys %$vv
-        ] };
-      }
+      return $self->_expand_andor('-'.$op, [
+        map +{ $k, { $_ => $vv->{$_} } },
+          sort keys %$vv
+      ]);
     }
     if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}}) {
       return { -op => [ $op, $self->_expand_ident(-ident => $k), $vv ] };
@@ -790,9 +774,9 @@ sub _expand_expr_hashpair {
         ? shift(@{$v = [ @$v ]})
         : '-'.($self->{logic} || 'or')
     );
-    return $self->_expand_expr({
+    return $self->_expand_andor(
       $this_logic => [ map +{ $k => $_ }, @$v ]
-    });
+    );
   }
   if (my $literal = is_literal_value($v)) {
     unless (length $k) {
@@ -937,6 +921,22 @@ sub _expand_in {
   ] };
 }
 
+sub _expand_nest {
+  my ($self, $op, $v) = @_;
+  # DBIx::Class requires a nest warning to be emitted once but the private
+  # method it overrode to do so no longer exists
+  if ($self->{is_dbic_sqlmaker}) {
+    unless (our $Nest_Warned) {
+      belch(
+        "-nest in search conditions is deprecated, you most probably wanted:\n"
+        .q|{..., -and => [ \%cond0, \@cond1, \'cond2', \[ 'cond3', [ col => bind ] ], etc. ], ... }|
+      );
+      $Nest_Warned = 1;
+    }
+  }
+  return $self->_expand_expr($v);
+}
+
 sub _recurse_where {
   my ($self, $where, $logic) = @_;