From: Arthur Axel "fREW" Schmidt Date: Thu, 2 Sep 2010 04:14:44 +0000 (+0000) Subject: good formatting for both subqueries and otherwise X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0569a14f45a9803b3629a53b9ed26d6189c48d18;p=scpubgit%2FQ-Branch.git good formatting for both subqueries and otherwise --- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 423c2d2..5ae9b99 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -205,6 +205,13 @@ sub newline { "\n" } sub indent { ' ' x $_[1] } +sub _is_select { + my $tree = shift; + $tree = $tree->[0] while ref $tree; + + lc $tree eq 'select'; +} + sub unparse { my ($self, $tree, $depth) = @_; @@ -226,8 +233,8 @@ sub unparse { elsif ($car eq 'PAREN') { return '(' . join(' ', - map $self->unparse($_, $depth + 1), @{$cdr}) - . ')'; + map $self->unparse($_, $depth + 2), @{$cdr}) . + (_is_select($cdr)?$self->newline.$self->indent($depth + 1):'') . ')'; } elsif ($car eq 'OR' or $car eq 'AND' or (grep { $car =~ /^ $_ $/xi } @binary_op_keywords ) ) { return join (" $car ", map $self->unparse($_, $depth), @{$cdr});