From: Matt S Trout Date: Mon, 25 Mar 2019 02:40:11 +0000 (+0000) Subject: extract _expand_expr_hashpair_op X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d0ae57ada170b925829c6bb1704fa225bf94dfbf;p=scpubgit%2FQ-Branch.git extract _expand_expr_hashpair_op --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index ed61272..3627abf 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -607,47 +607,7 @@ sub _expand_expr_hashpair { } $self->_assert_pass_injection_guard($k =~ /^-(.*)$/s) if $k =~ /^-/; if ($k =~ /^-/) { - if (my ($rest) = $k =~/^-not[_ ](.*)$/) { - return +{ -op => [ - 'not', - $self->_expand_expr({ "-${rest}", $v }) - ] }; - } - { - my $op = $k; - $op =~ s/^-// if length($op) > 1; - - # top level special ops are illegal in general - # note that, arguably, if it makes no sense at top level, it also - # makes no sense on the other side of an = sign or similar but DBIC - # gets disappointingly upset if I disallow it - if ( - (our $Expand_Depth) == 1 - and List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}} - ) { - puke "Illegal use of top-level '-$op'" - } - if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) { - return { -op => [ $op, $v ] }; - } - } - if ($self->{render}{$k}) { - return { $k => $v }; - } - if ( - ref($v) eq 'HASH' - and keys %$v == 1 - and (keys %$v)[0] =~ /^-/ - ) { - my ($func) = $k =~ /^-(.*)$/; - if (List::Util::first { $func =~ $_->{regex} } @{$self->{special_ops}}) { - return +{ -op => [ $func, $self->_expand_expr($v) ] }; - } - return +{ -func => [ $func, $self->_expand_expr($v) ] }; - } - if (!ref($v) or is_literal_value($v)) { - return +{ -op => [ $k =~ /^-(.*)$/, $self->_expand_expr($v) ] }; - } + return $self->_expand_expr_hashpair_op($k, $v); } if ( !defined($v) @@ -794,6 +754,52 @@ sub _expand_expr_hashpair { die "notreached"; } +sub _expand_expr_hashpair_op { + my ($self, $k, $v) = @_; + if (my ($rest) = $k =~/^-not[_ ](.*)$/) { + return +{ -op => [ + 'not', + $self->_expand_expr({ "-${rest}", $v }) + ] }; + } + { + my $op = $k; + $op =~ s/^-// if length($op) > 1; + + # top level special ops are illegal in general + # note that, arguably, if it makes no sense at top level, it also + # makes no sense on the other side of an = sign or similar but DBIC + # gets disappointingly upset if I disallow it + if ( + (our $Expand_Depth) == 1 + and List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}} + ) { + puke "Illegal use of top-level '-$op'" + } + if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) { + return { -op => [ $op, $v ] }; + } + } + if ($self->{render}{$k}) { + return { $k => $v }; + } + if ( + ref($v) eq 'HASH' + and keys %$v == 1 + and (keys %$v)[0] =~ /^-/ + ) { + my ($func) = $k =~ /^-(.*)$/; + if (List::Util::first { $func =~ $_->{regex} } @{$self->{special_ops}}) { + return +{ -op => [ $func, $self->_expand_expr($v) ] }; + } + return +{ -func => [ $func, $self->_expand_expr($v) ] }; + } + if (!ref($v) or is_literal_value($v)) { + return +{ -op => [ $k =~ /^-(.*)$/, $self->_expand_expr($v) ] }; + } + die "notreached"; +} + sub _expand_ident { my ($self, $op, $body) = @_; unless (defined($body) or (ref($body) and ref($body) eq 'ARRAY')) {