NAME

Paginator::Lite - A simple paginator

VERSION

Version 1.02

SYNOPSIS

This module provides a simple way to get some information about a collection of data (rows of the database, sometimes) that can be used to build pagination components.

use Paginator::Lite;

my $paginator = Paginator::Lite->new({
    current     => 3,
    items       => 30,
    frame_size  => 5,
});

...

$paginator->first       # 1
$paginator->last        # 6
$paginator->next        # 4

DESCRIPTION

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

METHODS

new

Constructor. Creates a Paginator::Lite object. May be aclled without args or with the same as repaginate()

my $paginator = Paginator::Lite->new;

repaginate

Takes the parameters and calculates the next, previous and which pages will be into the frame.

All parameters are optional. The module provides some default values.

If you try to pass negative values, the method will kick your ass, throwing an exception! Therefore, be nice!

If you pass the total number of pages, the method will ignore the number of items and the number of items per page (if one or both were provided). Otherwise, if you don't provide the number of pages, the method will try to calculate it using the number of items, the number of items per page or defaults values if you don't provide any.

Usually you will provide the args 'current', 'frame_size' and 'pages'. The last one may be exchanged by the pair 'items' and 'items_per_page'.

All parameter are named as follow:

pages: The total number of pages.
items: The total number of items.
items_per_page: The number of items for each page.
current: The number of the current page.
frame_size: The size of frame.

Example:

$paginator->repaginate({
    'pages'         => 20,
    'current'       => 13,
    'frame_size'    => 7,
});

my $first   = $paginator->first;    # $first    == 1
my $prev    = $paginator->prev;     # $prev     == 12
my $begin   = $paginator->begin;    # $begin    == 10
my $curr    = $paginator->curr;     # $curr     == 13
my $end     = $paginator->end;      # $end      == 16
my $last    = $paginator->last;     # $last     == 20

first

Accessor method to retrieve the number of the first one page.

prev

Accessor method to retrieve the number of previous page.

begin

Accessor method to retrieve the beginning of the frame.

curr

Accessor method to retrieve the number of current page.

end

Accessor method to retrieve the end of the frame.

next

Accessor method to retrieve the number of next page.

last

Accessor method to retrieve the number of the last one page.

frame_size

Accessor method to retrieve the frame size.

pages

Accessor method to retrieve the total number of pages

AUTHOR

Blabos de Blebe, <blabos at cpan.org>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Paginator::Lite

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2011 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.