From: Matt S Trout Date: Wed, 17 Oct 2018 22:59:14 +0000 (+0000) Subject: also barf on arrayref based order_by with the same problem X-Git-Tag: v2.000000~3^2~434 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9d4775b6d98c1d636a955dce784f4f366ed03aac;p=dbsrgits%2FSQL-Abstract.git also barf on arrayref based order_by with the same problem --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index eb0f157..2603608 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1050,20 +1050,21 @@ sub _order_by { my $expander = sub { my ($self, $dir, $expr) = @_; + my @to_expand = ref($expr) eq 'ARRAY' ? @$expr : $expr; + foreach my $arg (@to_expand) { + if ( + ref($arg) eq 'HASH' + and keys %$arg > 1 + and grep /^-(asc|desc)$/, keys %$arg + ) { + puke "ordering direction hash passed to order by must have exactly one key (-asc or -desc)"; + } + } my @exp = map +(defined($dir) ? { -op => [ $dir => $_ ] } : $_), - map $self->_expand_expr($_, undef, -ident), - ref($expr) eq 'ARRAY' ? @$expr : $expr; + map $self->_expand_expr($_, undef, -ident), @to_expand; return (@exp > 1 ? { -op => [ ',', @exp ] } : $exp[0]); }; - if ( - ref($arg) eq 'HASH' - and keys %$arg > 1 - and grep /^-(asc|desc)$/, keys %$arg - ) { - puke "ordering direction hash passed to order by must have exactly one key (-asc or -desc)"; - } - local @{$self->{expand_unary}}{qw(-asc -desc)} = ( sub { shift->$expander(asc => @_) }, sub { shift->$expander(desc => @_) }, diff --git a/t/06order_by.t b/t/06order_by.t index 7d1213e..e3b94f7 100644 --- a/t/06order_by.t +++ b/t/06order_by.t @@ -134,6 +134,12 @@ throws_ok ( ); throws_ok ( + sub { $sql->_order_by([ {-desc => 'colA', -asc => 'colB' } ]) }, + qr/hash passed .+ must have exactly one key/, + 'Undeterministic order exception', +); + +throws_ok ( sub { $sql->_order_by({-desc => [ qw/colA colB/ ], -asc => [ qw/colC colD/ ] }) }, qr/hash passed .+ must have exactly one key/, 'Undeterministic order exception',