Template::Plugin::Pagination - a plugin to help paginate pages of results


Template-Plugin-Pagination documentation Contained in the Template-Plugin-Pagination distribution.

Index


Code Index:

NAME

Top

Template::Plugin::Pagination - a plugin to help paginate pages of results

SYNOPSIS

Top

  [% USE page = Pagination(items, current_page, entries_per_page) %]

	[% FOREACH item IN page.page_data; ...; DONE %]

  First page: [% page.first_page %]
  Prev page: [% page.previous_page %]
  Next page: [% page.next_page %]
  Last page: [% page.last_page %]

DESCRIPTION

Top

This plugin helps you construct pages that include subsets of data from a list, such as search results which you'll paginated in groups of 10.

It's based heavily on Template::Plugin::Page, which you should see for a detailed example of to use this. (That module is a thin wrapper around Data::Page, whereas this one is a wrapper around Data::Paginated, which is Data::Page + Data::Pageset + some extras).

METHODS

Top

new

This is the constructor. It has one mandatory arguments: the list of items we're working with. You can also pass the page number you're currently working with which will otherwise default to 1) and the number of entries there will be on each page (which defaults to 10).

Pageset Methods

Top

You now have available all the methods from Data::Page, Data::Pageset and Data::Paginated, including:

page_data
first_page
last_page
next_page
previous_page

See their manual pages for details.

AUTHOR

Top

Tony Bowden, <cpan@tmtm.com>

BUGS and QUERIES

Top

Please direct all correspondence regarding this module to: bug-Template-Plugin-Pagination@rt.cpan.org

SEE ALSO

Top

Template::Plugin::Page, Data::Page, Data::Pageset, Data::Paginated

COPYRIGHT

Top


Template-Plugin-Pagination documentation Contained in the Template-Plugin-Pagination distribution.
package Template::Plugin::Pagination;

$VERSION = '0.90';

use strict;
use Data::Paginated;
use base 'Template::Plugin';

sub new {
  my ($proto, $context, $list, $current, $per_page) = @_;
  my $class = ref($proto) || $proto;

  ($list, $per_page, $current) = ($context, $list, $per_page)
    unless ref($context) eq 'Template::Context';

  return Data::Paginated->new({
    entries => $list,
    entries_per_page => $per_page || 10,
    current_page => $current || 1,
	});
}