make pod tests happy
[scpubgit/Q-Branch.git] / lib / SQL / Abstract / ExtraClauses.pm
index e3d1dd6..e0b2532 100644 (file)
@@ -5,8 +5,7 @@ use Moo;
 has sqla => (
   is => 'ro', init_arg => undef,
   handles => [ qw(
-    expand_expr expand_maybe_list_expr render_aqt
-    format_keyword join_query_parts
+    expand_expr expand_maybe_list_expr render_aqt join_query_parts
   ) ],
 );
 
@@ -42,8 +41,7 @@ sub apply_to {
     $sqla->expander($thing => $self->cb("_expand_${thing}"))
          ->renderer($thing => $self->cb("_render_${thing}"))
   }
-  $sqla->op_expander(as => $self->cb('_expand_op_as'));
-  $sqla->expander(as => $self->cb('_expand_op_as'));
+  $sqla->binop_expander(as => $self->cb('_expand_op_as'));
   $sqla->renderer(as => $self->cb('_render_as'));
   $sqla->expander(alias => $self->cb('_expand_alias'));
   $sqla->renderer(alias => $self->cb('_render_alias'));
@@ -61,10 +59,8 @@ sub apply_to {
   });
 
   $sqla->clause_expanders(
-    'update.from' => $self->cb('_expand_select_clause_from'),
-    'delete.using' => $self->cb(sub {
-      +(using => $_[0]->_expand_from_list(undef, $_[2]));
-    }),
+    'update.from' => $self->cb('_expand_from_list'),
+    'delete.using' => $self->cb('_expand_from_list'),
     'insert.rowvalues' => $self->cb(sub {
       +(from => $_[0]->expand_expr({ -values => $_[2] }));
     }),
@@ -78,10 +74,9 @@ sub apply_to {
     $self->cb('_expand_select', $_[0], \@before_setop);
   });
 
-  $sqla->clause_renderer('select.setop' => $self->cb(sub {
-    my ($self, undef, $setop) = @_;
-    $self->render_aqt($setop);
-  }));
+  $sqla->clause_renderer(
+    'select.setop' => $self->cb(sub { $_[0]->render_aqt($_[2]); })
+  );
 
   foreach my $setop (qw(union intersect except)) {
     $sqla->expander($setop => $self->cb('_expand_setop'));
@@ -113,7 +108,7 @@ sub apply_to {
   $sqla->expander(cast => $self->cb('_expand_cast'));
 
   $sqla->clause_expanders(
-    "select.from", $self->cb('_expand_select_clause_from'),
+    "select.from", $self->cb('_expand_from_list'),
     "update.target", $self->cb('_expand_update_clause_target'),
     "update.update", $self->cb('_expand_update_clause_target'),
   );
@@ -133,11 +128,6 @@ sub _expand_select {
   return $exp;
 }
 
-sub _expand_select_clause_from {
-  my ($self, undef, $from) = @_;
-  +(from => $self->_expand_from_list(undef, $from));
-}
-
 sub _expand_from_list {
   my ($self, undef, $args) = @_;
   if (ref($args) eq 'HASH') {
@@ -196,14 +186,14 @@ sub _render_join {
 
   my @parts = (
     $args->{from},
-    $self->format_keyword(join '_', ($args->{type}||()), 'join'),
+    { -keyword => join '_', ($args->{type}||()), 'join' },
     (map +($_->{-ident} || $_->{-as} ? $_ : ('(', $_, ')')), $args->{to}),
     ($args->{on} ? (
-      $self->format_keyword('on') ,
+      { -keyword => 'on' },
       $args->{on},
     ) : ()),
     ($args->{using} ? (
-      $self->format_keyword('using'),
+      { -keyword => 'using' },
       '(', $args->{using}, ')',
     ) : ()),
   );
@@ -213,7 +203,6 @@ sub _render_join {
 sub _expand_op_as {
   my ($self, undef, $vv, $k) = @_;
   my @vv = (ref($vv) eq 'ARRAY' ? @$vv : $vv);
-  $k ||= shift @vv;
   my $ik = $self->expand_expr($k, -ident);
   return +{ -as => [ $ik, $self->expand_expr($vv[0], -alias) ] }
     if @vv == 1 and ref($vv[0]) eq 'HASH';
@@ -228,7 +217,7 @@ sub _render_as {
   return $self->join_query_parts(
     ' ',
     $thing,
-    $self->format_keyword('as'),
+    { -keyword => 'as' },
     $alias,
   );
 }
@@ -309,13 +298,13 @@ sub _render_with {
       my ($alias, $query) = @$_;
       $self->join_query_parts(' ',
           $alias,
-          $self->format_keyword('as'),
+          { -keyword => 'as' },
           $query,
       )
     } @{$with->{queries}}
   );
   return $self->join_query_parts(' ',
-    $self->format_keyword(join '_', 'with', ($with->{type}||'')),
+    { -keyword => join '_', 'with', ($with->{type}||'') },
     $q_part,
   );
 }
@@ -331,7 +320,7 @@ sub _expand_setop {
 sub _render_setop {
   my ($self, $setop, $args) = @_;
   $self->join_query_parts(
-    ' '.$self->format_keyword(join '_', $setop, ($args->{type}||())).' ',
+    { -keyword => ' '.join('_', $setop, ($args->{type}||())).' ' },
     @{$args->{queries}}
   );
 }
@@ -348,3 +337,29 @@ sub _expand_clause_setop {
 }
 
 1;
+
+=head1 NAME
+
+SQL::Abstract::ExtraClauses - new/experimental additions to L<SQL::Abstract>
+
+=head1 SYNOPSIS
+
+  my $sqla = SQL::Abstract->new;
+  SQL::Abstract::ExtraClauses->apply_to($sqla);
+
+=head1 METHODS
+
+=head2 apply_to
+
+Applies the plugin to an L<SQL::Abstract> object.
+
+=head2 cb
+
+For plugin authors, creates a callback to call a method on the plugin.
+
+=head2 sqla
+
+Available only during plugin callback executions, contains the currently
+active L<SQL::Abstract> object.
+
+=cut