From: Matt S Trout Date: Mon, 23 Sep 2019 02:26:21 +0000 (+0000) Subject: extract setop select expander X-Git-Tag: v1.90_01~95 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c671eba6c2751d65437e394d7061038826a912e0;p=dbsrgits%2FSQL-Abstract.git extract setop select expander --- diff --git a/lib/SQL/Abstract/ExtraClauses.pm b/lib/SQL/Abstract/ExtraClauses.pm index 27f82b6..7bafdba 100644 --- a/lib/SQL/Abstract/ExtraClauses.pm +++ b/lib/SQL/Abstract/ExtraClauses.pm @@ -11,8 +11,11 @@ has sqla => ( ); sub cb { - my ($self, $method) = @_; - return sub { local $self->{sqla} = shift; $self->$method(@_) }; + my ($self, $method, @args) = @_; + return sub { + local $self->{sqla} = shift; + $self->$method(@args, @_) + }; } sub apply_to { @@ -72,18 +75,7 @@ sub apply_to { # set ops $sqla->wrap_expander(select => sub { - my $orig = shift; - $self->cb(sub { - my $self = shift; - my $exp = $self->sqla->$orig(@_); - return $exp unless my $setop = (my $sel = $exp->{-select})->{setop}; - if (my @keys = grep $sel->{$_}, @before_setop) { - my %inner; @inner{@keys} = delete @{$sel}{@keys}; - unshift @{(values(%$setop))[0]{queries}}, - { -select => \%inner }; - } - return $exp; - }); + $self->cb('_expand_select', $_[0], \@before_setop); }); $sqla->clause_renderer('select.setop' => $self->cb(sub { @@ -129,6 +121,18 @@ sub apply_to { return $sqla; } +sub _expand_select { + my ($self, $orig, $before_setop) = (shift, shift, shift); + my $exp = $self->sqla->$orig(@_); + return $exp unless my $setop = (my $sel = $exp->{-select})->{setop}; + if (my @keys = grep $sel->{$_}, @$before_setop) { + my %inner; @inner{@keys} = delete @{$sel}{@keys}; + unshift @{(values(%$setop))[0]{queries}}, + { -select => \%inner }; + } + return $exp; +} + sub _expand_select_clause_from { my ($self, undef, $from) = @_; +(from => $self->_expand_from_list(undef, $from));