From: Peter Rabbitson Date: Thu, 4 Sep 2014 10:50:11 +0000 (+0200) Subject: Add one more spot of unroll X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c1f3f2e8a79c6a4081c9949fa30da09d18d64d3b;p=dbsrgits%2FDBIx-Class-Historic.git Add one more spot of unroll --- diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index f13be43..4c07f5e 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -1223,6 +1223,18 @@ sub _collapse_cond_unroll_pairs { push @conds, { $lhs => $rhs }; } } + # unroll func + { -value => ... } + elsif ( + ref $rhs eq 'HASH' + and + ( my ($subop) = keys %$rhs ) == 1 + and + length ref ((values %$rhs)[0]) + and + my $vref = is_plain_value( (values %$rhs)[0] ) + ) { + push @conds, { $lhs => { $subop => @$vref } } + } else { push @conds, { $lhs => $rhs }; } diff --git a/t/sqlmaker/dbihacks_internals.t b/t/sqlmaker/dbihacks_internals.t index a225cdc..b635d6f 100644 --- a/t/sqlmaker/dbihacks_internals.t +++ b/t/sqlmaker/dbihacks_internals.t @@ -147,10 +147,17 @@ for my $t ( ) ), { - where => { -or => [ -and => [ foo => { '!=', undef }, bar => { -in => [ 69, 42 ] } ], foo => { '=', { -value => undef } } ] }, - sql => 'WHERE ( foo IS NOT NULL AND bar IN ( ?, ? ) ) OR foo IS NULL', - collapsed_sql => 'WHERE foo IS NULL OR ( bar IN ( ?, ? ) AND foo IS NOT NULL )', + where => { -or => [ + -and => [ foo => { '!=', { -value => undef } }, bar => { -in => [ 69, 42 ] } ], + foo => { '=', { -value => undef } }, + baz => { '!=' => { -ident => 'bozz' } }, + baz => { -ident => 'buzz' }, + ] }, + sql => 'WHERE ( foo IS NOT NULL AND bar IN ( ?, ? ) ) OR foo IS NULL OR baz != bozz OR baz = buzz', + collapsed_sql => 'WHERE baz != bozz OR baz = buzz OR foo IS NULL OR ( bar IN ( ?, ? ) AND foo IS NOT NULL )', cc_result => { -or => [ + baz => { '!=' => { -ident => 'bozz' } }, + baz => { '=' => { -ident => 'buzz' } }, foo => undef, { bar => { -in => [ 69, 42 ] }, foo => { '!=', undef } } ] },