sub search {
my $self = shift;
- #use Data::Dumper;warn Dumper(@_);
my $rs;
if( @_ ) {
$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' =>
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);
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;