From: Matt S Trout Date: Sat, 20 Apr 2019 02:53:12 +0000 (+0000) Subject: restore expand stability for extraclauses X-Git-Tag: v1.90_01~163 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38e67490d05429a527277addc383daac165e4db7;p=dbsrgits%2FSQL-Abstract.git restore expand stability for extraclauses --- diff --git a/lib/SQL/Abstract/ExtraClauses.pm b/lib/SQL/Abstract/ExtraClauses.pm index 6d2fcfd..9af44a5 100644 --- a/lib/SQL/Abstract/ExtraClauses.pm +++ b/lib/SQL/Abstract/ExtraClauses.pm @@ -116,22 +116,33 @@ sub register_defaults { qw(union intersect except) ); + my $expand_alias = sub { + my ($self, $to_expand) = @_; + [ map $self->expand_expr($_, -ident), + ref($to_expand) eq 'ARRAY' + ? @$to_expand + : $to_expand + ] + }; $self->clause_expander('select.with' => my $with_expander = sub { my ($self, $name, $with) = @_; my (undef, $type) = split '_', $name; if (ref($with) eq 'HASH') { return +{ %$with, - queries => [ map $self->expand_expr($_), @{$with->{queries}} ] + queries => [ + map +[ + $self->$expand_alias($_->[0]), + $self->expand_expr($_->[1]), + ], @{$with->{queries}} + ] } } my @with = @$with; my @exp; - while (my ($name, $query) = splice @with, 0, 2) { - my @n = map $self->expand_expr($_, -ident), - ref($name) eq 'ARRAY' ? @$name : $name; + while (my ($alias, $query) = splice @with, 0, 2) { push @exp, [ - \@n, + $self->$expand_alias($alias), $self->expand_expr($query) ]; } @@ -167,6 +178,7 @@ sub _expand_select_clause_from { sub _expand_from_list { my ($self, undef, $args) = @_; if (ref($args) eq 'HASH') { + return $args if $args->{-from_list}; return { -from_list => [ $self->expand_expr($args) ] }; } my @list;