eliminate IS special op usage
[dbsrgits/SQL-Abstract.git] / lib / SQL / Abstract.pm
index 0f412aa..d83da8c 100644 (file)
@@ -40,8 +40,8 @@ my @BUILTIN_SPECIAL_OPS = (
   {regex => qr/^ (?: not \s )? between $/ix, handler => sub { die "NOPE" }},
   {regex => qr/^ (?: not \s )? in      $/ix, handler => sub { die "NOPE" }},
   {regex => qr/^ ident                 $/ix, handler => sub { die "NOPE" }},
-  {regex => qr/^ value                 $/ix, handler => '_where_op_VALUE'},
-  {regex => qr/^ is (?: \s+ not )?     $/ix, handler => '_where_field_IS'},
+  {regex => qr/^ value                 $/ix, handler => sub { die "NOPE" }},
+  {regex => qr/^ is (?: \s+ not )?     $/ix, handler => sub { die "NOPE" }},
 );
 
 # unaryish operators - key maps to handler
@@ -701,6 +701,25 @@ sub _expand_expr_hashpair {
           { -ident => $vv }
         ] };
       }
+      if ($vk eq 'value') {
+        return $self->_expand_expr_hashpair($k, undef) unless defined($vv);
+        return +{ -op => [
+          $self->{cmp},
+          { -ident => $k },
+          { -bind => [ $k, $vv ] }
+        ] };
+      }
+      if ($vk =~ /^is(?:[ _]not)?$/) {
+        puke "$vk can only take undef as argument"
+          if defined($vv)
+             and not (
+               ref($vv) eq 'HASH'
+               and exists($vv->{-value})
+               and !defined($vv->{-value})
+             );
+        $vk =~ s/_/ /g;
+        return +{ -op => [ $vk.' null', { -ident => $k } ] };
+      }
     }
     if (ref($v) eq 'ARRAY') {
       return $self->{sqlfalse} unless @$v;