Added pager support, same syntax as Sweet. Also fixed a few issues with ResultSet...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSet.pm
index 644ff76..936bfdb 100644 (file)
@@ -42,15 +42,19 @@ sub next {
 
 sub count {
   my ($self) = @_;
-  return $self->{attrs}{rows} if $self->{attrs}{rows};
-    # This is a hack, and will break on the last page of a paged set.
-    # Once we have limit support in Storage, kill it.
-
   my $db_class = $self->{class};
+
+  # offset breaks COUNT(*), so remove it
+  my $attrs = { %{ $self->{attrs} } };
+  delete $attrs->{offset};
+      
   my @cols = 'COUNT(*)';
   my ($c) = $db_class->storage->select_single($db_class->_table_name, \@cols,
-                                            $self->{cond}, $self->{attrs});
-  return $c; # ($cursor->next)[0];
+                                            $self->{cond}, $attrs);
+  return 0 unless $c;
+  return ( $attrs->{rows} && $attrs->{rows} < $c ) 
+    ? $attrs->{rows} 
+    : $c;
 }
 
 sub all {