Consolidate handling of "is this a literal" and "is this a value"
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Cursor.pm
index 6483ca7..6681d23 100644 (file)
@@ -59,8 +59,15 @@ Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
       attrs => $attrs,
     }, ref $class || $class;
 
-    weaken( $cursor_registry{ refaddr($self) } = $self )
-      if DBIx::Class::_ENV_::HAS_ITHREADS;
+    if (DBIx::Class::_ENV_::HAS_ITHREADS) {
+
+      # quick "garbage collection" pass - prevents the registry
+      # from slowly growing with a bunch of undef-valued keys
+      defined $cursor_registry{$_} or delete $cursor_registry{$_}
+        for keys %cursor_registry;
+
+      weaken( $cursor_registry{ refaddr($self) } = $self )
+    }
 
     return $self;
   }
@@ -113,9 +120,11 @@ sub next {
     return;
   }
 
-
   unless ($sth = $self->sth) {
-    (undef, $sth) = $self->storage->_select( @{$self->{args}} );
+    (undef, $sth, undef) = $self->storage->_select( @{$self->{args}} );
+
+    $self->{_results} = [ (undef) x $sth->FETCH('NUM_OF_FIELDS') ];
+    $sth->bind_columns( \( @{$self->{_results}} ) );
 
     if ( $self->{attrs}{software_limit} and $self->{attrs}{offset} ) {
       $sth->fetch for 1 .. $self->{attrs}{offset};
@@ -124,14 +133,13 @@ sub next {
     $self->sth($sth);
   }
 
-  my $row = $sth->fetchrow_arrayref;
-  if ($row) {
+  if ($sth->fetch) {
     $self->{_pos}++;
+    return @{$self->{_results}};
   } else {
     $self->{_done} = 1;
+    return ();
   }
-
-  return @{$row||[]};
 }