From: Norbert Buchmuller Date: Fri, 21 Nov 2008 13:32:53 +0000 (+0000) Subject: Refactored to use _SWITCH_refkind in _where_hashpair_HASHREF. X-Git-Tag: v1.70~258 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cf8389306d53331a60f1c2680cfc107387158ef5;p=dbsrgits%2FSQL-Abstract.git Refactored to use _SWITCH_refkind in _where_hashpair_HASHREF. --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 9959486..848a60f 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -523,33 +523,33 @@ sub _where_hashpair_HASHREF { if ($special_op) { ($sql, @bind) = $special_op->{handler}->($self, $k, $op, $val); } + else { + $self->_SWITCH_refkind($val, { - # CASE: col => {op => \@vals} - elsif (ref $val eq 'ARRAY') { - ($sql, @bind) = $self->_where_field_op_ARRAYREF($k, $op, $val); - } - - # CASE: col => {op => \$scalar} - elsif (ref $val eq 'SCALAR') { - $sql = join ' ', $self->_convert($self->_quote($k)), - $self->_sqlcase($op), - $$val; - } + ARRAYREF => sub { # CASE: col => {op => \@vals} + ($sql, @bind) = $self->_where_field_op_ARRAYREF($k, $op, $val); + }, - # CASE: col => {op => undef} : sql "IS (NOT)? NULL" - elsif (! defined($val)) { - my $is = ($op =~ $self->{equality_op}) ? 'is' : - ($op =~ $self->{inequality_op}) ? 'is not' : - puke "unexpected operator '$op' with undef operand"; - $sql = $self->_quote($k) . $self->_sqlcase(" $is null"); - } + SCALARREF => sub { # CASE: col => {op => \$scalar} + $sql = join ' ', $self->_convert($self->_quote($k)), + $self->_sqlcase($op), + $$val; + }, - # CASE: col => {op => $scalar} - else { - $sql = join ' ', $self->_convert($self->_quote($k)), - $self->_sqlcase($op), - $self->_convert('?'); - @bind = $self->_bindtype($k, $val); + UNDEF => sub { # CASE: col => {op => undef} : sql "IS (NOT)? NULL" + my $is = ($op =~ $self->{equality_op}) ? 'is' : + ($op =~ $self->{inequality_op}) ? 'is not' : + puke "unexpected operator '$op' with undef operand"; + $sql = $self->_quote($k) . $self->_sqlcase(" $is null"); + }, + + FALLBACK => sub { # CASE: col => {op => $scalar} + $sql = join ' ', $self->_convert($self->_quote($k)), + $self->_sqlcase($op), + $self->_convert('?'); + @bind = $self->_bindtype($k, $val); + }, + }); } push @all_sql, $sql;