From: Matt S Trout Date: Tue, 26 Mar 2019 03:27:18 +0000 (+0000) Subject: start to extract op checking for null X-Git-Tag: v2.000000~3^2~331 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=043256bc956aff1796a6e46e17fa71db890256ea;p=dbsrgits%2FSQL-Abstract.git start to extract op checking for null --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 46f8def..b8d257e 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -805,13 +805,10 @@ sub _expand_expr_hashtriple { and not defined $vv->{-value} ) ) { - my $is = - $op =~ /^not$/i ? 'is not' # legacy - : $op =~ $self->{equality_op} ? 'is' - : $op =~ $self->{like_op} ? belch("Supplying an undefined argument to '@{[ uc $op]}' is deprecated") && 'is' - : $op =~ $self->{inequality_op} ? 'is not' - : $op =~ $self->{not_like_op} ? belch("Supplying an undefined argument to '@{[ uc $op]}' is deprecated") && 'is not' - : puke "unexpected operator '$op' with undef operand"; + my $is = $self->_dwim_op_to_is($op, + "Supplying an undefined argument to '%s' is deprecated", + "unexpected operator '%s' with undef operand", + ); return $self->_expand_expr_hashpair($k => { $is, undef }); } @@ -823,6 +820,28 @@ sub _expand_expr_hashtriple { ] }; } +sub _dwim_op_to_is { + my ($self, $op, $empty, $fail) = @_; + if ($op =~ /^not$/i) { + return 'is not'; + } + if ($op =~ $self->{equality_op}) { + return 'is'; + } + if ($op =~ $self->{like_op}) { + belch(sprintf $empty, uc($op)); + return 'is'; + } + if ($op =~ $self->{inequality_op}) { + return 'is not'; + } + if ($op =~ $self->{not_like_op}) { + belch(sprintf $empty, uc($op)); + return 'is not'; + } + puke(sprintf $fail, $op); +} + sub _expand_ident { my ($self, $op, $body) = @_; unless (defined($body) or (ref($body) and ref($body) eq 'ARRAY')) {