X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FExtraClauses.pm;h=27f88f91f056f302e7c99527faf0a75713971e38;hb=41086177ba1f6933a58673c79af6770fba80700e;hp=b5f15d9c2643ba260f55c76b11e6ea10cb6084cf;hpb=2f4717adc025a309b4137256f09344c853566630;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract/ExtraClauses.pm b/lib/SQL/Abstract/ExtraClauses.pm index b5f15d9..27f88f9 100644 --- a/lib/SQL/Abstract/ExtraClauses.pm +++ b/lib/SQL/Abstract/ExtraClauses.pm @@ -87,38 +87,18 @@ sub apply_to { return $exp; }); }); - my $expand_setop = $self->cb(sub { - my ($self, $setop, $args) = @_; - +{ "-${setop}" => { - %$args, - queries => [ map $self->expand_expr($_), @{$args->{queries}} ], - } }; - }); - $sqla->expanders(map +($_ => $expand_setop), qw(union intersect except)); $sqla->clause_renderer('select.setop' => $self->cb(sub { my ($self, undef, $setop) = @_; $self->render_aqt($setop); })); - $sqla->renderer($_ => $self->cb(sub { - my ($self, $setop, $args) = @_; - $self->join_query_parts( - ' '.$self->format_keyword(join '_', $setop, ($args->{type}||())).' ', - @{$args->{queries}} - ); - })) for qw(union intersect except); - - my $setop_expander = $self->cb(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 ]) - } - })); - }); + foreach my $setop (qw(union intersect except)) { + $sqla->expander($setop => $self->cb('_expand_setop')); + $sqla->renderer($setop => $self->cb('_render_setop')); + } + + my $setop_expander = $self->cb('_expand_clause_setop'); $sqla->clause_expanders( map +($_ => $setop_expander), @@ -338,4 +318,31 @@ sub _render_with { ); } +sub _expand_setop { + my ($self, $setop, $args) = @_; + +{ "-${setop}" => { + %$args, + queries => [ map $self->expand_expr($_), @{$args->{queries}} ], + } }; +} + +sub _render_setop { + my ($self, $setop, $args) = @_; + $self->join_query_parts( + ' '.$self->format_keyword(join '_', $setop, ($args->{type}||())).' ', + @{$args->{queries}} + ); +} + +sub _expand_clause_setop { + my ($self, $setop, $args) = @_; + my ($op, $type) = split '_', $setop; + +(setop => $self->expand_expr({ + "-${op}" => { + ($type ? (type => $type) : ()), + queries => (ref($args) eq 'ARRAY' ? $args : [ $args ]) + } + })); +} + 1;