NAME
Tags::HTML::Pager::Utils - Pager utilities.
SYNOPSIS
use Tags::HTML::Pager::Utils qw(adjust_actual_page compute_index_values pages_num);
my $actual_page = adjust_actual_page($input_actual_page, $pages);
my ($begin_index, $end_index) = compute_index_values($items, $actual_page, $items_on_page);
my $pages = pages_num($items, $items_on_page);
SUBROUTINES
adjust_actual_page
my $actual_page = adjust_actual_page($input_actual_page, $pages);
Adjust actual page.
Arguments:
- C<$input_actual_page> - Input value for actual page. This is value for adjust.
- C<$pages> - Number of pages.
Returns number.
compute_index_values
my ($begin_index, $end_index) = compute_index_values($items, $actual_page, $items_on_page);
Compute begin and end index in items list.
Arguments:
- C<$items> - Number of items.
- C<$actual_page> - Actual page of items.
- C<$items_on_page> - Items on page.
Returns array with begin and end index.
pages_num
my $pages = pages_num($items, $items_on_page);
Compute number of pages from $items
and $items_on_page
. If input arguments are undefined, returns 0.
Returns number.
ERRORS
adjust_actual_page():
Not defined number of pages.
Number of pages must be a positive number.
EXAMPLE1
use strict;
use warnings;
use Tags::HTML::Pager::Utils qw(adjust_actual_page);
# Input informations.
my $input_actual_page = 10;
my $pages = 5;
# Compute;
my $actual_page = adjust_actual_page($input_actual_page, $pages);
# Print out.
print "Input actual page: $input_actual_page\n";
print "Number of pages: $pages\n";
print "Adjusted actual page: $actual_page\n";
# Output:
# Input actual page: 10
# Number of pages: 5
# Adjusted actual page: 5
EXAMPLE2
use strict;
use warnings;
use Tags::HTML::Pager::Utils qw(compute_index_values);
# Input informations.
my $items = 55;
my $actual_page = 2;
my $items_on_page = 10;
# Compute.
my ($begin_index, $end_index) = compute_index_values($items, $actual_page, $items_on_page);
# Print out.
print "Items: $items\n";
print "Actual page: $actual_page\n";
print "Items on page: $items_on_page\n";
print "Begin index: $begin_index\n";
print "End index: $end_index\n";
# Output:
# Items: 55
# Actual page: 2
# Items on page: 10
# Computed begin index: 10
# Computed end index: 19
EXAMPLE3
use strict;
use warnings;
use Tags::HTML::Pager::Utils qw(pages_num);
# Input informations.
my $items = 123;
my $items_on_page = 20;
# Compute.
my $pages = pages_num($items, $items_on_page);
# Print out.
print "Items count: $items\n";
print "Items on page: $items_on_page\n";
print "Number of pages: $pages\n";
# Output:
# Items count: 123
# Items on page: 20
# Number of pages: 7
DEPENDENCIES
Error::Pure, Exporter, POSIX, Readonly.
REPOSITORY
https://github.com/michal-josef-spacek/Tags-HTML-Pager
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2022-2023 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.05