X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=927e33727507a6f9b87be4155dff3a1e9b961033;hb=80367e8a18152097da8ebad21b502ab1a27ec383;hp=330780ac3f63c0b4ee3ec17bb2e4d44fb2e3a04c;hpb=316b9be9e2ddadf4dad5b0e051aa6f975d95698a;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 330780a..927e337 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -28,7 +28,7 @@ BEGIN { # GLOBALS #====================================================================== -our $VERSION = '1.86'; +our $VERSION = '1.90_02'; # This would confuse some packagers $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases @@ -293,6 +293,19 @@ sub new { ); }; } + foreach my $type (qw(in between)) { + my $meth = "_where_field_".uc($type); + if (__PACKAGE__->can($meth) ne $class->can($meth)) { + my $exp = sub { + my ($self, $op, $v, $k) = @_; + $op = join ' ', split '_', $op; + return +{ -literal => [ + $self->$meth($k, $op, $v) + ] }; + }; + $opt{expand_op}{$_} = $exp for $type, "not_${type}"; + } + } if ($class->isa('DBIx::Class::SQLMaker')) { $opt{warn_once_on_nest} = 1; $opt{disable_old_special_ops} = 1; @@ -301,6 +314,11 @@ sub new { s/\A\s+//, s/\s+\Z// for $sql; return [ $sql, @bind ]; }; + $opt{expand_op}{ident} = $class->make_unop_expander(sub { + my ($self, undef, $body) = @_; + $body = $body->from if Scalar::Util::blessed($body); + $self->_expand_ident(ident => $body); + }); } } @@ -358,8 +376,11 @@ BEGIN { my $name = join '_', reverse split '_', $type; my $singular = "${type}er"; - eval qq{sub ${singular} { shift->${singular}s(\@_) }; 1 } - or die "Method builder failed for ${singular}: $@"; + eval qq{sub ${singular} { + my \$self = shift; + return \$self->_ext_rw('${name}', \@_) if \@_ == 1; + return \$self->${singular}s(\@_) + }; 1 } or die "Method builder failed for ${singular}: $@"; eval qq{sub wrap_${singular} { shift->wrap_${singular}s(\@_) }; 1 } or die "Method builder failed for wrap_${singular}: $@"; @@ -955,7 +976,7 @@ sub _expand_hashpair { } if ($k =~ /^-./) { return $self->_expand_hashpair_op($k, $v); - } elsif ($k =~ /^[^\w]/i) { + } elsif ($k =~ /^\W+$/) { my ($lhs, @rhs) = ref($v) eq 'ARRAY' ? @$v : $v; return $self->_expand_op( -op, [ $k, $self->expand_expr($lhs, -ident), @rhs ] @@ -1276,7 +1297,7 @@ sub _expand_bool { sub _expand_list { my ($self, undef, $expr) = @_; return { -op => [ - ',', map $self->expand_expr($_), + ',', map $self->expand_expr($_), @{$expr->{-op}}[1..$#{$expr->{-op}}] ] } if ref($expr) eq 'HASH' and ($expr->{-op}||[''])->[0] eq ','; return +{ -op => [ ',', @@ -1673,6 +1694,25 @@ sub _open_outer_paren { $sql; } +sub _where_field_IN { + my ($self, $k, $op, $vals) = @_; + @{$self->_render_op_in( + $op, + [ + $self->expand_expr($k, -ident), + map $self->expand_expr($_, -value), + ref($vals) eq 'ARRAY' ? @$vals : $vals + ] + )}; +} + +sub _where_field_BETWEEN { + my ($self, $k, $op, $vals) = @_; + @{$self->_render_op_between( + $op, + [ $self->expand_expr($k, -ident), ref($vals) eq 'ARRAY' ? @$vals : $vals ] + )}; +} #====================================================================== # ORDER BY