[Bast-commits] r9726 - in SQL-Abstract/1.x/trunk: . lib/SQL/Abstract t

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Tue Sep 14 01:00:24 GMT 2010


Author: frew
Date: 2010-09-14 02:00:24 +0100 (Tue, 14 Sep 2010)
New Revision: 9726

Modified:
   SQL-Abstract/1.x/trunk/Changes
   SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm
   SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t
Log:
doc additions and a method rename

Modified: SQL-Abstract/1.x/trunk/Changes
===================================================================
--- SQL-Abstract/1.x/trunk/Changes	2010-09-12 19:39:58 UTC (rev 9725)
+++ SQL-Abstract/1.x/trunk/Changes	2010-09-14 01:00:24 UTC (rev 9726)
@@ -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

Modified: SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm
===================================================================
--- SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm	2010-09-12 19:39:58 UTC (rev 9725)
+++ SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm	2010-09-14 01:00:24 UTC (rev 9726)
@@ -310,7 +310,7 @@
    'delete from' => 1,
 );
 
-sub whitespace {
+sub whitespace_keyword {
    my ($self, $keyword, $depth) = @_;
 
    my $before = '';
@@ -373,7 +373,7 @@
     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 @@
 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<colormap> 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.

Modified: SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t
===================================================================
--- SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t	2010-09-12 19:39:58 UTC (rev 9725)
+++ SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t	2010-09-14 01:00:24 UTC (rev 9726)
@@ -5,10 +5,10 @@
 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 @@
       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;




More information about the Bast-commits mailing list