From: Arthur Axel "fREW" Schmidt Date: Wed, 1 Sep 2010 03:55:49 +0000 (+0000) Subject: add format command X-Git-Tag: v1.70~91^2~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=203ce7d3dce3ec711431bbbeae6311b23e22ea7b;p=dbsrgits%2FSQL-Abstract.git add format command --- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index e1292f7..c77dd11 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -182,10 +182,11 @@ sub unparse { return join (" $tree->[0] ", map {unparse($_)} @{$tree->[1]}); } else { - return sprintf "%s %s\n", $tree->[0], unparse ($tree->[1]); + return sprintf '%s %s', $tree->[0], unparse ($tree->[1]); } } +sub format { unparse(parse(@_)) } 1; diff --git a/t/11unparse.t b/t/11unparse.t index 0d080f6..7aebc7d 100644 --- a/t/11unparse.t +++ b/t/11unparse.t @@ -8,7 +8,7 @@ use SQL::Abstract::Tree; FROM foo WHERE foo.a =1 and foo.b LIKE 'station'"; print "$sql\n"; - print SQL::Abstract::Tree::unparse(SQL::Abstract::Tree::parse($sql)) . "\n"; + print SQL::Abstract::Tree::format($sql) . "\n"; } { @@ -16,7 +16,7 @@ use SQL::Abstract::Tree; FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'"; print "$sql\n"; - print SQL::Abstract::Tree::unparse(SQL::Abstract::Tree::parse($sql)) . "\n"; + print SQL::Abstract::Tree::format($sql) . "\n"; } # stuff we want: