X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRetrieve.pm;h=87f531818f4557cab19ad0d0d0d94aac86e73c87;hb=d098704fa2e7e92b3a6cdf0a251f3e725623f9a4;hp=4c368873c973211c85d76552d5d078cd65af0f9f;hpb=e60dc79fcd4d6318e83584b826526e65048b86a9;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/CDBICompat/Retrieve.pm b/lib/DBIx/Class/CDBICompat/Retrieve.pm index 4c36887..87f5318 100644 --- a/lib/DBIx/Class/CDBICompat/Retrieve.pm +++ b/lib/DBIx/Class/CDBICompat/Retrieve.pm @@ -2,8 +2,11 @@ package # hide from PAUSE DBIx::Class::CDBICompat::Retrieve; use strict; -use warnings FATAL => 'all'; +# even though fatalization has been proven over and over to be a universally +# bad idea, this line has been part of the code from the beginning +# leaving the compat layer as-is, something may in fact depend on that +use warnings FATAL => 'all'; sub retrieve { my $self = shift; @@ -50,18 +53,31 @@ sub retrieve_from_sql { $cond =~ s/^\s*WHERE//i; - if( $cond =~ s/\bLIMIT (\d+)\s*$//i ) { - push @rest, { rows => $1 }; + # Need to parse the SQL clauses after WHERE in reverse + # order of appearance. + + my %attrs; + + if( $cond =~ s/\bLIMIT\s+(\d+)\s*$//i ) { + $attrs{rows} = $1; } - return $class->search_literal($cond, @rest); + if ( $cond =~ s/\bORDER\s+BY\s+(.*)\s*$//i ) { + $attrs{order_by} = $1; + } + + if( $cond =~ s/\bGROUP\s+BY\s+(.*)\s*$//i ) { + $attrs{group_by} = $1; + } + + return $class->search_literal($cond, @rest, ( %attrs ? \%attrs : () ) ); } sub construct { my $class = shift; my $obj = $class->resultset_instance->new_result(@_); $obj->in_storage(1); - + return $obj; }