r31081 - in /branches/upstream/libdata-pageset-perl: ./ current/ current/lib/ current/lib/Data/ current/t/

edward at users.alioth.debian.org edward at users.alioth.debian.org
Tue Feb 24 09:47:11 UTC 2009


Author: edward
Date: Tue Feb 24 09:47:06 2009
New Revision: 31081

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=31081
Log:
[svn-inject] Installing original source of libdata-pageset-perl

Added:
    branches/upstream/libdata-pageset-perl/
    branches/upstream/libdata-pageset-perl/current/
    branches/upstream/libdata-pageset-perl/current/Changes
    branches/upstream/libdata-pageset-perl/current/MANIFEST
    branches/upstream/libdata-pageset-perl/current/MANIFEST.SKIP
    branches/upstream/libdata-pageset-perl/current/META.yml
    branches/upstream/libdata-pageset-perl/current/Makefile.PL
    branches/upstream/libdata-pageset-perl/current/README
    branches/upstream/libdata-pageset-perl/current/lib/
    branches/upstream/libdata-pageset-perl/current/lib/Data/
    branches/upstream/libdata-pageset-perl/current/lib/Data/Pageset.pm
    branches/upstream/libdata-pageset-perl/current/t/
    branches/upstream/libdata-pageset-perl/current/t/main.t

Added: branches/upstream/libdata-pageset-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/Changes?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/Changes (added)
+++ branches/upstream/libdata-pageset-perl/current/Changes Tue Feb 24 09:47:06 2009
@@ -1,0 +1,45 @@
+Revision history for Perl extension Data::Pageset.
+
+1.05 Fri Feb 22 10:46:45 GMT 2008
+	- Fix bug in slide where last slide position is skipped (Ryan)
+
+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
+
+1.03 Thu Mar  9 22:55:44 GMT 2006
+	- fix bug in last page of slide mode
+
+1.02 Sat 21st Jan 2006
+	- Added 'mode' option so you can be in 'slide' mode for your page numbers
+
+1.01 Sat 1st Jan 2005
+	- Fixed bug with setting current_page after object construction new()
+	- set default pages_per_set to 10 - was not previously defaulted to anything
+
+1.00 Thurs Oct 26 2004
+	- Added tests to get Devel::Cover to 100%
+	- removed extranious lines of code as checks are in Data::Page
+	- made compatable with Data::Page v 2.00
+
+0.06  Sun Aug 17 08:27:00 2003
+	- Fixed tests that broke from Data::Page bug fix
+	- Made require Data::Page 0.18
+
+0.05  - skipped
+
+0.04  Wed Mar 12 13:13:13 2003
+	- Removed 'our' values so will work with 5.00503
+	- Thanks to Robert Price
+	- Added thanks to Leon in Read me
+
+0.03  Mon Oct 28 13:56:00 2002
+	- Documentation patch - thanks to Robin Szemeti
+
+0.02  Fri Aug 30 16:00:48 2002
+	- First release version.
+
+0.01  Fri Aug 30 11:00:48 2002
+	- original version; created by h2xs 1.21 with options
+		-A -X -n Data::Pageset initial version
+		

Added: branches/upstream/libdata-pageset-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/MANIFEST?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/MANIFEST (added)
+++ branches/upstream/libdata-pageset-perl/current/MANIFEST Tue Feb 24 09:47:06 2009
@@ -1,0 +1,8 @@
+Changes
+Makefile.PL
+MANIFEST
+MANIFEST.SKIP
+lib/Data/Pageset.pm
+README
+t/main.t
+META.yml

Added: branches/upstream/libdata-pageset-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/MANIFEST.SKIP?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libdata-pageset-perl/current/MANIFEST.SKIP Tue Feb 24 09:47:06 2009
@@ -1,0 +1,24 @@
+_build
+Build$
+blib
+~$
+\.bak$
+^MANIFEST\.SKIP$
+CVS
+^Makefile$
+^MakeMaker-\d
+\.old$
+^#.*#$
+^\.#
+\.#
+#$
+\B\.svn\b
+
+\.bs$
+\.c$
+\.o$
+pm_to_blib
+unpacked
+
+# autogenerated
+SIGNATURE

