From: Matt S Trout Date: Sat, 28 Jul 2012 18:06:58 +0000 (+0000) Subject: clean up FetchFirst more X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2a54ca0e2feb0d21f8a4b0fe1713f21e0cb4ed68;p=dbsrgits%2FData-Query.git clean up FetchFirst more --- diff --git a/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm b/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm index 930c382..5558074 100644 --- a/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm +++ b/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm @@ -1,5 +1,6 @@ package Data::Query::Renderer::SQL::Slice::FetchFirst; +use List::Util qw(reduce); use Data::Query::ExprHelpers; use Moo::Role; @@ -86,9 +87,9 @@ sub _render_slice { push @order_nodes, $order; $order = $order->{from}; } - my $inside_order = $order; - $inside_order = Order($_->{by}, $_->{reverse}, $inside_order) - for reverse @order_nodes; + my $inside_order = reduce { + Order($b->{by}, $b->{reverse}, $a) + } $order, reverse @order_nodes; my $inside_select = Select(\@inside_select_list, $inside_order); my $limit_plus_offset = +{ %{$dq->{limit}}, value => $dq->{limit}{value} + $dq->{offset}{value} @@ -98,9 +99,9 @@ sub _render_slice { $default_inside_alias, Slice(undef, $limit_plus_offset, $inside_select) ); - my $outside_order = $bridge_from; - $outside_order = Order($order_map{$_->{by}}, !$_->{reverse}, $outside_order) - for reverse @order_nodes; + my $outside_order = reduce { + Order($order_map{$b->{by}}, !$b->{reverse}, $a) + } $bridge_from, reverse @order_nodes; my $outside_select = Select( ( $dq->{preserve_order} @@ -114,10 +115,12 @@ sub _render_slice { ); my $final = Slice(undef, $dq->{limit}, $outside_select); if ($dq->{preserve_order}) { - $final = Alias($default_inside_alias, $final); - $final = Order($order_map{$_->{by}}, $_->{reverse}, $final) - for reverse @order_nodes; - $final = Select(\@outside_select_list, $final); + $final = Select( + \@outside_select_list, + reduce { + Order($order_map{$b->{by}}, $b->{reverse}, $a) + } Alias($default_inside_alias, $final), reverse @order_nodes + ); } return $self->_render($final); }