Start testing/writing API compatability layer
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / Compat.pm
index 1b231dd..2fd21c6 100644 (file)
@@ -1,6 +1,65 @@
 use MooseX::Declare;
 
 class SQL::Abstract::Compat {
+
+  use Moose::Util::TypeConstraints;
+  use MooseX::Types::Moose qw/Str ScalarRef ArrayRef HashRef/;
+  use SQL::Abstract::Types::Compat ':all';
+  use SQL::Abstract::AST::Compat;
+  use SQL::Abstract::AST::v1;
+  use Data::Dump qw/pp/;
+
+  class_type 'SQL::Abstract';
+  clean;
+
+  has logic => (
+    is => 'rw',
+    isa => LogicEnum,
+    default => 'AND'
+  );
+
+  has visitor => (
+    is => 'rw',
+    isa => 'SQL::Abstract',
+    clearer => 'clear_visitor',
+    lazy => 1,
+    builder => '_build_visitor',
+  );
+
+
+  method select(Str|ArrayRef|ScalarRef $from, ArrayRef|Str $fields,
+                WhereType $where?,
+                WhereType $order?)
+  {
+
+    my $ast = $self->_new_compat_ast->select($from,$fields,$where,$order);
+    pp($ast);
+
+    return ($self->visitor->dispatch($ast), $self->visitor->binds);
+  }
+
+  method where(WhereType $where,
+               WhereType $order?)
+  {
+    my $ret = "";
+    if ($where) {
+      my $ast = $self->_new_compat_ast->generate($where);
+      $ret .= "WHERE " . $self->visitor->_expr($ast);
+    }
+
+    return $ret;
+  }
+
+  #TODO: Handle logic and similar args later
+  method _new_compat_ast() {
+    return SQL::Abstract::AST::Compat->new;
+  }
+
+  method _build_visitor() {
+    return SQL::Abstract->create(1);
+  } 
+
 }
 
 =head1 NAME