CDBI::Iterator->first moves it's index pointer

[prev] [thread] [next] [Date index for 2004/11/10]

From: Rhesa Rozendaal
Subject: CDBI::Iterator->first moves it's index pointer
Date: 17:23 on 10 Nov 2004
I ran into a weird bug today.
I'm using an Iterator on a bunch of objects to create an rss feed.
I'm checking (with $it->first) whether the date of the first object is 
newer than the IF_MODIFIED_SINCE header, so I can return a 304 Not 
Modified if there are no new items.
However, if it _is_ newer, then I loop over the items with $it->next to 
populate the xml.

The bug: the latest news item never shows up in the feed.

It turns out that "first" does this:

	my $self = shift;
	$self->reset;
	return $self->next;

In other words, it moves the iterator to the next element, returning the 
first. I expected it to return the first element, and not move its index 
pointer.

I'm sure there are legitimate reasons for this behaviour, but it took me 
surprise.

Just thought I'd mention it.

Rhesa Rozendaal

CDBI::Iterator->first moves it's index pointer
Rhesa Rozendaal 17:23 on 10 Nov 2004

Re: CDBI::Iterator->first moves it's index pointer
Rhesa Rozendaal 21:31 on 10 Nov 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52