DBIx::Class::SQLAHacks;
use base qw/SQL::Abstract::Limit/;
+use strict;
+use warnings;
use Carp::Clan qw/^DBIx::Class/;
sub new {
sub _order_directions {
my ($self, $order) = @_;
$order = $order->{order_by} if ref $order eq 'HASH';
+ if (ref $order eq 'HASH') {
+ $order = [$self->_order_directions_hash($order)];
+ } elsif (ref $order eq 'ARRAY') {
+ $order = [map {
+ if (ref $_ eq 'HASH') {
+ $self->_order_directions_hash($_);
+ } else {
+ $_;
+ }
+ } @{ $order }];
+ }
return $self->SUPER::_order_directions($order);
}
+sub _order_directions_hash {
+ my ($self, $order) = @_;
+ my @new_order;
+ foreach my $key (keys %{ $order }) {
+ if ($key =~ /^-(desc|asc)/i ) {
+ my $direction = $1;
+ my $type = ref $order->{ $key };
+ if ($type eq 'ARRAY') {
+ push @new_order, map( "$_ $direction", @{ $order->{ $key } } );
+ } elsif (!$type) {
+ push @new_order, "$order->{$key} $direction";
+ } else {
+ croak "hash order_by can only contain Scalar or Array, not $type";
+ }
+ } else {
+ croak "$key is not a valid direction, use -asc or -desc";
+ }
+ }
+ return @new_order;
+}
+
sub _table {
my ($self, $from) = @_;
if (ref $from eq 'ARRAY') {