The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Nile::Paginate - Standalone Object-Oriented Efficient Data Pagination

SYNOPSIS

        use Nile::Paginate;
        
        #Example data
        my $total_entries = 100;
        my $entries_per_page = 10;
        my $pages_per_set = 7;
        my $current_page = 4;

        my $paginate = Nile::Paginate->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 "<b>$page</b> ";
                } 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 <b>4</b> 5 6 7 

DESCRIPTION

The standalone object-orinated module produced by Nile::Paginate 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 Data::Pageset. Basically this module is a duplicate of the module Data::Pageset. 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:

use Nile::Paginate;

by this line:

use Pagination;

You can even choose to view page numbers in your set in a 'sliding' fassion.

METHODS

new()

        use Nile::Paginate;
        my $paginate = Nile::Paginate->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'
        );

This is the constructor of the object.

SETTINGS are passed in a hash like fashion, using key and value pairs. Possible settings are:

total_entries - how many data units you have,

entries_per_page - the number of entries per page to display,

current_page - the current page number (defaults to page 1) and,

pages_per_set - how many pages to display, defaults to 10,

mode - the mode (which defaults to 'slide') determins how the paging will work.

total_entries()

  $paginate->total_entries($total_entries);

This method sets or returns the total_entries. If called without any arguments it returns the current total entries.

entries_per_page()

  $paginate->entries_per_page($entries_per_page);

This method sets or returns the entries per page (page size). If called without any arguments it returns the current data entries per page.

current_page()

  $paginate->current_page($page_num);

This method sets or returns the current page. If called without any arguments it returns the current page number.

mode()

        $paginate->mode('slide');

This method sets or returns the pages set mode which takes only two values 'fixed' or 'slide'. The default is 'slide'. The fixed mode will be good if you want to display all the navigation pages.

pages_per_set()

  $paginate->pages_per_set($number_of_pages_per_set);

Sets or returns the number of pages per set (visible pages). If called without any arguments it will return the current number of pages per set.

entries_on_current_page()

  $paginate->entries_on_current_page();

This method returns the number of entries on the current page.

first_page()

  $paginate->first_page();

Returns first page. Always returns 1.

last_page()

  $paginate->last_page();

Returns the last page number, the total number of pages.

total_pages()

  $paginate->total_pages();

Returns the last page number, the total number of pages.

first()

  $paginate->first();

Returns the number of the first entry on the current page.

last()

  $paginate->last();

Returns the number of the last entry on the current page.

previous_page()

  $paginate->previous_page();

Returns the previous page number, if one exists. Otherwise it returns undefined.

next_page()

  $paginate->next_page();

Returns the next page number, if one exists. Otherwise it returns undefined.

first_page_in_set()

  $paginate->first_page_in_set();

Returns 1 if the first page is in the current pages set. Otherwise it returns 0.

last_page_in_set()

  $paginate->last_page_in_set();

Returns 1 if the last page is in the current pages set. Otherwise it returns 0.

previous_set()

  print "Previous set starts at ", $paginate->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.

next_set()

  print "Next set starts at ", $paginate->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.

pages_in_set()

  foreach my $page_num (@{$paginate->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.

EXPORT

None by default.

AUTHOR

Ahmed Amin Elsheshtawy, <support@mewsoft.com> Website: http://www.mewsoft.com

SEE ALSO

Data::Page. Data::Pageset.

COPYRIGHT AND LICENSE

Copyright (C) 2010-2015 by Ahmed Amin Elsheshtawy <support@mewsoft.com>, http://www.mewsoft.com

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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 146:

=back doesn't take any parameters, but you said =back 4

=back without =over