Subject: | Patch for slide problem (first shift left is skipped) |
Date: | Fri, 22 Feb 2008 00:19:23 -0800 |
To: | bug-Data-Pageset [...] rt.cpan.org |
From: | Ryan D Johnson <ryan [...] innerfence.com> |
Hi. I noticed a problem with Data::Pageset in sliding mode:
ryan@rdj-laptop ~ $ re.pl
$ use Data::Pageset;
$ my $p = Data::Pageset->new({ total_entries => 500, entries_per_page =>
20, current_page => 22, pages_per_set => 5, mode => 'slide' );
$Data_Pageset1 = Data::Pageset=HASH(0x8e3a55c);
$ $p->pages_in_set;
$ARRAY1 = [
21,
22,
23,
24,
25
];
In this example, page 22 should be in the middle.
I've enclosed a patch that fixed the error (a >= instead of just a >),
including new test cases. I wasn't able to find a source repository, so
it's just an interdir diff.
I hope you'll accept this patch so that the fix will be available for
everyone on CPAN.
Thanks for the hard work and for sharing it with the community!
/rdj
diff -urN /home/ryan/.cpan/build/Data-Pageset-1.04-vxuNeK/Changes ./Changes
--- /home/ryan/.cpan/build/Data-Pageset-1.04-vxuNeK/Changes 2008-02-10 09:36:15.000000000 -0800
+++ ./Changes 2008-02-21 23:55:43.000000000 -0800
@@ -1,5 +1,8 @@
Revision history for Perl extension Data::Pageset.
+1.05 Unreleased
+ - fix bug in slide where last slide position is skipped
+
1.04 Thu Mar 9 22:55:44 GMT 2006
- Apply patch from http://rt.cpan.org/Public/Bug/Display.html?id=27384
to fix slider bug - thanks to PLOBBES
diff -urN /home/ryan/.cpan/build/Data-Pageset-1.04-vxuNeK/lib/Data/Pageset.pm ./lib/Data/Pageset.pm
--- /home/ryan/.cpan/build/Data-Pageset-1.04-vxuNeK/lib/Data/Pageset.pm 2008-02-10 09:34:41.000000000 -0800
+++ ./lib/Data/Pageset.pm 2008-02-21 23:52:24.000000000 -0800
@@ -9,7 +9,7 @@
@ISA = qw(Data::Page);
-$VERSION = '1.04';
+$VERSION = '1.04_01';
=head1 NAME
@@ -256,6 +256,7 @@
$self->{PAGE_SET_PAGES} = [ '1' .. $self->last_page() ];
} else {
+
# Find the middle rounding down - we want more pages after, than before
my $middle = int( $max_pages_per_set / 2 );
@@ -281,7 +282,7 @@
= $max_pages_per_set + $middle - $offset;
$self->{PAGE_SET_PAGES} = [ '1' .. $max_pages_per_set ];
} elsif ( $self->current_page()
- >= ( $self->last_page() - $middle - $offset ) )
+ > ( $self->last_page() - $middle - $offset ) )
{
# near the end of the page numbers
@@ -386,6 +387,10 @@
Leo Lapworth <lt>LLAP@cuckoo.org<gt> - let me know if you've used
this module - go on... you know you want to.
+=head1 CONTRIBUTORS
+
+Ryan D Johnson C<< <ryan@innerfence.com> >>
+
=head1 SEE ALSO
L<Data::Page>.
diff -urN /home/ryan/.cpan/build/Data-Pageset-1.04-vxuNeK/t/main.t ./t/main.t
--- /home/ryan/.cpan/build/Data-Pageset-1.04-vxuNeK/t/main.t 2007-09-02 08:52:06.000000000 -0700
+++ ./t/main.t 2008-02-22 00:00:08.000000000 -0800
@@ -4,7 +4,7 @@
use lib qw( ./blib/lib ../blib/lib );
-use Test::More tests => 499;
+use Test::More tests => 554;
# Check we can load module
BEGIN { use_ok( 'Data::Pageset' ); }
@@ -260,3 +260,14 @@
999 10 20 10 1 100 191 200 19 20 21 190,191,192,193,194,195,196,197,198,199 30 10 16,17,18,19,20,21,22,23,24,25 slide
1070 20 54 15 1 54 1061 1070 53 54 undef 1060,1061,1062,1063,1064,1065,1066,1067,1068,1069 undef 32 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 slide
209 10 5 5 1 21 41 50 4 5 6 40,41,42,43,44,45,46,47,48,49 10 1 3,4,5,6,7 slide
+
+# High pages - shift left two
+500 20 21 5 1 25 401 420 20 21 22 400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419 26 16 19,20,21,22,23 slide
+# High pages - shift left one
+500 20 22 5 1 25 421 440 21 22 23 420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439 27 17 20,21,22,23,24 slide
+# High pages - first fixed
+500 20 23 5 1 25 441 460 22 23 24 440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459 undef 18 21,22,23,24,25 slide
+# High pages - penultimate fixed
+500 20 24 5 1 25 461 480 23 24 25 460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479 undef 18 21,22,23,24,25 slide
+# High pages - final page
+500 20 25 5 1 25 481 500 24 25 undef 480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499 undef 18 21,22,23,24,25 slide