X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FFormatter.pm;h=51645f8a5cf71f321aca89e7c9101ca76932a6e8;hb=a2795aac17bdfac1bf308699914f78289883c232;hp=f337a259ddb516477d975b6a9454953c502129a5;hpb=12fceb64ae12d5938c54d76234846ce6c229ac95;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract/Formatter.pm b/lib/SQL/Abstract/Formatter.pm index f337a25..51645f8 100644 --- a/lib/SQL/Abstract/Formatter.pm +++ b/lib/SQL/Abstract/Formatter.pm @@ -44,28 +44,32 @@ sub _fold_sql { my $j_part = $pre.(my $j = ref($p) ? $self->_join(@$p) : $p); if (length($j_part) + length($line) + $join_len <= $w) { $line .= $j_part; - } else { - if (ref($p) and $p->[1] eq '(' and $p->[-1] eq ')') { - my $already = !($line eq $indent0 or $line eq $line_orig); - push @res, $line.($already ? $join : '').'('."\n"; - my (undef, undef, $inner) = @$p; - my $fold_indent = $already ? $indent : $next_indent; - my $folded = $self->_fold_sql($fold_indent, $fold_indent, @$inner); - push @res, $folded."\n"; - $line_orig = $line - = $indent0.')'.($nl_post and $idx < $#parts ? ' '.$nl_post : ''); - next PART; - } - push @res, $line.$nl_pre."\n" if $line ne $line_orig; - if (length($line = $line_proto.$j) <= $w) { - $line_proto = $line; - next PART; - } - my $folded = $self->_fold_sql($line_proto, $next_indent, @$p); + next PART; + } + my $innerdent = @res + ? $next_indent + : $indent0.$self->indent_by; + if (ref($p) and $p->[1] eq '(' and $p->[-1] eq ')') { + my $already = !($line eq $indent0 or $line eq $line_orig); + push @res, $line.($already ? $join : '').'('."\n"; + my (undef, undef, $inner) = @$p; + my $folded = $self->_fold_sql($innerdent, $innerdent, @$inner); $folded =~ s/\n\Z//; - push @res, $folded.$nl_pre."\n"; - $line_orig = $line = $idx == $#parts ? '' : $line_proto; + push @res, $folded."\n"; + $line_orig = $line + = $indent0.')'.($idx == $#parts ? '' : $join); + next PART; + } + if ($line ne $line_orig) { + push @res, $line.($idx == $#parts ? '' : $nl_pre)."\n"; + } + if (length($line = $line_proto.$j) <= $w) { + next PART; } + my $folded = $self->_fold_sql($line_proto, $innerdent, @$p); + $folded =~ s/\n\Z//; + push @res, $folded.($idx == $#parts ? '' : $nl_pre)."\n"; + $line_orig = $line = $idx == $#parts ? '' : $line_proto; } return join '', @res, $line; }