extract setop expander
[scpubgit/Q-Branch.git] / lib / SQL / Abstract / ExtraClauses.pm
index b5f15d9..27f88f9 100644 (file)
@@ -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;