Added: branches/upstream/libdata-pageset-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/META.yml?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/META.yml (added)
+++ branches/upstream/libdata-pageset-perl/current/META.yml Tue Feb 24 09:47:06 2009
@@ -1,0 +1,12 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Data-Pageset
+version:      1.05
+version_from: lib/Data/Pageset.pm
+installdirs:  site
+requires:
+    Data::Page:                    2
+    Test::More:                    0.1
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: branches/upstream/libdata-pageset-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/Makefile.PL?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/Makefile.PL (added)
+++ branches/upstream/libdata-pageset-perl/current/Makefile.PL Tue Feb 24 09:47:06 2009
@@ -1,0 +1,9 @@
+use ExtUtils::MakeMaker;
+WriteMakefile(
+    'NAME'		=> 'Data::Pageset',
+    'VERSION_FROM'	=> 'lib/Data/Pageset.pm',
+    'PREREQ_PM'		=> {
+		'Data::Page'	=> 2.00,
+		'Test::More' 	=> 0.1,
+    }, 
+);

Added: branches/upstream/libdata-pageset-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/README?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/README (added)
+++ branches/upstream/libdata-pageset-perl/current/README Tue Feb 24 09:47:06 2009
@@ -1,0 +1,171 @@
+Data::Pageset(3)      User Contributed Perl Documentation     Data::Pageset(3)
+
+
+
+NNAAMMEE
+       Data::Pageset - Page numbering and page sets
+
+SSYYNNOOPPSSIISS
+         use Data::Pageset;
+         my $page_info = Data::Pageset->new({
+           'total_entries'       => $total_entries,
+           'entries_per_page'    => $entries_per_page,
+           # Optional, will use defaults otherwise.
+           'current_page'        => $current_page,
+           'pages_per_set'       => $pages_per_set,
+           'mode'                => 'fixed', # default, or 'slide'
+         });
+
+         # General page information
+         print "         First page: ", $page_info->first_page, "\n";
+         print "          Last page: ", $page_info->last_page, "\n";
+         print "          Next page: ", $page_info->next_page, "\n";
+         print "      Previous page: ", $page_info->previous_page, "\n";
+
+         # Results on current page
+         print "First entry on page: ", $page_info->first, "\n";
+         print " Last entry on page: ", $page_info->last, "\n";
+
+         # Can add in the pages per set after the object is created
+         $page_info->pages_per_set($pages_per_set);
+
+         # Page set information
+         print "First page of previous page set: ",  $page_info->previous_set, "\n";
+         print "    First page of next page set: ",  $page_info->next_set, "\n";
+
+         # Print the page numbers of the current set
+         foreach my $page (@{$page_info->pages_in_set()}) {
+           if($page == $page_info->current_page()) {
+             print "<b>$page</b> ";
+           } else {
+             print "$page ";
+           }
+         }
+
+DDEESSCCRRIIPPTTIIOONN
+       The object produced by Data::Pageset can be used to create page naviga-
+       tion, it inherits from Data::Page and has access to all methods from
+       this object.
+
+       In addition it also provides methods for dealing with set of pages, so
+       that if there are too many pages you can easily break them into chunks
+       for the user to browse through.
+
+       You can even choose to view page numbers in your set in a 'sliding'
+       fassion.
+
+       The object can easily be passed to a templating system such as Template
+       Toolkit or be used within a script.
+
+MMEETTHHOODDSS
+       _n_e_w_(_)
+
+         use Data::Pageset;
+         my $page_info = Data::Pageset->new({
+           'total_entries'       => $total_entries,
+           'entries_per_page'    => $entries_per_page,
+           # Optional, will use defaults otherwise.
+           'current_page'        => $current_page,
+           'pages_per_set'       => $pages_per_set,
+           'mode'                => 'slide', # default fixed
+         });
+
+       This is the constructor of the object, it requires an anonymous hash
+       containing the 'total_entries', how many data units you have, and the
+       number of 'entries_per_page' to display. Optionally the 'current_page'
+       (defaults to page 1) and pages_per_set (how many pages to display,
+       defaults to 10) can be added.
+
+       The mode (which defaults to 'fixed') determins how the paging will
+       work, for example with 10 pages_per_set and the current_page set to 18
+       you will get the following results:
+
+       _F_i_x_e_d_:
+
+       Pages in set:
+           11,12,13,14,15,16,17,18,19,20
+
+       Previous page set:
+           1
+
+       Next page set:
+           21
+
+       _S_l_i_d_e_:
+
+       Pages in set:
+           14,15,16,17,18,19,20,21,22,23
+
+       Previous page set:
+           9
+
+       Next page set:
+           24
+
+       You can not change modes once the object is created.
+
+       _c_u_r_r_e_n_t___p_a_g_e_(_)
+
+         $page_info->current_page($page_num);
+
+       This method sets the current_page to the argument supplied, it can also
+       be set in the constructor, but you may want to reuse the object if
+       printing out multiple pages. It will then return the page number once
+       set.
+
+       If this method is called without any arguments it returns the current
+       page number.
+
+       _p_a_g_e_s___p_e_r___s_e_t_(_)
+
+         $page_info->pages_per_set($number_of_pages_per_set);
+
+       Calling this method initalises the calculations required to use the
+       paging methods below. The value can also be passed into the constructor
+       method _n_e_w_(_).
+
+       If called without any arguments it will return the current number of
+       pages per set.
+
+       _p_r_e_v_i_o_u_s___s_e_t_(_)
+
+         print "Back to previous set which starts at ", $page_info->previous_set(), "\n";
+
+       This method returns the page number at the start of the previous page
+       set.  undef is return if pages_per_set has not been set.
+
+       _n_e_x_t___s_e_t_(_)
+
+         print "Next set starts at ", $page_info->next_set(), "\n";
+
+       This method returns the page number at the start of the next page set.
+       undef is return if pages_per_set has not been set.
+
+       _p_a_g_e_s___i_n___s_e_t_(_)
+
+         foreach my $page_num (@{$page_info->pages_in_set()}) {
+           print "Page: $page_num \n";
+         }
+
+       This method returns an array ref of the the page numbers within the
+       current set. undef is return if pages_per_set has not been set.
+
+EEXXPPOORRTT
+       None by default.
+
+AAUUTTHHOORR
+       Leo Lapworth <lt>LLAP at cuckoo.org<gt> - let me know if you've used this
+       module - go on... you know you want to.
+
+SSEEEE AALLSSOO
+       Data::Page.
+
+CCOOPPYYRRIIGGHHTT
+       Copyright (C) 2003, Leo Lapworth
+
+       This module is free software; you can redistribute it or modify it
+       under the same terms as Perl itself.
+
+
+
+perl v5.8.6                       2006-01-21                  Data::Pageset(3)

