From: Matt S Trout Date: Sun, 28 Oct 2018 00:36:11 +0000 (+0000) Subject: dbic uses _order_by_chunks, unsure how to unit test X-Git-Tag: v2.000000~3^2~431 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2af21cb852b6c6c629ce0eda1116fd366cea666b;p=dbsrgits%2FSQL-Abstract.git dbic uses _order_by_chunks, unsure how to unit test --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 460a2f4..f8518de 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1045,10 +1045,10 @@ sub _open_outer_paren { # ORDER BY #====================================================================== -sub _order_by { +sub _expand_order_by { my ($self, $arg) = @_; - return '' unless defined($arg) and not (ref($arg) eq 'ARRAY' and !@$arg); + return unless defined($arg) and not (ref($arg) eq 'ARRAY' and !@$arg); my $expander = sub { my ($self, $dir, $expr) = @_; @@ -1072,7 +1072,13 @@ sub _order_by { sub { shift->$expander(desc => @_) }, ); - my $expanded = $self->$expander(undef, $arg); + return $self->$expander(undef, $arg); +} + +sub _order_by { + my ($self, $arg) = @_; + + return '' unless defined(my $expanded = $self->_expand_order_by($arg)); my ($sql, @bind) = $self->_render_expr($expanded); @@ -1081,6 +1087,21 @@ sub _order_by { return wantarray ? ($final_sql, @bind) : $final_sql; } +sub _order_by_chunks { + my ($self, $arg) = @_; + + return () unless defined(my $expanded = $self->_expand_order_by($arg)); + + for ($expanded) { + if (ref() eq 'HASH' and my $op = $_->{-op}) { + if ($op->[0] eq ',') { + return map [ $self->_render_expr($_) ], @{$op}[1..$#$op]; + } + } + return [ $self->_render_expr($_) ]; + } +} + #====================================================================== # DATASOURCE (FOR NOW, JUST PLAIN TABLE OR LIST OF TABLES) #======================================================================