From: Matt S Trout Date: Thu, 21 Mar 2019 04:35:47 +0000 (+0000) Subject: introduce expand_op concept and move between to it X-Git-Tag: v2.000000~3^2~375 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e11f6255dd73fab29a1d56d6f468677e4a071950;p=dbsrgits%2FSQL-Abstract.git introduce expand_op concept and move between to it --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index e1ec82a..0fe7738 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -195,13 +195,18 @@ sub new { -or => '_expand_andor', }; - $opt{render_op} = our $RENDER_OP; + $opt{expand_op} = { + 'between' => '_expand_between', + 'not between' => '_expand_between', + }; $opt{render} = { (map +("-$_", "_render_$_"), qw(op func bind ident literal list)), %{$opt{render}||{}} }; + $opt{render_op} = our $RENDER_OP; + return bless \%opt, $class; } @@ -677,22 +682,8 @@ sub _expand_expr_hashpair { belch 'Use of [and|or|nest]_N modifiers is deprecated and will be removed in SQLA v2.0. ' . "You probably wanted ...-and => [ -$op => COND1, -$op => COND2 ... ]"; } - if ($op =~ /^(?:not )?between$/) { - local our $Cur_Col_Meta = $k; - my @rhs = map $self->_expand_expr($_), - ref($vv) eq 'ARRAY' ? @$vv : $vv; - unless ( - (@rhs == 1 and ref($rhs[0]) eq 'HASH' and $rhs[0]->{-literal}) - or - (@rhs == 2 and defined($rhs[0]) and defined($rhs[1])) - ) { - puke "Operator '${\uc($op)}' requires either an arrayref with two defined values or expressions, or a single literal scalarref/arrayref-ref"; - } - return +{ -op => [ - $op, - $self->_expand_ident(-ident => $k), - @rhs - ] } + if (my $x = $self->{expand_op}{$op}) { + return $self->$x($op, $vv, $k); } if ($op =~ /^(?:not )?in$/) { if (my $literal = is_literal_value($vv)) { @@ -928,6 +919,25 @@ sub _expand_andor { die "notreached"; } +sub _expand_between { + my ($self, $op, $vv, $k) = @_; + local our $Cur_Col_Meta = $k; + my @rhs = map $self->_expand_expr($_), + ref($vv) eq 'ARRAY' ? @$vv : $vv; + unless ( + (@rhs == 1 and ref($rhs[0]) eq 'HASH' and $rhs[0]->{-literal}) + or + (@rhs == 2 and defined($rhs[0]) and defined($rhs[1])) + ) { + puke "Operator '${\uc($op)}' requires either an arrayref with two defined values or expressions, or a single literal scalarref/arrayref-ref"; + } + return +{ -op => [ + $op, + $self->_expand_ident(-ident => $k), + @rhs + ] } +} + sub _recurse_where { my ($self, $where, $logic) = @_;