Added: branches/upstream/libdata-pageset-perl/current/lib/Data/Pageset.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/lib/Data/Pageset.pm?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/lib/Data/Pageset.pm (added)
+++ branches/upstream/libdata-pageset-perl/current/lib/Data/Pageset.pm Tue Feb 24 09:47:06 2009
@@ -1,0 +1,411 @@
+package Data::Pageset;
+
+use strict;
+use Carp;
+
+use Data::Page;
+
+use vars qw(@ISA $VERSION);
+
+ at ISA = qw(Data::Page);
+
+$VERSION = '1.05';
+
+=head1 NAME
+
+Data::Pageset - Page numbering and page sets
+
+=head1 SYNOPSIS
+
+  use Data::Pageset;
+  my $page_info = Data::Pageset->new({
+    'total_entries'       => $total_entries, 
+    'entries_per_page'    => $entries_per_page, 
+    # Optional, will use defaults otherwise.
+    'current_page'        => $current_page,
+    'pages_per_set'       => $pages_per_set,
+    'mode'                => 'fixed', # default, or 'slide'
+  });
+
+  # General page information
+  print "         First page: ", $page_info->first_page, "\n";
+  print "          Last page: ", $page_info->last_page, "\n";
+  print "          Next page: ", $page_info->next_page, "\n";
+  print "      Previous page: ", $page_info->previous_page, "\n";
+
+  # Results on current page
+  print "First entry on page: ", $page_info->first, "\n";
+  print " Last entry on page: ", $page_info->last, "\n";
+
+  # Can add in the pages per set after the object is created
+  $page_info->pages_per_set($pages_per_set);
+  
+  # Page set information
+  print "First page of previous page set: ",  $page_info->previous_set, "\n";
+  print "    First page of next page set: ",  $page_info->next_set, "\n";
+  
+  # Print the page numbers of the current set
+  foreach my $page (@{$page_info->pages_in_set()}) {
+    if($page == $page_info->current_page()) {
+      print "<b>$page</b> ";
+    } else {
+      print "$page ";
+    }
+  }
+
+=head1 DESCRIPTION
+
+The object produced by Data::Pageset can be used to create page
+navigation, it inherits from Data::Page and has access to all 
+methods from this object.
+
+In addition it also provides methods for dealing with set of pages,
+so that if there are too many pages you can easily break them
+into chunks for the user to browse through.
+
+You can even choose to view page numbers in your set in a 'sliding'
+fassion.
+
+The object can easily be passed to a templating system
+such as Template Toolkit or be used within a script.
+
+=head1 METHODS
+
+=head2 new()
+
+  use Data::Pageset;
+  my $page_info = Data::Pageset->new({
+    'total_entries'       => $total_entries, 
+    'entries_per_page'    => $entries_per_page, 
+    # Optional, will use defaults otherwise.
+    'current_page'        => $current_page,
+    'pages_per_set'       => $pages_per_set,
+    'mode'                => 'slide', # default fixed
+  });
+
+This is the constructor of the object, it requires an anonymous
+hash containing the 'total_entries', how many data units you have,
+and the number of 'entries_per_page' to display. Optionally
+the 'current_page' (defaults to page 1) and pages_per_set (how
+many pages to display, defaults to 10) can be added. 
+
+The mode (which defaults to 'fixed') determins how the paging
+will work, for example with 10 pages_per_set and the current_page
+set to 18 you will get the following results:
+
+=head3 Fixed:
+
+=over 4
+
+=item Pages in set:
+
+11,12,13,14,15,16,17,18,19,20
+
+=item Previous page set:  
+
+1
+
+=item Next page set:
+
+21
+
+=back 4
+
+=head3 Slide:
+
+=over 4
+
+=item Pages in set:
+
+14,15,16,17,18,19,20,21,22,23
+
+=item Previous page set:  
+
+9
+
+=item Next page set:
+
+24
+
+=back 4
+
+You can not change modes once the object is created.
+
+=cut
+
+sub new {
+    my ( $class, $conf ) = @_;
+    my $self = {};
+
+    croak "total_entries and entries_per_page must be supplied"
+        unless defined $conf->{'total_entries'}
+            && defined $conf->{'entries_per_page'};
+
+    $conf->{'current_page'} = 1 unless defined $conf->{'current_page'};
+    $conf->{pages_per_set} = 10 unless defined $conf->{'pages_per_set'};
+    if ( defined $conf->{'mode'} && $conf->{'mode'} eq 'slide' ) {
+        $self->{mode} = 'slide';
+    } else {
+        $self->{mode} = 'fixed';
+    }
+    bless( $self, $class );
+
+    $self->total_entries( $conf->{'total_entries'} );
+    $self->entries_per_page( $conf->{'entries_per_page'} );
+    $self->current_page( $conf->{'current_page'} );
+
+    $self->pages_per_set( $conf->{'pages_per_set'} );
+
+    return $self;
+}
+
+=head2 current_page()
+
+  $page_info->current_page($page_num);
+
+This method sets the current_page to the argument supplied, it can also be 
+set in the constructor, but you may want to reuse the object if printing out
+multiple pages. It will then return the page number once set. 
+
+If this method is called without any arguments it returns the current page number.
+
+=cut
+
+sub current_page {
+    my $self = shift;
+
+    if (@_) {
+
+        # Set current page
+        $self->_current_page_accessor(@_);
+
+        # Redo calculations, using current pages_per_set value
+        $self->pages_per_set( $self->pages_per_set() );
+    }
+
+    # Not sure if there is some cleaver way of calling SUPER here,
+    # think it would have to be wrapped in an eval
+    return $self->first_page
+        if $self->_current_page_accessor < $self->first_page;
+    return $self->last_page
+        if $self->_current_page_accessor > $self->last_page;
+    return $self->_current_page_accessor();
+}
+
+=head2 pages_per_set()
+
+  $page_info->pages_per_set($number_of_pages_per_set);
+
+Calling this method initalises the calculations required to use
+the paging methods below. The value can also be passed into
+the constructor method new().
+
+If called without any arguments it will return the current
+number of pages per set.
+
+=cut
+
+sub pages_per_set {
+    my $self              = shift;
+    my $max_pages_per_set = shift;
+
+    # set as undef so it at least exists
+    $self->{PAGE_SET_PAGES_PER_SET} = undef
+        unless exists $self->{PAGE_SET_PAGES_PER_SET};
+
+    # Not trying to set, so return current number;
+    return $self->{PAGE_SET_PAGES_PER_SET} unless $max_pages_per_set;
+
+    $self->{PAGE_SET_PAGES_PER_SET} = $max_pages_per_set;
+
+    unless ( $max_pages_per_set > 1 ) {
+
+        # Only have one page in the set, must be page 1
+        $self->{PAGE_SET_PREVIOUS} = $self->current_page() - 1
+            if $self->current_page != 1;
+        $self->{PAGE_SET_PAGES} = [1];
+        $self->{PAGE_SET_NEXT}  = $self->current_page() + 1
+            if $self->current_page() < $self->last_page();
+    } else {
+        if ( $self->{mode} eq 'fixed' ) {
+            my $starting_page = $self->_calc_start_page($max_pages_per_set);
+            my $end_page      = $starting_page + $max_pages_per_set - 1;
+
+            if ( $end_page < $self->last_page() ) {
+                $self->{PAGE_SET_NEXT} = $end_page + 1;
+            }
+
+            if ( $starting_page > 1 ) {
+                $self->{PAGE_SET_PREVIOUS}
+                    = $starting_page - $max_pages_per_set;
+
+           # I can't see a reason for this to be here!
+           #$self->{PAGE_SET_PREVIOUS} =  1 if $self->{PAGE_SET_PREVIOUS} < 1;
+            }
+
+            $end_page = $self->last_page() if $self->last_page() < $end_page;
+            $self->{PAGE_SET_PAGES} = [ $starting_page .. $end_page ];
+        } else {
+
+            # We're in slide mode
+
+            # See if we have enough pages to slide
+            if ( $max_pages_per_set >= $self->last_page() ) {
+
+                # No sliding, no next/prev pageset
+                $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 );
+
+                # offset for extra value right of center on even numbered sets
+                my $offset = 1;
+                if ( $max_pages_per_set % 2 != 0 ) {
+
+                    # must have been an odd number, add one
+                    $middle++;
+                    $offset = 0;
+                }
+
+                my $starting_page = $self->current_page() - $middle + 1;
+                $starting_page = 1 if $starting_page < 1;
+                my $end_page = $starting_page + $max_pages_per_set - 1;
+                $end_page = $self->last_page()
+                    if $self->last_page() < $end_page;
+
+                if ( $self->current_page() <= $middle ) {
+
+                    # near the start of the page numbers
+                    $self->{PAGE_SET_NEXT}
+                        = $max_pages_per_set + $middle - $offset;
+                    $self->{PAGE_SET_PAGES} = [ '1' .. $max_pages_per_set ];
+                } elsif ( $self->current_page()
+                    > ( $self->last_page() - $middle - $offset ) )
+                {
+
+                    # near the end of the page numbers
+                    $self->{PAGE_SET_PREVIOUS}
+                        = $self->last_page() 
+                        - $max_pages_per_set 
+                        - $middle + 1;
+                    $self->{PAGE_SET_PAGES}
+                        = [ ( $self->last_page() - $max_pages_per_set + 1 )
+                        .. $self->last_page() ];
+                } else {
+
+                    # Start scrolling baby!
+                    $self->{PAGE_SET_PAGES} = [ $starting_page .. $end_page ];
+                    $self->{PAGE_SET_PREVIOUS}
+                        = $starting_page - $middle - $offset;
+                    $self->{PAGE_SET_PREVIOUS} = 1
+                        if $self->{PAGE_SET_PREVIOUS} < 1;
+                    $self->{PAGE_SET_NEXT} = $end_page + $middle;
+                }
+            }
+        }
+    }
+
+}
+
+=head2 previous_set()
+
+  print "Back to previous set which starts at ", $page_info->previous_set(), "\n";
+
+This method returns the page number at the start of the previous page set.
+undef is return if pages_per_set has not been set.
+
+=cut  
+
+sub previous_set {
+    my $self = shift;
+    return $self->{PAGE_SET_PREVIOUS} if defined $self->{PAGE_SET_PREVIOUS};
+    return undef;
+}
+
+=head2 next_set()
+
+  print "Next set starts at ", $page_info->next_set(), "\n";
+
+This method returns the page number at the start of the next page set.
+undef is return if pages_per_set has not been set.
+
+=cut  
+
+sub next_set {
+    my $self = shift;
+    return $self->{PAGE_SET_NEXT} if defined $self->{PAGE_SET_NEXT};
+    return undef;
+}
+
+=head2 pages_in_set()
+
+  foreach my $page_num (@{$page_info->pages_in_set()}) {
+    print "Page: $page_num \n";
+  }
+
+This method returns an array ref of the the page numbers within
+the current set. undef is return if pages_per_set has not been set.
+
+=cut  
+
+sub pages_in_set {
+    my $self = shift;
+    return $self->{PAGE_SET_PAGES};
+}
+
+# Calc the first page in the current set
+sub _calc_start_page {
+    my ( $self, $max_page_links_per_page ) = @_;
+    my $start_page;
+
+    my $current_page = $self->current_page();
+    my $max_pages_per_set;
+
+    my $current_page_set = 0;
+
+    if ( $max_page_links_per_page > 0 ) {
+        $current_page_set = int( $current_page / $max_page_links_per_page );
+
+        if ( $current_page % $max_page_links_per_page == 0 ) {
+            $current_page_set = $current_page_set - 1;
+        }
+    }
+
+    $start_page = ( $current_page_set * $max_page_links_per_page ) + 1;
+
+    return $start_page;
+}
+
+=head1 EXPORT
+
+None by default.
+
+=head1 AUTHOR
+
+Leo Lapworth C<< <LLAP at cuckoo.org> >>
+
+=head1 SVN
+
+http://code.google.com/p/llap/
+
+=head1 CONTRIBUTORS
+
+Ryan D Johnson C<< <ryan at innerfence.com> >>
+PLOBBES
+
+=head1 SEE ALSO
+
+L<Data::Page>.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2007, Leo Lapworth
+
+This module is free software; you can redistribute it or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
+

