From: Arthur Axel "fREW" Schmidt Date: Tue, 14 Sep 2010 01:00:24 +0000 (+0000) Subject: doc additions and a method rename X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ee4227a70551db9d17b5045b77b73d57f38981b1;p=scpubgit%2FQ-Branch.git doc additions and a method rename --- diff --git a/Changes b/Changes index 2e4d0da..e2646ba 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for SQL::Abstract + - Document methods on Tree + - Change ::Tree::whitespace to whitespace_keyword + revision 1.67_03 2010-09-11 ---------------------------- - Add docs for SQL::Abstract::Tree->new diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index c5abe28..e8e5ff3 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -310,7 +310,7 @@ my %starters = ( 'delete from' => 1, ); -sub whitespace { +sub whitespace_keyword { my ($self, $keyword, $depth) = @_; my $before = ''; @@ -373,7 +373,7 @@ sub unparse { return join (" $car ", map $self->unparse($_, $bindargs, $depth), @{$cdr}); } else { - my ($l, $r) = @{$self->whitespace($car, $depth)}; + my ($l, $r) = @{$self->whitespace_keyword($car, $depth)}; return sprintf "$l%s %s$r", $self->format_keyword($car), $self->unparse($cdr, $bindargs, $depth); } } @@ -437,3 +437,29 @@ use the profile and override the parts that you don't like. Takes C<$sql> and C<\@bindargs>. Returns a formatting string based on the string passed in + +=head2 parse + + $sqlat->parse('SELECT * FROM bar WHERE x = ?') + +Returns a "tree" representing passed in SQL. Please do not depend on the +structure of the returned tree. It may be stable at some point, but not yet. + +=head2 unparse + + $sqlat->parse($tree_structure, \@bindargs) + +Transform "tree" into SQL, applying various transforms on the way. + +=head2 format_keyword + + $sqlat->format_keyword('SELECT') + +Currently this just takes a keyword and puts the C stuff around it. +Later on it may do more and allow for coderef based transforms. + +=head2 whitespace_keyword + + my ($before, $after) = @{$sqlat->whitespace_keyword('SELECT')}; + +Returns whitespace to be inserted around a keyword. diff --git a/t/13whitespace_keyword.t b/t/13whitespace_keyword.t index 2d2319c..838ed04 100644 --- a/t/13whitespace_keyword.t +++ b/t/13whitespace_keyword.t @@ -5,10 +5,10 @@ use Test::More; use SQL::Abstract::Tree; my $sqlat = SQL::Abstract::Tree->new({ - newline => "\n", - indent_string => " ", - indent_amount => 1, - indentmap => { + newline => "\n", + indent_string => " ", + indent_amount => 1, + indentmap => { select => 0, where => 1, from => 2, @@ -16,15 +16,15 @@ my $sqlat = SQL::Abstract::Tree->new({ on => 4, 'group by' => 5, 'order by' => 6, - }, + }, }); for ( keys %{$sqlat->indentmap}) { - my ($l, $r) = @{$sqlat->whitespace($_, 1)}; - is($r, ' ', "right is a space for $_"); - is($l, "\n " . ' ' x $sqlat->indentmap->{$_}, "left calculated correctly for $_" ); + my ($l, $r) = @{$sqlat->whitespace_keyword($_, 1)}; + is($r, ' ', "right is a space for $_"); + is($l, "\n " . ' ' x $sqlat->indentmap->{$_}, "left calculated correctly for $_" ); } -is($sqlat->whitespace('select', 0)->[0], '', 'Select gets no newline or indent for depth 0'); +is($sqlat->whitespace_keyword('select', 0)->[0], '', 'Select gets no newline or indent for depth 0'); done_testing;