From: Matt S Trout Date: Sun, 31 Jul 2011 20:39:00 +0000 (+0000) Subject: clean up code to use intersperse X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9d8243ac9c0ec52600cfda32d93ed684e0260644;p=dbsrgits%2FData-Query.git clean up code to use intersperse --- diff --git a/lib/Data/Query/Renderer/SQL/Naive.pm b/lib/Data/Query/Renderer/SQL/Naive.pm index 92b1617..354036d 100644 --- a/lib/Data/Query/Renderer/SQL/Naive.pm +++ b/lib/Data/Query/Renderer/SQL/Naive.pm @@ -193,17 +193,24 @@ sub _handle_op_type_flatten { push @arg_final, $arg; } } - my @sql = ('(', map +($self->_render($_), $op_name), @arg_final); - $sql[-1] = ')'; # replace final AND or whatever with ) - \@sql; + [ '(', + intersperse( + $self->_format_keyword($op_name), + map $self->_render($_), @arg_final + ), + ')' + ]; } sub _handle_op_type_in { my ($self, $op, $dq) = @_; my ($lhs, @in) = @{$dq->{args}}; - my @rhs = ('(', map +($self->_render($_), ','), @in); - $rhs[-1] = ')'; - [ $self->_render($lhs), $op, @rhs ]; + [ $self->_render($lhs), + $op, + '(', + intersperse(',', map $self->_render($_), @in), + ')' + ]; } sub _handle_op_type_between { @@ -235,7 +242,7 @@ sub _handle_op_type_apply { }; [ "$ident(", - (map $self->_render($_), @args), + intersperse(',', map $self->_render($_), @args), ')' ] } @@ -260,19 +267,11 @@ sub _render_select { # it is, in fact, completely valid for there to be nothing for us # to project from since many databases handle 'SELECT 1;' fine - my @select = map [ - ($_->{type} eq DQ_ALIAS - ? $self->_render_alias($_, $self->_format_keyword('AS')) - : $self->_render($_) - ), - ',' - ], @{$dq->{select}}; - - # we put the commas inside the [] for each entry as a hint to the pretty - # printer downstream so now we need to eliminate the comma from the last - # entry - we know there always is one due to the die guard at the top - - pop @{$select[-1]}; + my @select = intersperse(',', + map +($_->{type} eq DQ_ALIAS + ? $self->_render_alias($_, $self->_format_keyword('AS')) + : $self->_render($_)), @{$dq->{select}} + ); return [ $self->_format_keyword('SELECT'),