[Bps-public-commit] r9734 - DBIx-SearchBuilder/trunk/SearchBuilder

ruz at bestpractical.com ruz at bestpractical.com
Fri Nov 23 18:05:56 EST 2007


Author: ruz
Date: Fri Nov 23 18:05:56 2007
New Revision: 9734

Modified:
   DBIx-SearchBuilder/trunk/SearchBuilder/Union.pm

Log:
::Union::Next
* fix situation when there are more than two collections in an union
  and a collection next to the current is empty, so we should jump
  over it


Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Union.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Union.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Union.pm	Fri Nov 23 18:05:56 2007
@@ -103,22 +103,22 @@
 =cut
 
 sub Next {
-  my $self=shift;
+    my $self=shift;
 
-  return undef unless defined  $self->{data}[ $self->{curp} ];
-    
-  my $cur =  $self->{data}[ $self->{curp} ];
-  # do the search to avoid the count query and the search
-  $cur->_DoSearch if $cur->{'must_redo_search'};
-  if ( $cur->_ItemsCounter == $cur->Count ) {
-	# move to the next element
-	$self->{curp}++;
-	return undef unless defined   $self->{data}[ $self->{curp} ];
-	$cur =  $self->{data}[ $self->{curp} ];
-	$self->{data}[ $self->{curp} ]->GotoFirstItem;
-  }
-  $self->{item}++;
-  $cur->Next;
+    my $goto_first = 0;
+    while ( my $cur = $self->{'data'}[ $self->{'curp'} ] ) {
+        $cur->GotoFirstItem if $goto_first;
+
+        my $res = $cur->Next;
+        if ( $res ) {
+            $self->{'item'}++;
+            return $res;
+        }
+
+        $goto_first = 1;
+        $self->{'curp'}++;
+    }
+    return undef;
 }
 
 =head2 Last



More information about the Bps-public-commit mailing list