LEFT JOIN + rework join tests
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / AST / v1.pm
index 2596c63..0ce6e9f 100644 (file)
@@ -69,18 +69,26 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract {
   }
 
   method _join(HashRef $ast) {
+    confess "'args' option to join should be an array ref, not " . dump($ast->{args})
+      unless is_ArrayRef($ast->{args});
+
     my ($from, $to) = @{ $ast->{args} };
+
+    # TODO: Validate join type
+    my $type = $ast->{join_type} || "";
   
-    my $output = $self->dispatch($from)
-               . ' JOIN ' 
-               . $self->dispatch($to);
+    my @output = $self->dispatch($from);
+
+    push @output, uc $type if $type;
+    push @output, "JOIN", $self->dispatch($to);
 
-    $output .= exists $ast->{on}
-             ? ' ON (' . $self->_expr( $ast->{on} )
-             : ' USING (' .$self->dispatch($ast->{using} || croak "No 'on' or 'join' clause passed to -join");
+    push @output, 
+        exists $ast->{on}
+      ? ('ON', '(' . $self->_expr( $ast->{on} ) . ')' )
+      : ('USING', '(' .$self->dispatch($ast->{using} || croak "No 'on' or 'join' clause passed to -join").
+                  ')' );
 
-    $output .= ")";
-    return $output;
+    return join(" ", @output);
       
   }