Paginator::Lite
version 2.001003
A simple tool to automate the creation of paging links
use Paginator::Lite; my $paginator = Paginator::Lite->new({ curr => 3, items => 65, frame_size => 5, page_size => 10, base_url => '/foo/items', mode => 'query', params => { bar => 123 }, }); ... $paginator->first # 1 $paginator->last # 7 $paginator->begin # 1 $paginator->end # 5 $paginator->next # 4 $paginator->prev # 2 $paginator->base_url # '/foo/items' $paginator->first_url # '/foo/items?bar=123&page=1' $paginator->prev_url # '/foo/items?bar=123&page=2' $paginator->curr_url # '/foo/items?bar=123&page=3' $paginator->next_url # '/foo/items?bar=123&page=4' $paginator->last_url # '/foo/items?bar=123&page=7'
When handle with huge amounts of data sometimes you want to display only a portion of it and provide controls to naviagte through it.
The classic way is to provide links or buttons to next, previous and some pages around the current page, like this:
(prev) 1 2 [3] 4 5 (next)
But when the number of pages grow up too much this approach may be annoying:
(prev) 1 2 3 4 5 6 7 8 9 10 [11] 12 13 14 15 16 16 18 19 20 21 (next)
So Paginator::Lite helps you calculating the numbers to feed your view loops and implements the concept of frame. A frame is a small portion of pages around the current page that will be displayed in addition to (prev), (next) and other permanent buttons:
(prev) 10 11 12 [13] 14 15 16 (next) \ / ----- frame ---- 7 of 21 pages
Paginator::Lite - A simple paginator
2.1.0
Creates a Paginator::Lite object.
You must provide all required arguments: base_url, curr, frame_size, items and page_size.
base_url
curr
frame_size
items
page_size
params is a optional argument that may be used to pass arbitrary data.
params
See more details about them in documentation of their respective accessors.
Returns the value of base_url. It is the same value that you must supply to constructor. This value will be used by the template to build the links to direct pages.
Returns the value of current page. It is the same value that you must supply to constructor.
Returns the value of frame_size. It is the same value that you must supply to constructor. It is also the number of pages visible around current page.
Usually frame_size may be calculated by:
my $frame_size = $pag->end - $pag->begin + 1
However when current page is too close to first or last, the frame may be deformed but still trying to center in the current page.
first
last
Returns the value of page_size. It is the same value that you must supply to constructor and means the number of items that you want display in a single page.
Returns the value of items. It is the same value the you must provide to constructor and means the total number of items that you are paginating.
Returns the value of the first page, usually 1.
Returns the value of the last page. This value is calculated by dividing the total amount of items by the number of items per page and then rounding up the result.
$self->{last} = ceil( $self->items / $self->page_size );
Returns the value of the first page of current frame. Usually you will iterate between begin and end in your view to create direct links to those pages.
begin
end
Returns the value of the last page of current frame.
Returns the value of previous page. Usually this value is curr - 1, except when current page is 1.
curr - 1
Returns the value of next page. Usually this value is curr + 1, except when current page is last.
curr + 1
Returns arbitrary data passed to contructor by params argument.
Returns the chosen mode (path or query) of resulting URLs.
Returns the URL of the first page.
Returns the URL of the previous page.
Returns the URL of the current page.
Returns the URL of the next page.
Returns the URL of the last page.
Returns the URL of given page.
Private. It casts the magic when building the object.
Blabos de Blebe, <blabos at cpan.org>
<blabos at cpan.org>
Please report any bugs or feature requests to bug-paginator-lite at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Paginator-Lite. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-paginator-lite at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Paginator::Lite
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Paginator-Lite
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Paginator-Lite
CPAN Ratings
http://cpanratings.perl.org/d/Paginator-Lite
Search CPAN
http://search.cpan.org/dist/Paginator-Lite/
Copyright 2012 Blabos de Blebe.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
Blabos de Blebe <blabos@cpan.org>
This software is copyright (c) 2017 by Blabos de Blebe.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Paginator::Lite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Paginator::Lite
CPAN shell
perl -MCPAN -e shell install Paginator::Lite
For more information on module installation, please visit the detailed CPAN module installation guide.