From: Matt S Trout Date: Tue, 26 Mar 2019 03:27:18 +0000 (+0000) Subject: start to extract op checking for null X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5f2c2f1ee0cf6f070952989694ae73450e4fd68f;p=scpubgit%2FQ-Branch.git start to extract op checking for null --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 077fa43..6ede36a 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')) {