clean up row and op expansion to methods
[scpubgit/Q-Branch.git] / lib / SQL / Abstract.pm
index c158536..2004c71 100644 (file)
@@ -168,11 +168,8 @@ sub new {
   # special operators
   $opt{special_ops} ||= [];
 
-  # regexes are applied in order, thus push after user-defines
-  push @{$opt{special_ops}}, @BUILTIN_SPECIAL_OPS;
-
   if ($class->isa('DBIx::Class::SQLMaker')) {
-    $opt{is_dbic_sqlmaker} = 1;
+    $opt{warn_once_on_nest} = 1;
     $opt{disable_old_special_ops} = 1;
   }
 
@@ -204,19 +201,13 @@ sub new {
     -bind => sub { shift; +{ @_ } },
     -in => '_expand_in',
     -not_in => '_expand_in',
-    -row => sub {
-      my ($self, $node, $args) = @_;
-      +{ $node => [ map $self->expand_expr($_), @$args ] };
-    },
+    -row => '_expand_row',
     -between => '_expand_between',
     -not_between => '_expand_between',
-    -op => sub {
-      my ($self, $node, $args) = @_;
-      my ($op, @opargs) = @$args;
-      +{ $node => [ $op, map $self->expand_expr($_), @opargs ] };
-    },
+    -op => '_expand_op',
     (map +($_ => '_expand_op_is'), ('-is', '-is_not')),
     -ident => '_expand_ident',
+    -value => '_expand_value',
   };
 
   $opt{expand_op} = {
@@ -228,23 +219,9 @@ sub new {
     (map +($_ => '_expand_op_andor'), ('and', 'or')),
     (map +($_ => '_expand_op_is'), ('is', 'is_not')),
     'ident' => '_expand_ident',
+    'value' => '_expand_value',
   };
 
-  # placeholder for _expand_unop system
-  {
-    my %unops = (-value => '_expand_value');
-    foreach my $name (keys %unops) {
-      $opt{expand}{$name} = $unops{$name};
-      my ($op) = $name =~ /^-(.*)$/;
-      $opt{expand_op}{$op} = sub {
-        my ($self, $op, $arg, $k) = @_;
-        return $self->_expand_expr_hashpair_cmp(
-          $k, { "-${op}" => $arg }
-        );
-      };
-    }
-  }
-
   $opt{render} = {
     (map +("-$_", "_render_$_"), qw(op func bind ident literal row)),
     %{$opt{render}||{}}
@@ -747,8 +724,13 @@ sub _expand_expr_hashpair_op {
 
     if (
       (our $Expand_Depth) == 1
-      and $self->{disable_old_special_ops}
-      and List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}}
+      and (
+        List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}}
+        or (
+          $self->{disable_old_special_ops}
+          and List::Util::first { $op =~ $_->{regex} } @BUILTIN_SPECIAL_OPS
+        )
+      )
     ) {
       puke "Illegal use of top-level '-$op'"
     }
@@ -921,6 +903,17 @@ sub _expand_not {
   +{ -op => [ 'not', $_[0]->_expand_expr($_[2]) ] };
 }
 
+sub _expand_row {
+  my ($self, $node, $args) = @_;
+  +{ $node => [ map $self->expand_expr($_), @$args ] };
+}
+
+sub _expand_op {
+  my ($self, $node, $args) = @_;
+  my ($op, @opargs) = @$args;
+  +{ $node => [ $op, map $self->expand_expr($_), @opargs ] };
+}
+
 sub _expand_bool {
   my ($self, undef, $v) = @_;
   if (ref($v)) {
@@ -1054,7 +1047,7 @@ sub _expand_nest {
   my ($self, $op, $v) = @_;
   # DBIx::Class requires a nest warning to be emitted once but the private
   # method it overrode to do so no longer exists
-  if ($self->{is_dbic_sqlmaker}) {
+  if ($self->{warn_once_on_nest}) {
     unless (our $Nest_Warned) {
       belch(
         "-nest in search conditions is deprecated, you most probably wanted:\n"