1. Perl
  2. Module
  3. here

Data::Page - Easy paging process

The Data::Page module is a module that makes paging processing convenient. You can get a lot of information by giving the constructor the information you need.

use Data::Page;

my $page = Data::Page->new($total_entries, $entries_per_page, $current_page);

print "First page:", $page->first_page, "\n";
print "Last page:", $page->last_page, "\n";
print "First entry on page:", $page->first, "\n";
print "Last entry on page:", $page->last, "\n";

In the first argument of the constructor (new), specify the total number of results. In the second argument, specify the number of entries per page. In the third argument, specify the current page. The third argument can be omitted and the default is 1.

Information that can be obtained

You can use various methods to get the following information:

Total number

my $total_entories = $page->total_entries;

Use the total_entries method to get the total number. This will be the value given in the first argument of the constructor.

Number of cases per page

my $entries_per_page = $page->entries_per_page

Use the entries_per_page method to get the number per page. This is the same as specified in the second argument of the constructor.

Number of current pages

my $entries_on_this_page = $page->entries_on_this_page

Use the entries_on_this_page method to get the number of items currently contained in the page. "Number of items per page" always returns a constant value, while "Number of items on the current page" actually returns the number of items contained in the page.

Current page number

my $current_page = $page->current_page;

Use the current_page method to get the current page number. This is the same as the one specified in the third argument of the constructor.

First page number

my $first_page = $page->first_page;

Use the first_page method to get the first page number. Always returns 1.

Last page number

my $last_page = $page->last_page;

Use the last_page method to get the last page number. This is the same value as the total number of pages.

First index on the current page

my $first = $page->first;

Use the first method to get the first index of the current page. For example, if the total number is 20, the number per page is 10, and the current page is 2, the number 11 will be returned.

Last index on the current page

my $last = $page->last;

Use the last method to get the last index of the current page. For example, if the total number is 20, the number per page is 10, and the current page is 1, the number 10 will be returned.

Previous page number

my $previous_page = $page->previous_page;

Use the previous_page method to get the previous page number. Returns undef if there is no previous page number.

Next page number

my $next_page = $page->next_page;

Use the next_page method to get the next page number. Returns undef if the next page number does not exist.

Related Informatrion