NAME

Teng::Plugin::Pager - Pager

SYNOPSIS

package MyApp::DB;
use parent qw/Teng/;
__PACKAGE__->load_plugin('Pager');

package main;
my $db = MyApp::DB->new(dbh => $dbh);
my $page = $c->req->param('page') || 1;
my ($rows, $pager) = $db->search_with_pager('user' => {type => 3}, {page => $page, rows => 5});

DESCRIPTION

This is a helper for pagination.

This pager fetches "entries_per_page + 1" rows. And detect "this page has a next page or not".

METHODS

my (\@rows, $pager) = $db->search_with_pager($table_name, \%where, \%opts)

Select from database with pagination.

The arguments are mostly same as $db-search()>. But two additional options are available.

$opts->{page}

Current page number.

$opts->{rows}

The number of entries per page.

This method returns ArrayRef[Teng::Row] and instance of Teng::Plugin::Pager::Page.

Teng::Plugin::Pager::Page

search_with_pager method returns the instance of Teng::Plugin::Pager::Page. It gives paging information.

METHODS

$pager->entries_per_page()

The number of entries per page('rows'. you provided).

$pager->current_page()

Returns: fetched page number.

$pager->has_next()

The page has next page or not in boolean value.

$pager->entries_on_this_page()

How many entries on this page?

$pager->next_page()

The page number of next page.

$pager->previous_page()

The page number of previous page.

$pager->prev_page()

Alias for $pager->previous_page().