From: Matt S Trout Date: Sun, 31 Jul 2011 05:20:21 +0000 (+0000) Subject: implement $self->{logic} and kill numbered modifiers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=37490959494182c1141d78922aafef27cb551080;p=dbsrgits%2FSQL-Abstract.git implement $self->{logic} and kill numbered modifiers --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 0f7a4fc..96d79d9 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -518,7 +518,7 @@ sub _where_to_dq { sub _where_to_dq_ARRAYREF { my ($self, $where, $logic) = @_; - $logic = uc($logic || 'OR'); + $logic = uc($logic || $self->{logic} || 'OR'); $logic eq 'AND' or $logic eq 'OR' or puke "unknown logic: $logic"; return unless @$where; @@ -627,6 +627,8 @@ sub _where_hashpair_to_dq { return $self->_op_to_dq( NOT => ref($v) ? $self->_where_to_dq($v) : $self->_ident_to_dq($v) ); + } elsif ($op =~ /^(?:AND|OR|NEST)_?\d+/) { + die "Use of [and|or|nest]_N modifiers is no longer supported"; } else { my @args = do { if (ref($v) eq 'HASH' and keys(%$v) == 1 and (keys %$v)[0] =~ /^-(.*)/s) { @@ -684,6 +686,8 @@ sub _where_hashpair_to_dq { return $self->_literal_to_dq( [ $self->${\$special_op->{handler}}($k, $op, $value) ] );; + } elsif ($op =~ /^(?:AND|OR|NEST)_?\d+$/i) { + die "Use of [and|or|nest]_N modifiers is no longer supported"; } (uc($op), $value); } else { @@ -732,10 +736,12 @@ sub _where_hashpair_to_dq { return $self->_literal_to_dq( $op eq '!=' ? $self->{sqltrue} : $self->{sqlfalse} ); - } elsif (defined($rhs->[0]) and $rhs->[0] =~ /-(and|or)/i) { + } elsif (defined($rhs->[0]) and $rhs->[0] =~ /^-(and|or)$/i) { return $self->_where_to_dq_ARRAYREF([ map +{ $k => { $op => $_ } }, @{$rhs}[1..$#$rhs] ], uc($1)); + } elsif ($op =~ /^-(?:AND|OR|NEST)_?\d+/) { + die "Use of [and|or|nest]_N modifiers is no longer supported"; } return $self->_where_to_dq_ARRAYREF([ map +{ $k => { $op => $_ } }, @$rhs diff --git a/t/04modifiers.t b/t/04modifiers.t index 098ff19..71d2c28 100644 --- a/t/04modifiers.t +++ b/t/04modifiers.t @@ -335,12 +335,12 @@ my @nest_tests = ( }, { where => {a => 1, -nest => {b => 2, c => 3}}, - stmt => 'WHERE ( ( (b = ? AND c = ?) AND a = ? ) )', + stmt => 'WHERE ( ( b = ? AND c = ? AND a = ? ) )', bind => [qw/2 3 1/], }, { where => {a => 1, -or => {-nest => {b => 2, c => 3}}}, - stmt => 'WHERE ( ( (b = ? AND c = ?) AND a = ? ) )', + stmt => 'WHERE ( ( b = ? AND c = ? AND a = ? ) )', bind => [qw/2 3 1/], }, { @@ -355,7 +355,7 @@ my @nest_tests = ( }, { where => [a => 1, -nest => {b => 2, c => 3}, -nest => [d => 4, e => 5]], - stmt => 'WHERE ( ( a = ? OR ( b = ? AND c = ? ) OR ( d = ? OR e = ? ) ) )', + stmt => 'WHERE ( ( a = ? OR ( b = ? AND c = ? ) OR d = ? OR e = ? ) )', bind => [qw/1 2 3 4 5/], }, );