refactor a bit more, honour literals in converter
Matt S Trout [Mon, 16 Apr 2012 07:11:45 +0000 (07:11 +0000)]
lib/SQL/Abstract/Converter.pm

index 2ce72cf..b7380dd 100644 (file)
@@ -230,32 +230,37 @@ sub _select_to_dq {
     }
   };
 
-  return $self->_select_list_to_dq($fields, $ordered_dq);
+  return $self->_select_select_to_dq($fields, $ordered_dq);
 }
 
-sub _select_list_to_dq {
+sub _select_select_to_dq {
   my ($self, $fields, $from_dq) = @_;
 
   $fields ||= '*';
 
   return +{
     type => DQ_SELECT,
-    select => [ $self->_select_field_list_to_dq($fields) ],
+    select => $self->_select_field_list_to_dq($fields),
     from => $from_dq,
   };
 }
 
 sub _select_field_list_to_dq {
   my ($self, $fields) = @_;
-  map $self->_select_field_to_dq($_),
-    ref($fields) eq 'ARRAY' ? @$fields : $fields;
+  [ map $self->_select_field_to_dq($_),
+      ref($fields) eq 'ARRAY' ? @$fields : $fields ];
 }
 
 sub _select_field_to_dq {
   my ($self, $field) = @_;
-  ref($field)
-    ? $self->_literal_to_dq($$field)
-    : $self->_ident_to_dq($field)
+  if (my $ref = ref($field)) {
+    if ($ref eq 'REF' and ref($$field) eq 'HASH') {
+      return $$field;
+    } else {
+      return $self->_literal_to_dq($$field);
+    }
+  }
+  return $self->_ident_to_dq($field)
 }
 
 sub _delete_to_dq {