#=Copyright Infomation
#==========================================================
#Module Name : Mewsoft::Pagination
#Program Author : Ahmed Amin Elsheshtawy
#Home Page : http://www.mewsoft.com
#Contact Email : support@mewsoft.com
#Copyrights © 2008 Mewsoft Corp. All rights reserved.
#==========================================================
#==========================================================
package Mewsoft::Pagination;
# pagination - pag·i·na·tion
#1. the process of numbering the pages of a book.
#2. the number and arrangement of pages, as might be noted in a bookseller’s catalogue.
$VERSION = '0.20';
use strict;
=head1 NAME
Mewsoft::Pagination - Standalone Object-Oriented Efficient Data Pagination
=head1 SYNOPSIS
use Mewsoft::Pagination;
#Example data
my $total_entries = 100;
my $entries_per_page = 10;
my $pages_per_set = 7;
my $current_page = 4;
my $paginate = Mewsoft::Pagination->new(
total_entries => $total_entries,
entries_per_page => $entries_per_page,
current_page => $current_page,
pages_per_set => $pages_per_set,
mode => "slide", #modes are 'slide', 'fixed', default is 'slide'
);
# General page information
print " First page: ", $paginate->first_page, "\n";
print " Last page: ", $paginate->last_page, "\n";
print " Next page: ", $paginate->next_page, "\n";
print " Previous page: ", $paginate->previous_page, "\n";
print " Current page: ", $paginate->current_page, "\n";
# Entries on current page
print "First entry on current page: ", $paginate->first, "\n";
print " Last entry on current page: ", $paginate->last, "\n";
#Returns the number of entries on the current page
print "Entries on the current page: ", $paginate->entries_on_current_page, " \n";
# Page set information
print "First page of previous page set: ", $paginate->previous_set, "\n";
print " First page of next page set: ", $paginate->next_set, "\n";
# Print the page numbers of the current set (visible pages)
foreach my $page (@{$paginate->pages_in_set()}) {
if($page == $paginate->current_page()) {
print "$page ";
} else {
print "$page ";
}
}
#This will print out these results:
#First page: 1
#Last page: 10
#Next page: 5
#Previous page: 3
#Current page: 4
#First entry on current page: 31
#Last entry on current page: 40
#Entries on the current page: 10
#First page of previous page set:
#First page of next page set: 11
# 1 2 3 4 5 6 7
=head1 DESCRIPTION
The standalone object-orinated module produced by Mewsoft::Pagination which
does not depend on any other modules can be used to create page
navigation for any type of applications specially good for web applications. For example
I use it in our Forums software, Auctions, Classifieds, and also our Directory
Software andmany others. It makes live easier better than repeating the same code in your applications.
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. This part taken direct
from the similar module B. Basically this module
is a duplicate of the module B. The reason I created
this module is that all other pagination modules depends on other
modules which is also dependes on others modules. So it is not good
if you are building a large web application to ask your customers to
install such a small module to support your product.
This module is very friendly where you can change any single
input parameter at anytime and it will automatically recalculate
all internal methods data without the need to recreate the object again.
All the main object input options can be set direct and the module
will redo the calculations including the mode method.
You can include this module with your applications by extracting the
module package and copying the module file Pagination.pm to your
application folder and just replace this line in the above code:
B