X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FFormatter.pm;h=6fedeb53117848dba80d85a1b4db64da682ea8db;hb=161d810565dbf4a3be23d02d37c3a9374511eb77;hp=42237fabe72ffcb4865340ee10d2d1589c9d090b;hpb=0655a7af8219e8fb04fd77ec6d6f9af95cf42a34;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract/Formatter.pm b/lib/SQL/Abstract/Formatter.pm index 42237fa..6fedeb5 100644 --- a/lib/SQL/Abstract/Formatter.pm +++ b/lib/SQL/Abstract/Formatter.pm @@ -45,20 +45,21 @@ sub _fold_sql { $line .= $j_part; } else { if (ref($p) and $p->[1] eq '(' and $p->[-1] eq ')') { - push @res, $line.$join.'('."\n"; + push @res, $line.($line =~ /S/ ? $join : '').'('."\n"; my (undef, undef, $inner) = @$p; my $folded = $self->_fold_sql($indent, $indent, @$inner); - push @res, $nl_post.$folded."\n"; - $line = $indent0.')'; + push @res, $folded."\n"; + $line = $indent0.')'.($nl_post and $idx < $#parts ? ' '.$nl_post : ''); next PART; } - push @res, $line.$nl_pre."\n"; + push @res, $line.$nl_pre."\n" if $line =~ /\S/; if (length($line = $indent.$nl_post.$j) <= $w) { next PART; } - my $folded = $self->_fold_sql($indent, $next_indent, @$p); - push @res, $folded.$pre."\n"; - $line = $indent.$nl_post; + my $folded = $self->_fold_sql($indent.$nl_post, $next_indent, @$p); + $folded =~ s/\n\Z//; + push @res, $folded.$nl_pre."\n"; + $line = $idx == $#parts ? '' : $indent.$nl_post; } } return join '', @res, $line;