From: Peter Rabbitson Date: Mon, 25 May 2009 06:48:38 +0000 (+0000) Subject: Factor out the order_by sqlahacks resolver X-Git-Tag: v0.08103~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fde3719aca80cb4012aea1391758d629250289fc;p=dbsrgits%2FDBIx-Class.git Factor out the order_by sqlahacks resolver --- diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index b38dbf5..63834e3 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -259,22 +259,34 @@ sub _order_by { sub _order_directions { my ($self, $order) = @_; - $order = $order->{order_by} if ref $order eq 'HASH'; + return $self->SUPER::_order_directions( $self->_resolve_order($order) ); +} + +sub _resolve_order { + my ($self, $order) = @_; + $order = $order->{order_by} if (ref $order eq 'HASH' and $order->{order_by}); + if (ref $order eq 'HASH') { - $order = [$self->_order_directions_hash($order)]; - } elsif (ref $order eq 'ARRAY') { + $order = [$self->_resolve_order_hash($order)]; + } + elsif (ref $order eq 'ARRAY') { $order = [map { - if (ref $_ eq 'HASH') { - $self->_order_directions_hash($_); - } else { - $_; + if (ref ($_) eq 'SCALAR') { + $$_ + } + elsif (ref ($_) eq 'HASH') { + $self->_resolve_order_hash($_) } - } @{ $order }]; + else { + $_ + } + } @$order]; } - return $self->SUPER::_order_directions($order); + + return $order; } -sub _order_directions_hash { +sub _resolve_order_hash { my ($self, $order) = @_; my @new_order; foreach my $key (keys %{ $order }) { diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 32084bd..0d9cace 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1187,7 +1187,7 @@ sub _select_args { my $bind_attrs = {}; ## Future support my @args = ('select', $attrs->{bind}, $ident, $bind_attrs, $select, $condition, $order); if ($attrs->{software_limit} || - $self->sql_maker->_default_limit_syntax eq "GenericSubQ") { + $sql_maker->_default_limit_syntax eq "GenericSubQ") { $attrs->{software_limit} = 1; } else { $self->throw_exception("rows attribute must be positive if present")