GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::SpreadPagination(3) User Contributed Perl Documentation Data::SpreadPagination(3)

Data::SpreadPagination - Page numbering and spread pagination

  use Data::SpreadPagination;
  my $pageInfo = Data::SpreadPagination->new({
    totalEntries      => $totalEntries, 
    entriesPerPage    => $entriesPerPage, 
    # Optional, will use defaults otherwise.
    # only 1 of currentPage / startEntry can be provided.
    currentPage       => $currentPage,
    startEntry        => $startEntry,
    maxPages          => $maxPages,
  });

  # General page information
  print "         First page: ", $pageInfo->first_page, "\n";
  print "          Last page: ", $pageInfo->last_page, "\n";
  print "          Next page: ", $pageInfo->next_page, "\n";
  print "      Previous page: ", $pageInfo->previous_page, "\n";

  # Results on current page
  print "First entry on page: ", $pageInfo->first, "\n";
  print " Last entry on page: ", $pageInfo->last, "\n";

  # Page range information
  my $pageRanges = $pageInfo->page_ranges;

  # Print out the page spread
  foreach my $page ($pageInfo->pages_in_spread()) {
    if (!defined $page) {
      print "... ";
    } elsif ($page == $pageInfo->current_page) {
      print "<b>$page</b> ";
    } else {
      print "$page ";
    }
  }

The object produced by Data::SpreadPagination can be used to create a spread pagination navigator. It inherits from Data::Page, and has access to all of the methods from this object.

In addition, it also provides methods for creating a pagination spread, to allow for keeping the number of pagenumbers displayed within a sensible limit, but at the same time allowing easy navigation.

The object can easily be passed to a templating system such as Template Toolkit or be used within a script.

  my $pageInfo = Data::SpreadPagination->new({
    totalEntries      => $totalEntries, 
    entriesPerPage    => $entriesPerPage, 
    # Optional, will use defaults otherwise.
    # only 1 of currentPage / startEntry can be provided.
    currentPage       => $currentPage,
    startEntry        => $startEntry,
    maxPages          => $maxPages,
  });

This is the constructor of the object. It requires an anonymous hash containing the 'totalEntries', how many data units you have, and the number of 'entriesPerPage' to display. Optionally the 'currentPage' / 'startEntry' (defaults to page/entry 1) and 'maxPages' (how many pages to display in addition to the current page) can be added.

  print "Maximum additional pages to display is ", $pageInfo->max_pages(), "\n";

This method returns the maximum number of pages that are included in the spread pagination in addition to the current page.

  $ranges = $pageInfo->page_ranges();
  for my $qtr (1..4) {
    my $range = $ranges->[$qtr-1];
    if (defined $range) {
      print "Qtr $qtr: no pages\n";
    } else {
      print "Qtr $qtr: pages " . $range->[0] . " to " . $range->[1] . "\n";
    }
  }

This method returns either an array or an arrayref (based upon context) of the page ranges for each of the four quarters in the spread. Each range is either undef for an empty quarter, or an array of the lower and upper pages in the range.

  # Print out the page spread
  foreach my $page ($pageInfo->pages_in_spread_raw()) {
    if ($page == $pageInfo->current_page) {
      print "<b>$page</b> ";
    } else {
      print "$page ";
    }
  }

This method returns either an array or an arrayref (based upon context) of purely the page numbers within the spread.

  # Print out the page spread
  foreach my $page ($pageInfo->pages_in_spread()) {
    if (!defined $page) {
      print "... ";
    } elsif ($page == $pageInfo->current_page) {
      print "<b>$page</b> ";
    } else {
      print "$page ";
    }
  }

This method returns either an array or an arrayref (based upon context) of the page numbers within the spread. Breaks in the sequence are indicated with undef's.

Hopefully there aren't any nasty bugs lurking in here anywhere. However, if you do find one, please report it via RT.

The algorithm used to create the pagination spread was reverse-engineered out of Squirrelmail by myself, and then reimplemented from description only by Alex Gough.

Alex Gough for implementing the central algorithm from my description.

Jody Belka "knew@cpan.org"

Data::Page.

Copyright 2004 by Jody Belka

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2004-07-19 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.