Template::Plugin::Page 0.10 review

Download
by rbytes.net on

Template::Plugin::Page is a plugin to help when paging through sets of results. SYNOPSIS [% USE page = Page($total_entries, $

License: Perl Artistic License
File size: 3K
Developer: Leon Brocard
0 stars award from rbytes.net

Template::Plugin::Page is a plugin to help when paging through sets of results.

SYNOPSIS

[% USE page = Page($total_entries, $entries_per_page, $current_page) %]

First page: [% page.first_page %]
Last page: [% page.last_page %]
First entry on page: [% page.first %]
Last entry on page: [% page.last %]

When searching through large amounts of data, it is often the case that a result set is returned that is larger than we want to display on one page. This results in wanting to page through various pages of data. The maths behind this is unfortunately fiddly, hence this module.

The main concept is that you pass in the number of total entries, the number of entries per page, and the current page number. You can then call methods to find out how many pages of information there are, and what number the first and last entries on the current page really are.

It would be typically used in the following way for an HTML template:

[% USE page = Page(134, 10, 13) %]
Matches < b >[% page.first %] - [% page.last %]< /b > of
< b >[% page.total_entries %]< /b > records.< BR >

Page < b >[% page.current_page %]< /b > of
< b >[% page.last_page %]< /b >< BR >

[% IF page.previous_page %]
< a href="index.cgi?page=[% page.previous_page %]" >Previous< /a >
[% END %]   

[% IF page.next_page %]
< a href="index.cgi?page=[% page.next_page %]" > Next< /a >
[% END %]

... which would output something like:

Matches < b >121 - 130< /b > of
< b >134< /b > records.< BR >

Page < b >13< /b > of
< b >14< /b> < BR >

< a href="index.cgi?page=12" >Previous< /a >
   

< a href="index.cgi?page=14" >Next< /a >

Note that this module is simply a plugin to the Data::Page module.

Requirements:
Perl

Template::Plugin::Page 0.10 search tags