From: Matt S Trout Date: Fri, 6 Sep 2019 01:24:58 +0000 (+0000) Subject: formatter starts to work X-Git-Tag: v2.000000~3^2~158 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b349d2fa19970adb0e99406d11eb8ab9a9284b49;hp=b7516a3a3ffbb07e06b84f712a975b8825cf1698;p=dbsrgits%2FSQL-Abstract.git formatter starts to work --- diff --git a/lib/SQL/Abstract/Formatter.pm b/lib/SQL/Abstract/Formatter.pm index 1402ecc..59f5f20 100644 --- a/lib/SQL/Abstract/Formatter.pm +++ b/lib/SQL/Abstract/Formatter.pm @@ -9,8 +9,7 @@ has max_width => (is => 'ro', default => 78); sub _join { shift; -::Dwarn [ JOIN => @_ ]; - return ::Dwarn SQL::Abstract::Parts::stringify(\@_); + return SQL::Abstract::Parts::stringify(\@_); } sub format { @@ -27,7 +26,6 @@ sub _simplify { } sub _fold_sql { -::Dwarn \@_; my ($self, $indent0, $indent, $join, @parts) = @_; my @res; my $w = $self->max_width; @@ -40,13 +38,20 @@ sub _fold_sql { my $line = $indent0; my $next_indent = $indent.$self->indent_by; PART: foreach my $idx (0..$#parts) { - ::Dwarn [ PARTSTART => $idx, \@parts, $line, \@res ]; my $p = $parts[$idx]; my $pre = $idx ? $join : ''; 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 ($p->[1] eq '(' and $p->[-1] eq ')') { + push @res, $line.$pre.'('."\n"; + my (undef, undef, $inner) = @$p; + my $folded = $self->_fold_sql($indent, $indent, @$inner); + push @res, $nl_post.$folded."\n"; + $line = $indent0.')'; + next PART; + } push @res, $line.$nl_pre."\n"; if (length($line = $indent.$nl_post.$j) <= $w) { next PART; @@ -55,9 +60,8 @@ sub _fold_sql { push @res, $folded.$pre."\n"; $line = $indent.$nl_post; } - ::Dwarn [ PART => $idx => $line => $j_part => \@res ]; } - return +(::Dwarn [ join '', @res, $line ])->[0]; + return join '', @res, $line; } 1; diff --git a/lib/SQL/Abstract/Parts.pm b/lib/SQL/Abstract/Parts.pm index 5a8ef4e..e4a2033 100644 --- a/lib/SQL/Abstract/Parts.pm +++ b/lib/SQL/Abstract/Parts.pm @@ -16,7 +16,6 @@ sub new { sub stringify { my ($self) = @_; -::Dwarn([ STR => $self ]); my ($join, @parts) = @$self; return join($join, map +(ref() ? stringify($_) : $_), @parts); }