[Bast-commits] r9674 - in SQL-Abstract/1.x/branches/sqla-tree: lib/SQL/Abstract t

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Thu Sep 2 05:00:07 GMT 2010


Author: frew
Date: 2010-09-02 06:00:07 +0100 (Thu, 02 Sep 2010)
New Revision: 9674

Modified:
   SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm
   SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t
Log:
initial profile and configuration support

Modified: SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm
===================================================================
--- SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm	2010-09-02 04:40:03 UTC (rev 9673)
+++ SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm	2010-09-02 05:00:07 UTC (rev 9674)
@@ -70,8 +70,28 @@
 
 sub _binary_op_keywords { @binary_op_keywords }
 
-sub new { bless sub {}, shift }
+my %profiles = (
+   console => {
+      indent => ' ',
+      indent_amount => 2,
+      newline => "\n",
+   },
+   none => {
+      indent => '',
+      indent_amount => 0,
+      newline => '',
+   },
+);
 
+sub new {
+   my ($class, $args) = @_;
+
+   my $profile = delete $args->{profile} || 'none';
+   my $data = {%{$profiles{$profile}}, %{$args||{}}};
+
+   bless $data, $class
+}
+
 sub parse {
   my ($self, $s) = @_;
 
@@ -202,9 +222,12 @@
    return [$before, $after];
 }
 
-sub newline { "\n" }
+sub _newline { $_[0]->{newline} }
+sub _indent { $_[0]->{indent} }
+sub _indent_amount { $_[0]->{indent_amount} }
+sub newline { $_[0]->_newline }
 
-sub indent { '   ' x $_[1] }
+sub indent { $_[0]->_indent x $_[0]->_indent_amount x $_[1] }
 
 sub _is_select {
    my $tree = shift;

Modified: SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t
===================================================================
--- SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t	2010-09-02 04:40:03 UTC (rev 9673)
+++ SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t	2010-09-02 05:00:07 UTC (rev 9674)
@@ -3,7 +3,7 @@
 
 use SQL::Abstract::Tree;
 
-my $sqlat = SQL::Abstract::Tree->new;
+my $sqlat = SQL::Abstract::Tree->new({ profile => 'console' });
 
 {
    my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";




More information about the Bast-commits mailing list