[Dbix-class] Status update, plans

Dan Kubb dan.kubb at autopilotmarketing.com
Sun Jul 31 04:12:09 CEST 2005


Hi Matt,

> Next time I get a chance to hack on it I'm going to build a cursor
> (iterator) class and move all search/retrieve stuff over to using it
> (although in array context all the objects will still be returned,  
> of course).

How about returning a tied array that uses the cursor underneath
instead of returning a plain array?

Inside the tied array you'd have the cursor object, a cache all the  
objects
that have been fetched so far, your current position within the  
result-set
and maybe the total result-set size -- if you can know it without  
fetching
it all back first.  The total size is possible to know with some data  
sources,
like recent versions of MySQL.

If the caller asks for $pos + 1 you'd just return $cursor->next (or  
whatever).
If they request an item less than or equal to $pos, you'd return the  
object
from the cache. If they request an item greater than $pos + 1, you'd  
just
fast-forward to that point (caching as you go) and return $cursor->next.

The advantage is that loading the objects is delayed until they are
absolutely needed.  An even bigger gain is made if the array isn't used
at all.

-- 

Dan Kubb



More information about the Dbix-class mailing list