From: Arthur Axel "fREW" Schmidt Date: Thu, 2 Sep 2010 05:00:07 +0000 (+0000) Subject: initial profile and configuration support X-Git-Tag: v1.70~91^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=75c3a063a606faba914d602470bfa67a3fb7006e;p=dbsrgits%2FSQL-Abstract.git initial profile and configuration support --- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 49dbe04..0cd92ff 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -70,7 +70,27 @@ my $tokenizer_re = qr/ \s* ( $tokenizer_re_str | \( | \) | \? ) \s* /xi; 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 @@ sub whitespace { 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; diff --git a/t/11unparse.t b/t/11unparse.t index a865416..97eb5b7 100644 --- a/t/11unparse.t +++ b/t/11unparse.t @@ -3,7 +3,7 @@ use warnings; 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'";