From: Peter Rabbitson Date: Thu, 21 Oct 2010 12:49:11 +0000 (+0000) Subject: Preserve \@bindargs passed to unparse() X-Git-Tag: v1.70~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Abstract.git;a=commitdiff_plain;h=3a247d2317bce9466e2153662317caa7a01d9fcc Preserve \@bindargs passed to unparse() --- diff --git a/Changes b/Changes index 775bf5d..5eedf96 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,7 @@ Revision history for SQL::Abstract - Add proper handling of lists (foo,bar,?) - Better handling of generic -function's during AST construction - Special handle IS NOT? NULL + - Make sure unparse() does not destroy a passed in \@bindargs revision 1.68 2010-09-16 ---------------------------- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 7b97b29..8d8449f 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -395,10 +395,14 @@ sub fill_in_placeholder { return '?' } +# FIXME - terrible name for a user facing API sub unparse { - my ($self, $tree, $bindargs, $depth) = @_; + my ($self, $tree, $bindargs) = @_; + $self->_unparse($tree, [@{$bindargs||[]}], 0); +} - $depth ||= 0; +sub _unparse { + my ($self, $tree, $bindargs, $depth) = @_; if (not $tree or not @$tree) { return ''; @@ -414,7 +418,7 @@ sub unparse { } if (ref $car) { - return join (' ', map $self->unparse($_, $bindargs, $depth), @$tree); + return join (' ', map $self->_unparse($_, $bindargs, $depth), @$tree); } elsif ($car eq 'LITERAL') { if ($cdr->[0] eq '?') { @@ -425,18 +429,18 @@ sub unparse { elsif ($car eq 'PAREN') { return '(' . join(' ', - map $self->unparse($_, $bindargs, $depth + 2), @{$cdr}) . + map $self->_unparse($_, $bindargs, $depth + 2), @{$cdr}) . ($self->_is_key($cdr)?( $self->newline||'' ).$self->indent($depth + 1):'') . ') '; } elsif ($car eq 'AND' or $car eq 'OR' or $car =~ / ^ $binary_op_re $ /x ) { - return join (" $car ", map $self->unparse($_, $bindargs, $depth), @{$cdr}); + return join (" $car ", map $self->_unparse($_, $bindargs, $depth), @{$cdr}); } elsif ($car eq 'LIST' ) { - return join (', ', map $self->unparse($_, $bindargs, $depth), @{$cdr}); + return join (', ', map $self->_unparse($_, $bindargs, $depth), @{$cdr}); } else { my ($l, $r) = @{$self->pad_keyword($car, $depth)}; - return sprintf "$l%s %s$r", $self->format_keyword($car), $self->unparse($cdr, $bindargs, $depth); + return sprintf "$l%s %s$r", $self->format_keyword($car), $self->_unparse($cdr, $bindargs, $depth); } }