detect disabled ops earlier and fail
Matt S Trout [Sat, 21 Sep 2019 20:15:00 +0000 (20:15 +0000)]
lib/SQL/Abstract.pm
t/21op_ident.t

index 79c6300..4b4c08f 100644 (file)
@@ -686,19 +686,6 @@ sub _expand_hashpair_op {
 
   my $op = $self->_normalize_op($k);
 
-  if (my $exp = $self->{expand}{$op}) {
-    return $self->$exp($op, $v);
-  }
-
-  # Ops prefixed with -not_ get converted
-
-  if (my ($rest) = $op =~/^not_(.*)$/) {
-    return +{ -op => [
-      'not',
-      $self->_expand_expr({ "-${rest}", $v })
-    ] };
-  }
-
   { # Old SQLA compat
 
     my $op = join(' ', split '_', $op);
@@ -717,9 +704,27 @@ sub _expand_hashpair_op {
     ) {
       puke "Illegal use of top-level '-$op'"
     }
+  }
+
+  if (my $exp = $self->{expand}{$op}) {
+    return $self->$exp($op, $v);
+  }
+
+  # Ops prefixed with -not_ get converted
+
+  if (my ($rest) = $op =~/^not_(.*)$/) {
+    return +{ -op => [
+      'not',
+      $self->_expand_expr({ "-${rest}", $v })
+    ] };
+  }
+
+  { # Old SQLA compat
 
     # the old unary op system means we should touch nothing and let it work
 
+    my $op = join(' ', split '_', $op);
+
     if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
       return { -op => [ $op, $v ] };
     }
index 7fe09d3..d73b11c 100644 (file)
@@ -17,6 +17,16 @@ for my $q ('', '"') {
     $sql_maker->where({ foo => { -ident => undef } })
   } qr/-ident requires a single plain scalar argument/;
 
+  throws_ok {
+    local $sql_maker->{disable_old_special_ops} = 1;
+    $sql_maker->where({'-or' => [{'-ident' => 'foo'},'foo']})
+  } qr/Illegal.*top-level/;
+
+  throws_ok {
+    local $sql_maker->{disable_old_special_ops} = 1;
+    $sql_maker->where({'-or' => [{'-ident' => 'foo'},{'=' => \'bozz'}]})
+  } qr/Illegal.*top-level/;
+
   my ($sql, @bind) = $sql_maker->select('artist', '*', { 'artist.name' => { -ident => 'artist.pseudonym' } } );
   is_same_sql_bind (
     $sql,