functionalise order mapping
Matt S Trout [Sun, 29 Jul 2012 17:19:00 +0000 (17:19 +0000)]
lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm

index f7be0b2..d885fb4 100644 (file)
@@ -75,13 +75,12 @@ sub _render_slice {
   };
 
   my $order_gensym_count;
-  my %order_map;
-  foreach my $order (@order_nodes) {
-    my $by = $order->{by};
+  my @mapped_order = map {
+    my $by = $_->{by};
     if (is_Identifier $by) {
       $default_inside_alias ||= $by->{elements}[0]
         if @{$by->{elements}} == 2;
-      $order_map{$by}
+      my $mapped_by
         = $alias_map{join('.', @{$by->{elements}})}
           ||= do {
                 if (
@@ -95,10 +94,11 @@ sub _render_slice {
                   Identifier($name);
                 }
               };
+      Order($mapped_by, $_->{reverse});
     } else {
       die "XXX not implemented yet";
     }
-  }
+  } @order_nodes;
 
   $default_inside_alias ||= 'me';
 
@@ -112,9 +112,9 @@ sub _render_slice {
         ? Select(
           \@outside_select_list,
           compose {
-            Order($order_map{$b->{by}}, $b->{reverse}, $a)
+            Order($b->{by}, $b->{reverse}, $a)
           } (
-            @order_nodes,
+            @mapped_order,
             Alias($default_inside_alias, $_)
           )
         )
@@ -127,13 +127,13 @@ sub _render_slice {
             @outside_select_list,
             $dq->{preserve_order}
               ? (grep @{$_->{elements}} == 1,
-                  @order_map{map $_->{by}, @order_nodes})
+                  map $_->{by}, @mapped_order)
               : (),
           ],
           compose {
-            Order($order_map{$b->{by}}, !$b->{reverse}, $a)
+            Order($b->{by}, !$b->{reverse}, $a)
           } (
-            @order_nodes,
+            @mapped_order,
             Alias(
               $default_inside_alias,
               Slice(