remove obsolete thing that never worked
[scpubgit/Q-Branch.git] / lib / SQL / Abstract.pm
index 5ed6fcf..dda7fc5 100644 (file)
@@ -279,6 +279,20 @@ sub new {
         [ $_[0]->_order_by($_[2]) ];
       };
     }
+    if (__PACKAGE__->can('_select_fields') ne $class->can('_select_fields')) {
+      $opt{expand_clause}{'select.select'} = sub { $_[2] };
+      $opt{render_clause}{'select.select'} = sub {
+        my @super = $_[0]->_select_fields($_[2]);
+        my $effort = [
+          ref($super[0]) eq 'HASH'
+            ? $_[0]->render_expr($super[0])
+            : @super
+        ];
+        return $_[0]->join_query_parts(
+          ' ', { -keyword => 'select' }, $effort
+        );
+      };
+    }
     if ($class->isa('DBIx::Class::SQLMaker')) {
       $opt{warn_once_on_nest} = 1;
       $opt{disable_old_special_ops} = 1;
@@ -287,6 +301,11 @@ sub new {
         s/\A\s+//, s/\s+\Z// for $sql;
         return [ $sql, @bind ];
       };
+      $opt{expand_op}{ident} = sub {
+        my ($self, undef, $body) = @_;
+        $body = $body->from if Scalar::Util::blessed($body);
+        $self->_expand_ident(ident => $body);
+      };
     }
   }
 
@@ -330,10 +349,11 @@ sub make_binop_expander {
 sub plugin {
   my ($self, $plugin, @args) = @_;
   unless (ref $plugin) {
-    $plugin =~ s/\A\+/${\ref($self)}::Plugin::/;
+    $plugin =~ s/\A\+/${\__PACKAGE__}::Plugin::/;
     require(join('/', split '::', $plugin).'.pm');
   }
   $plugin->apply_to($self, @args);
+  return $self;
 }
 
 BEGIN {
@@ -343,8 +363,11 @@ BEGIN {
     my $name = join '_', reverse split '_', $type;
     my $singular = "${type}er";
 
-    eval qq{sub ${singular} { shift->${singular}s(\@_) }; 1 }
-      or die "Method builder failed for ${singular}: $@";
+    eval qq{sub ${singular} {
+      my \$self = shift;
+      return \$self->_ext_rw('${name}', \@_) if \@_ == 1;
+      return \$self->${singular}s(\@_)
+    }; 1 } or die "Method builder failed for ${singular}: $@";
     eval qq{sub wrap_${singular} {
       shift->wrap_${singular}s(\@_)
     }; 1 } or die "Method builder failed for wrap_${singular}: $@";
@@ -535,7 +558,8 @@ sub _returning {
   my ($sql, @bind) = @{ $self->render_aqt(
     $self->expand_expr({ -list => $f }, -ident)
   ) };
-  return ($self->_sqlcase(' returning ').$sql, @bind);
+  my $rsql = $self->_sqlcase(' returning ').$sql;
+  return wantarray ? ($rsql, @bind) : $rsql;
 }
 
 sub _expand_insert_value {
@@ -735,9 +759,10 @@ sub _expand_select_clause_order_by {
 sub _select_fields {
   my ($self, $fields) = @_;
   return $fields unless ref($fields);
-  return @{ $self->render_aqt(
+  my ($sql, @bind) = @{ $self->render_aqt(
     $self->expand_expr({ -list => $fields }, '-ident')
   ) };
+  return wantarray ? ($sql, @bind) : $sql;
 }
 
 #======================================================================
@@ -1241,6 +1266,9 @@ sub _expand_op {
   if (my $exp = $self->{expand_op}{$op}) {
     return $self->$exp($op, \@opargs);
   }
+  if (List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
+    return { -op => [ $op, @opargs ] };
+  }
   +{ -op => [ $op, map $self->expand_expr($_), @opargs ] };
 }
 
@@ -1704,6 +1732,8 @@ sub _order_by {
 
   my $final_sql = $self->_sqlcase(' order by ').$sql;
 
+  return $final_sql unless wantarray;
+
   return ($final_sql, @bind);
 }
 
@@ -3458,11 +3488,17 @@ When supplied with a coderef, it is called as:
 
 =back
 
-=head1 NEW METHODS
+=head1 NEW METHODS (EXPERIMENTAL)
 
 See L<SQL::Abstract::Reference> for the C<expr> versus C<aqt> concept and
 an explanation of what the below extensions are extending.
 
+=head2 plugin
+
+  $sqla->plugin('+Foo');
+
+Enables plugin SQL::Abstract::Plugin::Foo.
+
 =head2 render_expr
 
   my ($sql, @bind) = $sqla->render_expr($expr);