From: Matt S Trout Date: Wed, 17 Apr 2019 01:03:35 +0000 (+0000) Subject: move setop expansion to generic rather than loop X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FQ-Branch.git;a=commitdiff_plain;h=f61bfd7bdd385955175775113c3bdc61eb98646d move setop expansion to generic rather than loop --- diff --git a/lib/SQL/Abstract/ExtraClauses.pm b/lib/SQL/Abstract/ExtraClauses.pm index ad49758..1fb0e2c 100644 --- a/lib/SQL/Abstract/ExtraClauses.pm +++ b/lib/SQL/Abstract/ExtraClauses.pm @@ -98,24 +98,24 @@ sub register_defaults { ); }) for qw(union intersect except); - foreach my $setop (qw(union intersect except)) { + my $setop_expander = sub { + my ($self, $setop, $args) = @_; + my ($op, $type) = split '_', $setop; + +(setop => $self->expand_expr({ + "-${op}" => { + ($type ? (type => $type) : ()), + queries => (ref($args) eq 'ARRAY' ? $args : [ $args ]) + } + })); + }; + + $self->clause_expanders( + map +($_ => $setop_expander), + map "select.${_}", + map +($_, "${_}_all", "${_}_distinct"), + qw(union intersect except) + ); - $self->clause_expander("select.${setop}" => sub { - +(setop => $_[0]->expand_expr({ - "-${setop}" => { - queries => (ref($_[2]) eq 'ARRAY' ? $_[2] : [ $_[2] ]), - } - })); - }); - $self->clause_expander("select.${setop}_all" => sub { - +(setop => $_[0]->expand_expr({ - "-${setop}" => { - type => 'all', - queries => (ref($_[2]) eq 'ARRAY' ? $_[2] : [ $_[2] ]), - } - })); - }); - } $self->clause_expander('select.with' => my $with_expander = sub { my ($self, undef, $with) = @_; if (ref($with) eq 'HASH') {