From: Ash Berlin Date: Sun, 29 Mar 2009 22:58:39 +0000 (+0100) Subject: Support setting default cmp operator in compat X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f94aef7f1ad8b1634a80225ee2e47b75f3ea7a45;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Support setting default cmp operator in compat --- diff --git a/lib/SQL/Abstract/Compat.pm b/lib/SQL/Abstract/Compat.pm index 471ca04..09b586a 100644 --- a/lib/SQL/Abstract/Compat.pm +++ b/lib/SQL/Abstract/Compat.pm @@ -18,7 +18,8 @@ class SQL::Abstract::Compat { is => 'rw', isa => LogicEnum, default => 'AND', - coerce => 1 + coerce => 1, + required => 1, ); has visitor => ( @@ -29,6 +30,16 @@ class SQL::Abstract::Compat { builder => '_build_visitor', ); + has cmp => ( + is => 'rw', + isa => 'Str', + default => '=', + required => 1, + ); + + our %CMP_MAP = ( + '=' => '==', + ); method select(Str|ArrayRef|ScalarRef $from, ArrayRef|Str $fields, WhereType $where?, @@ -145,9 +156,10 @@ class SQL::Abstract::Compat { } method field(Str $key, $value) returns (AST) { + my $op = $CMP_MAP{$self->cmp} || $self->cmp; my $ret = { -type => 'expr', - op => '==', + op => $op, args => [ { -type => 'name', args => [$key] } ], @@ -183,7 +195,7 @@ class SQL::Abstract::Compat { args => [ map { { -type => 'expr', - op => '==', + op => $op, args => [ { -type => 'name', args => [$key] }, $self->value($_) diff --git a/t/compat/00new.t b/t/compat/00new.t index 732c0d9..083b7dd 100644 --- a/t/compat/00new.t +++ b/t/compat/00new.t @@ -43,13 +43,13 @@ my @handle_tests = ( # acked by RIBASUSHI stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' }, -); -my @foo = ( #6 { args => {cmp => "like"}, stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )' }, +); +my @foo = ( #7 { args => {logic => "or", cmp => "like"},