fixups for HAVING clauses
[dbsrgits/Data-Query.git] / lib / Data / Query / ExprBuilder.pm
index 9e12dd6..0c8ee7b 100644 (file)
@@ -1,31 +1,34 @@
 package Data::Query::ExprBuilder;
 
 use strictures 1;
-use Data::Query::Constants qw(DQ_OPERATOR DQ_VALUE);
 use Scalar::Util ();
+use Data::Query::ExprHelpers qw(perl_scalar_value perl_operator);
 
 use overload (
+  # unary operators
+  (map {
+    my $op = $_;
+    $op => sub {
+      Data::Query::ExprBuilder->new({
+        expr => perl_operator($op => $_[0]->{expr})
+      });
+    }
+  } qw(! neg)),
   # binary operators
   (map {
     my ($overload, $as) = ref($_) ? @$_ : ($_, $_);
     $overload => sub {
       Data::Query::ExprBuilder->new({
-        expr => {
-          type => DQ_OPERATOR,
-          operator => { perl => $as },
-          args => [
+        expr => perl_operator(
+           $as,
            map {
              (Scalar::Util::blessed($_)
              && $_->isa('Data::Query::ExprBuilder'))
                ? $_->{expr}
-               : {
-                   type => DQ_VALUE,
-                   subtype => { perl => 'Scalar' },
-                   value => $_
-                 }
+               : perl_scalar_value($_)
+              # we're called with ($left, $right, 0) or ($right, $left, 1)
             } $_[2] ? @_[1,0] : @_[0,1]
-          ]
-        },
+          )
       });
     }
   }