Added: branches/upstream/libdata-pageset-perl/current/t/main.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-pageset-perl/current/t/main.t?rev=31081&op=file
==============================================================================
--- branches/upstream/libdata-pageset-perl/current/t/main.t (added)
+++ branches/upstream/libdata-pageset-perl/current/t/main.t Tue Feb 24 09:47:06 2009
@@ -1,0 +1,273 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use lib qw( ./blib/lib ../blib/lib );
+
+use Test::More tests => 554;
+
+# Check we can load module
+BEGIN { use_ok( 'Data::Pageset' ); }
+
+#######
+# new()
+#######
+eval {
+	Data::Pageset->new();
+};
+like($@,qr/total_entries and entries_per_page must be supplied/,'new - Croak when no params');
+
+eval {
+	Data::Pageset->new({
+		'total_entries' => 12,
+	});
+};
+like($@,qr/total_entries and entries_per_page must be supplied/,'new - Croak when no entries_per_page');
+
+eval {
+	Data::Pageset->new({
+		'entries_per_page' => 3,
+	});
+};
+like($@,qr/total_entries and entries_per_page must be supplied/,'new - Croak when no entries_per_page');
+
+eval {
+	Data::Pageset->new({
+		'total_entries' => 12,
+		'entries_per_page' => -2,
+	});
+};
+like($@,qr/Fewer than one entry per page/,'new - Croak when num entries_per_page is negative');
+
+
+my $dp = Data::Pageset->new({
+	'total_entries' => '23',
+	'entries_per_page' => '2',
+});
+is($dp->current_page(),'1','new - Default current page of 1 set');
+
+$dp = Data::Pageset->new({
+	'total_entries' => '23',
+	'entries_per_page' => '2',
+	'current_page' => -90,
+});
+is($dp->current_page(),'1','new - Default current page of 1 set when current_page less than first_page');
+
+$dp = Data::Pageset->new({
+	'total_entries' => '20',
+	'entries_per_page' => '10',
+	'current_page' => 9,
+});
+is($dp->current_page(),'2','new - Default current page set to last page when current_page greater than last_page');
+
+######
+# pages_per_set
+######
+
+is($dp->pages_per_set(),10,'pages_per_set - get undef when not defined');
+
+$dp = Data::Pageset->new({
+	'total_entries' => '20',
+	'entries_per_page' => '10',
+	'current_page' => 4,
+	'pages_per_set' => 2,
+});
+
+$dp = Data::Pageset->new({
+	'total_entries' => '20',
+	'entries_per_page' => '10',
+	'current_page' => 4,
+	'pages_per_set' => -2,
+});
+
+#####
+# Current_page()
+######
+
+$dp = Data::Pageset->new({
+	'total_entries' => '20',
+	'entries_per_page' => '10',
+});
+
+#is($dp->current_page(),1,'Got default current page as 1, when none set');
+
+############
+# General tests
+############
+
+# Some configs for testing
+my %config = (
+	'total_entries'		=> 300,
+	'entries_per_page'	=> 10,
+	'current_page'		=> 17
+);
+
+my $page_info = Data::Pageset->new({
+	'total_entries'       => $config{'total_entries'}, 
+	'entries_per_page'    => $config{'entries_per_page'}, 
+	'current_page'		  => $config{'current_page'},
+});
+
+isa_ok($page_info,'Data::Pageset');
+
+$page_info->pages_per_set(2);
+
+is($page_info->pages_per_set(),2,'pages_per_set - got 2 as exected');
+
+is('19',$page_info->next_set(),'Know that the next set is 2');
+
+is('15',$page_info->previous_set(),'Know that the next set is 11');
+
+is('17 18',join(' ',@{$page_info->pages_in_set()}),'Pages returned correctly');
+
+is($config{'current_page'},$page_info->current_page(),'Current page matches');
+
+my $name;
+
+my $t = 0;
+
+foreach my $line (<DATA>) {
+  chomp $line;
+  next unless $line;
+
+  if ($line =~ /^# ?(.+)/) {
+    $name = $1;
+    next;
+  }
+  my @vals = map { $_ = undef if $_ eq 'undef'; $_ } split /\s+/, $line;
+
+  my $page = Data::Pageset->new({
+  	'total_entries'		=> $vals[0],
+	'entries_per_page'	=> $vals[1],
+	'current_page'		=> $vals[2],
+	'pages_per_set'		=> $vals[3],
+	'mode'			=> $vals[15],
+  });
+
+  my @integers = (0..$vals[0]);
+  @integers = $page->splice(\@integers);
+  my $integers = join ',', @integers;
+  my $page_nums = join ',', @{$page->pages_in_set()};
+  
+  is($page->first_page, $vals[4], "$name: first page");
+  is($page->last_page, $vals[5], "$name: last page");
+  is($page->first, $vals[6], "$name: first");
+  is($page->last, $vals[7], "$name: last");
+  is($page->previous_page, $vals[8], "$name: previous_page");
+  is($page->current_page, $vals[9], "$name: current_page");
+  is($page->next_page, $vals[10], "$name: next_page");
+  is($integers, $vals[11], "$name: splice");
+  is($page->next_set(), $vals[12], "$name: next_set");
+  is($page->previous_set(), $vals[13], "$name: previous_set");
+  is($page_nums, $vals[14], "$name: pages_in_set");
+
+#  my $ps = Data::Pageset->new({
+#  	'total_entries'		=> $vals[0],
+#	'entries_per_page'	=> $vals[1],
+#	'current_page'		=> $page->previous_set,
+#	'pages_per_set'		=> $vals[3],
+#	'mode'			=> $vals[15],
+#  });
+#  my $ns = Data::Pageset->new({
+#  	'total_entries'		=> $vals[0],
+#	'entries_per_page'	=> $vals[1],
+#	'current_page'		=> $page->next_set,
+#	'pages_per_set'		=> $vals[3],
+#	'mode'			=> $vals[15],
+#  });
+#
+#  diag("totent($vals[0]) epp($vals[1]) cp($vals[9]) pps($vals[3])\n");
+#  diag("previous set pis: ", join(",",@{$ps->pages_in_set()}), "\n") if($page->previous_set);
+#  diag("    this set pis: ", join(",",@{$page->pages_in_set()}), "\n");
+#  diag("    next set pis: ", join(",",@{$ns->pages_in_set()}), "\n") if($page->next_set);
+
+}
+
+# 0: total_entries
+# 1: entries_per_page
+# 2: current_page
+# 3: pages_per_set
+# 4: first_page number
+# 5: last_page number
+# 6: first entry on page
+# 7: last last entry on page
+# 8: previous_page
+# 9: current_page
+# 10: next_page
+# 11: results on current page
+# 12: next_set
+# 13: previous_set
+# 14: page numbers for set
+# 15: mode
+ 
+__DATA__
+# Initial test
+50 10 1 1   1 5 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 2 undef 1
+50 10 2 4   1 5 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 5 undef 1,2,3,4
+50 10 3 undef   1 5 21 30 2 3 4 20,21,22,23,24,25,26,27,28,29 undef undef 1,2,3,4,5
+50 10 4 2   1 5 31 40 3 4 5 30,31,32,33,34,35,36,37,38,39 5 1 3,4
+50 10 5 1   1 5 41 50 4 5 undef 40,41,42,43,44,45,46,47,48,49 undef 4 1
+
+# Under 10
+1 10 1 4   1 1 1 1 undef 1 undef 0 undef undef 1
+2 10 1 5   1 1 1 2 undef 1 undef 0,1  undef undef 1
+3 10 1 6   1 1 1 3 undef 1 undef 0,1,2 undef undef 1
+4 10 1 7   1 1 1 4 undef 1 undef 0,1,2,3 undef undef 1
+5 10 1 undef   1 1 1 5 undef 1 undef 0,1,2,3,4 undef undef 1
+6 10 1 9   1 1 1 6 undef 1 undef 0,1,2,3,4,5 undef undef 1
+7 10 1 10   1 1 1 7 undef 1 undef 0,1,2,3,4,5,6 undef undef 1
+8 10 1 undef   1 1 1 8 undef 1 undef 0,1,2,3,4,5,6,7 undef undef 1
+9 10 1 12   1 1 1 9 undef 1 undef 0,1,2,3,4,5,6,7,8 undef undef 1
+10 10 1 13   1 1 1 10 undef 1 undef 0,1,2,3,4,5,6,7,8,9 undef undef 1
+
+# Over 10
+11 10 1 2   1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2
+11 10 2 3   1 2 11 11 1 2 undef 10 undef undef 1,2
+12 10 1 undef   1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2
+12 10 2 5   1 2 11 12 1 2 undef 10,11  undef undef 1,2
+13 10 1 6   1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9  undef undef 1,2
+13 10 2 7   1 2 11 13 1 2 undef 10,11,12 undef undef 1,2
+
+# Under 20
+19 10 1 2   1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2
+19 10 2 3   1 2 11 19 1 2 undef 10,11,12,13,14,15,16,17,18 undef undef 1,2
+20 10 1 undef   1 2 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2
+20 10 2 5   1 2 11 20 1 2 undef 10,11,12,13,14,15,16,17,18,19 undef undef 1,2
+
+# Over 20
+21 10 1 5   1 3 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2,3
+21 10 2 5   1 3 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 undef undef 1,2,3
+21 10 3 5   1 3 21 21 2 3 undef 20 undef undef 1,2,3
+22 10 1 5   1 3 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2,3
+22 10 2 10   1 3 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 undef undef 1,2,3
+22 10 3 10   1 3 21 22 2 3 undef 20,21 undef undef 1,2,3
+23 10 1 10   1 3 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2,3
+23 10 2 undef   1 3 11 20 1 2 3 10,11,12,13,14,15,16,17,18,19 undef undef 1,2,3
+23 10 3 10   1 3 21 23 2 3 undef 20,21,22 undef undef 1,2,3
+
+# Slide - no sliding (to low pages)
+1 10 1 4   1 1 1 1 undef 1 undef 0 undef undef 1 slide
+89 10 1 10 1 9 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2,3,4,5,6,7,8,9 slide
+
+# Slide - no sliding (current page to low)
+89 10 1 10 1 9 1 10 undef 1 2 0,1,2,3,4,5,6,7,8,9 undef undef 1,2,3,4,5,6,7,8,9 slide
+89 10 4 10 1 9 31 40 3 4 5 30,31,32,33,34,35,36,37,38,39 undef undef 1,2,3,4,5,6,7,8,9 slide
+
+# Slide - sliding
+89 10 4 10 1 9 31 40 3 4 5 30,31,32,33,34,35,36,37,38,39 undef undef 1,2,3,4,5,6,7,8,9 slide
+999 10 20 9 1 100 191 200 19 20 21 190,191,192,193,194,195,196,197,198,199 29 11 16,17,18,19,20,21,22,23,24 slide
+999 10 11 9 1 100 101 110 10 11 12 100,101,102,103,104,105,106,107,108,109 20 2 7,8,9,10,11,12,13,14,15 slide
+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        




More information about the Pkg-perl-cvs-commits mailing list