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=59f5f200d7a0bdf0da1d0f83ac8c7a294ab5663a;hpb=4ebfbfc14c43fde301c9e3ee25df9f078dff0a3c;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract/Formatter.pm b/lib/SQL/Abstract/Formatter.pm index 59f5f20..6fedeb5 100644 --- a/lib/SQL/Abstract/Formatter.pm +++ b/lib/SQL/Abstract/Formatter.pm @@ -44,21 +44,22 @@ sub _fold_sql { if (length($j_part) + length($line) + $join_len <= $w) { $line .= $j_part; } else { - if ($p->[1] eq '(' and $p->[-1] eq ')') { - push @res, $line.$pre.'('."\n"; + if (ref($p) and $p->[1] eq '(' and $p->[-1] eq ')') { + 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;