make pod tests happy
[scpubgit/Q-Branch.git] / lib / SQL / Abstract / ExtraClauses.pm
index 808ff0d..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'));
@@ -76,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'));
@@ -189,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}, ')',
     ) : ()),
   );
@@ -206,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';
@@ -221,7 +217,7 @@ sub _render_as {
   return $self->join_query_parts(
     ' ',
     $thing,
-    $self->format_keyword('as'),
+    { -keyword => 'as' },
     $alias,
   );
 }
@@ -302,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,
   );
 }
@@ -324,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}}
   );
 }
@@ -341,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