Data::SimplePaginator - data pagination without assumptions (I think)


Data-SimplePaginator documentation  | view source Contained in the Data-SimplePaginator distribution.

Index


NAME

Top

Data::SimplePaginator - data pagination without assumptions (I think)

SYNOPSIS

Top

 my $paginator;

 # paginate the alphabet into groups of 10 letters each
 $paginator = Data::SimplePaginator->new(10);
 $paginator->data(A..Z);

 # print the second page (K..T)
 foreach( $paginator->page(2) ) {
 	print $_;
 }

DESCRIPTION

Top

This module helps me create pagination without a lot of fuss. I looked at other pagination modules (see also, below) and their interfaces were cumbersome for me.

This module will NOT...

Keep track of the current page for you
Screw with your CGI or other environment
Generate any HTML

If you're using Template Toolkit you probably want to use Data::Pageset or Data::SpreadPagination because they have lots of subs that work great with the way TT is set up.

METHODS

Top

new

 my $number_per_page = 10;

 $paginator = Data::SimplePaginator->new();

 $paginator = Data::SimplePaginator->new($number_per_page);

 $paginator = Data::SimplePaginator->new($number_per_page, A..Z);

Creates a new pagination object to split up data into sets of $number_per_page. Default items per page is 10, and default data is the empty list.

data

 my @items = ('orange','apple','banana','...');

 $paginator->data( @items );

 my @all = $paginator->data;

This method lets you set new data items for the paginator. It stores a shallow copy of the array, not a reference to it.

Return value is the current data array.

size

 $paginator->size(15);

 my $items_per_page = $paginator->size;

This method lets you set the size of the page, a.k.a. the number of items per page.

Return value is the size of the page.

pages

 my $number_of_pages = $paginator->pages;

Returns the number of pages based on the data you provide and the number of items per page that you set.

page

 my @contents = $paginator->page($number);

 my @first_page = $paginator->page(1);

 my @last_page = $paginator->page( $paginator->pages );

The first page is page 1, the last page is number of pages.

Returns items from @list that are on the specified page. If you give an invalid/undefined page number or one that's out of range for your data set, you get an empty list.

EXAMPLES

Top

use Data::SimplePaginator;

paginate the alphabet into groups of 10 letters each

 $paginator = Data::SimplePaginator->new(10,A..Z);

add more elements to the paginator

 $paginator->data( $paginator->data, 1..4, map { lc } A..Z, 5..8 );

create a pageset paginator to group pages in sets of 3

 my $pageset = Data::SimplePaginator->new(3, 1..$paginator->pages);

SEE ALSO

Top

The other paginators I looked at before deciding to write this one:

HTML::Paginator
Data::Paginated
Data::Page (also: Data::Pageset, Data::SpreadPagination)

AUTHOR

Top

Jonathan Buhacoff <jonathan@buhacoff.net>

COPYRIGHT

Top

LICENSE

Top

This library is free software and can be modified and distributed under the same terms as Perl itself.


Data-SimplePaginator documentation  | view source Contained in the Data-SimplePaginator distribution.