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
'delete from' => 1,
);
-sub whitespace {
+sub whitespace_keyword {
my ($self, $keyword, $depth) = @_;
my $before = '';
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);
}
}
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.
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,
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;