[Bast-commits] r7766 - in DBIx-Class/0.08/branches/is_resultset_paginated: lib/DBIx/Class t/resultset

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Wed Oct 7 18:31:03 GMT 2009


Author: frew
Date: 2009-10-07 18:31:02 +0000 (Wed, 07 Oct 2009)
New Revision: 7766

Added:
   DBIx-Class/0.08/branches/is_resultset_paginated/t/resultset/is_paginated.t
Modified:
   DBIx-Class/0.08/branches/is_resultset_paginated/lib/DBIx/Class/ResultSet.pm
Log:
is_paginated method and test

Modified: DBIx-Class/0.08/branches/is_resultset_paginated/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/is_resultset_paginated/lib/DBIx/Class/ResultSet.pm	2009-10-07 18:05:05 UTC (rev 7765)
+++ DBIx-Class/0.08/branches/is_resultset_paginated/lib/DBIx/Class/ResultSet.pm	2009-10-07 18:31:02 UTC (rev 7766)
@@ -519,7 +519,7 @@
     # in ::Relationship::Base::search_related (the row method), and furthermore
     # the relationship is of the 'single' type. This means that the condition
     # provided by the relationship (already attached to $self) is sufficient,
-    # as there can be only one row in the databse that would satisfy the 
+    # as there can be only one row in the databse that would satisfy the
     # relationship
   }
   else {
@@ -1240,7 +1240,7 @@
 
   my $tmp_attrs = { %$attrs };
 
-  # take off any limits, record_filter is cdbi, and no point of ordering a count 
+  # take off any limits, record_filter is cdbi, and no point of ordering a count
   delete $tmp_attrs->{$_} for (qw/select as rows offset order_by record_filter/);
 
   # overwrite the selector (supplied by the storage)
@@ -2564,6 +2564,17 @@
   shift->set_cache(undef);
 }
 
+=head2 is_paginated
+
+Returns true if the resultset has been paginated
+
+=cut
+
+sub is_paginated {
+  my ($self) = @_;
+  return !!$self->{attrs}{page};
+}
+
 =head2 related_resultset
 
 =over 4
@@ -2711,8 +2722,8 @@
   }];
 
   my $seen = { %{$attrs->{seen_join} || {} } };
-  my $jpath = ($attrs->{seen_join} && keys %{$attrs->{seen_join}}) 
-    ? $from->[-1][0]{-join_path} 
+  my $jpath = ($attrs->{seen_join} && keys %{$attrs->{seen_join}})
+    ? $from->[-1][0]{-join_path}
     : [];
 
 
@@ -2948,7 +2959,7 @@
   # even though it doesn't make much sense, this is what pre 081xx has
   # been doing
   if (my $page = delete $attrs->{page}) {
-    $attrs->{offset} = 
+    $attrs->{offset} =
       ($attrs->{rows} * ($page - 1))
             +
       ($attrs->{offset} || 0)
@@ -3143,7 +3154,7 @@
 
 =back
 
-Which column(s) to order the results by. 
+Which column(s) to order the results by.
 
 [The full list of suitable values is documented in
 L<SQL::Abstract/"ORDER BY CLAUSES">; the following is a summary of
@@ -3435,12 +3446,12 @@
 
 =over 4
 
-=item * 
+=item *
 
 Prefetch uses the L</cache> to populate the prefetched relationships. This
 may or may not be what you want.
 
-=item * 
+=item *
 
 If you specify a condition on a prefetched relationship, ONLY those
 rows that match the prefetched condition will be fetched into that relationship.

Added: DBIx-Class/0.08/branches/is_resultset_paginated/t/resultset/is_paginated.t
===================================================================
--- DBIx-Class/0.08/branches/is_resultset_paginated/t/resultset/is_paginated.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/is_resultset_paginated/t/resultset/is_paginated.t	2009-10-07 18:31:02 UTC (rev 7766)
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+use lib qw(t/lib);
+use Test::More;
+use Test::Exception;
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+my $tkfks = $schema->resultset('Artist');
+
+ok !$tkfks->is_paginated, 'vanilla resultset is not paginated';
+
+my $paginated = $tkfks->search(undef, { page => 5 });
+ok $paginated->is_paginated, 'resultset is paginated now';
+
+done_testing;
+




More information about the Bast-commits mailing list