X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=2f80a434fdfc93aa87abbf64f0c91bd7dd06f0b8;hb=3e0e9e276de1823691989e19575edc86658155f3;hp=4ab33896673a68dc0d07e1c83823770a69a85f12;hpb=3fb6c5fe70f9453f7524e68cf252b81619f13dbd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4ab3389..2f80a43 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -155,7 +155,6 @@ call it as C. sub search { my $self = shift; - #use Data::Dumper;warn Dumper(@_); my $rs; if( @_ ) { @@ -165,7 +164,14 @@ sub search { $attrs = { %$attrs, %{ pop(@_) } }; } - my $where = (@_ ? ((@_ == 1 || ref $_[0] eq "HASH") ? shift : {@_}) : undef()); + my $where = (@_ + ? ((@_ == 1 || ref $_[0] eq "HASH") + ? shift + : ((@_ % 2) + ? $self->throw_exception( + "Odd number of arguments to search") + : {@_})) + : undef()); if (defined $where) { $where = (defined $attrs->{where} ? { '-and' => @@ -377,13 +383,17 @@ Can be used to efficiently iterate over records in the resultset: sub next { my ($self) = @_; - my $cache = $self->get_cache; - if( @$cache ) { + my $cache; + if( @{$cache = $self->{all_cache} || []}) { $self->{all_cache_position} ||= 0; my $obj = $cache->[$self->{all_cache_position}]; $self->{all_cache_position}++; return $obj; } + if ($self->{attrs}{cache}) { + $self->{all_cache_position} = 0; + return ($self->all)[0]; + } my @row = $self->cursor->next; # warn Dumper(\@row); use Data::Dumper; return unless (@row); @@ -555,7 +565,7 @@ sub all { my @obj = map { $self->_construct_object(@$_); } $self->cursor->all; $self->set_cache( \@obj ); - return @{ $self->get_cache }; + return @obj; } return map { $self->_construct_object(@$_); } $self->cursor->all;