From: Matt S Trout Date: Tue, 26 Mar 2019 04:40:00 +0000 (+0000) Subject: extract scalar handling X-Git-Tag: v2.000000~3^2~323 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=016b47d10b4a1fe0b1bd13d64adfac75f9867357;p=dbsrgits%2FSQL-Abstract.git extract scalar handling --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 1e3033a..a4db249 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -201,6 +201,7 @@ sub new { -and => '_expand_op_andor', -or => '_expand_op_andor', -nest => '_expand_nest', + -bind => sub { shift; +{ @_ } }, }; $opt{expand_op} = { @@ -603,10 +604,7 @@ sub _expand_expr { return +{ -literal => $literal }; } if (!ref($expr) or Scalar::Util::blessed($expr)) { - if (my $d = our $Default_Scalar_To) { - return $self->_expand_expr({ $d => $expr }); - } - return $self->_expand_value(-value => $expr); + return $self->_expand_expr_scalar($expr); } die "notreached"; } @@ -629,6 +627,8 @@ sub _expand_expr_hashpair { sub _expand_expr_hashpair_ident { my ($self, $k, $v) = @_; + local our $Cur_Col_Meta = $k; + # hash with multiple or no elements is andor if (ref($v) eq 'HASH' and keys %$v != 1) { @@ -644,15 +644,7 @@ sub _expand_expr_hashpair_ident { # scalars and objects get expanded as whatever requested or values if (!ref($v) or Scalar::Util::blessed($v)) { - my $d = our $Default_Scalar_To; - local our $Cur_Col_Meta = $k; - return $self->_expand_expr_hashpair_ident( - $k, - ($d - ? $self->_expand_expr($d => $v) - : { -value => $v } - ) - ); + return $self->_expand_expr_hashpair_scalar($k, $v); } if (ref($v) eq 'HASH') { return $self->_expand_expr_hashtriple($k, %$v); @@ -685,6 +677,23 @@ sub _expand_expr_hashpair_ident { die "notreached"; } +sub _expand_expr_scalar { + my ($self, $expr) = @_; + + if (my $d = our $Default_Scalar_To) { + return $self->_expand_expr({ $d => $expr }); + } + return $self->_expand_value(-value => $expr); +} + +sub _expand_expr_hashpair_scalar { + my ($self, $k, $v) = @_; + + return $self->_expand_expr_hashpair_cmp( + $k, $self->_expand_expr_scalar($v), + ); +} + sub _expand_expr_hashpair_op { my ($self, $k, $v) = @_;