From: Matt S Trout Date: Fri, 20 Apr 2012 10:03:55 +0000 (+0000) Subject: parse simple order literals X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3d82b6c9f79e8fd739351c532e686dbee82c4f88;p=dbsrgits%2FSQL-Abstract.git parse simple order literals --- diff --git a/lib/SQL/Abstract/Converter.pm b/lib/SQL/Abstract/Converter.pm index 6621945..78a4292 100644 --- a/lib/SQL/Abstract/Converter.pm +++ b/lib/SQL/Abstract/Converter.pm @@ -552,7 +552,7 @@ sub _order_by_to_dq { my $dq = { type => DQ_ORDER, - (defined($dir) ? (reverse => !!$dir =~ /desc/i) : ()), + (defined($dir) ? (reverse => !!($dir =~ /desc/i)) : ()), ($from ? (from => $from) : ()), }; @@ -575,7 +575,12 @@ sub _order_by_to_dq { } elsif (ref($arg) eq 'REF' and ref($$arg) eq 'ARRAY') { $dq->{by} = $self->_literal_to_dq($$arg); } elsif (ref($arg) eq 'SCALAR') { - $dq->{by} = $self->_literal_to_dq($$arg); + if (my ($ident, $dir) = $$arg =~ /^(\w+)(?:\s+(desc|asc))?/i) { + $dq->{by} = $self->_ident_to_dq($ident); + $dq->{reverse} = 1 if $dir and lc($dir) eq 'desc'; + } else { + $dq->{by} = $self->_literal_to_dq($$arg); + } } elsif (ref($arg) eq 'HASH') { my ($key, $val, @rest) = %$arg;