From: Matt S Trout Date: Wed, 16 Jul 2008 19:36:25 +0000 (+0000) Subject: aliasify X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=29c7d026f71cebf58051d5e1a3e299955b2fac0f;p=dbsrgits%2FSQL-Abstract.git aliasify --- diff --git a/e.pl b/e.pl index 24ee949..4eb3f95 100644 --- a/e.pl +++ b/e.pl @@ -60,6 +60,10 @@ sub _run_e { map { _une($_) } $_[0]->(); } +sub _aliasify { + map { ref($_) eq 'ARRAY' ? [ -alias, $_->[1], $_->[0] ] : $_ } @_ +} + sub expr (&) { _run_e(@_) } sub _do { my ($name, $code, @in) = @_; @@ -67,11 +71,16 @@ sub _do { } sub _dolist { my ($name, $code, @in) = @_; - _do($name, sub { [ -list, map { _une($_) } $code->() ] }, @in); + _do($name, + sub { [ -list, + map { _une($_) } + _aliasify $code->() + ] }, + @in); } sub ORDER_BY (&;@) { _do(-order_by, @_) } sub SELECT (&;@) { _dolist('-select', @_); } -sub JOIN (&;@) { _do('-join', @_) } +sub JOIN (&;@) { _do('-join', _aliasify @_) } sub WHERE (&;@) { _do(-where, @_) } sub GROUP_BY (&;@) { _dolist(-group_by, @_); } sub sum { E->new([ -sum, _une(shift) ]); }