|
CGI::Pager - generate HTML pagination linkage easily. |
CGI::Pager - generate HTML pagination linkage easily.
Generates helper data and HTML for paginated representation of results.
my $pager = CGI::Pager->new(
total_count => $search_results_count,
page_len => 50,
);
print 'Found ', $search_results_count, ' results, displaying: ',
$pager->first_pos_displayed, ' - ', $pager->last_pos_displayed, ' ';
# Display links to first and previous page, if necessary.
unless ($pager->is_at_start) {
print a({ -href => $pager->first_url }, 'First page'), ' ',
a({ -href => $pager->prev_url }, '<< Previous page');
}
# Display links to each individual page of results.
foreach my $page ($pager->pages) {
if ($page->{is_current}) {
print strong($page->{number});
}
else {
print a({ -href => $page->{url} }, $page->{number});
}
}
# Display links to next and the last page, if necessary.
unless ($pager->is_at_end) {
print a({ -href => $pager->next_url }, 'Next page >>'), ' ',
a({ -href => $pager->last_url }, 'Last page');
}
my $pager = CGI::Pager->new(
labels => {
first => 'First',
last => 'Last',
next => 'Next',
prev => 'Previous',
},
links_order => [ qw/first prev pages next last/ ],
links_delim => ' | ',
pages_delim => ' ',
);
$template->param(
first_page_url => $pager->first_url,
prev_page_url => $pager->prev_url,
next_page_url => $pager->next_url,
last_page_url => $pager->last_url,
page_links => $pager->html('pages'),
);
print CGI::Pager::quick_html(
total_count => $search_results_count,
page_len => 50,
html_mode => 'combined',
);
CGI::Pager performs the ``dirty work'' necessary to program paginated data display in a web application. Based on given resultset size, page size, and offset value sensed from current URI, it constructs links for navigation between results pages. It can be used conveniently from a templating system, has both OO and functional interface, and can optionally generate necessary HTML itself.
url - the URL
of the page, number - the number of page, starting from 1,
and is_current - true if page is the currently displayed page.
first, last, prev, next, pages, combined or
combined_div. The first four will produce a single link to
respective page. 'pages' yields a string of links to individual
pages. combined, which is the default, is concatenation of
these. combined_div is like combined, but wrapped in a DIV
element with class attribute set to ``navBar''. The concatenation of
links can be controlled by links_order, links_delim and
pages_delim initialization parameters.
CGI::Pager::quick_html. Returns HTML generated by internally
created temporary pager instance. Made for those rare cases when not
using OO style is cleaner. Accepted parameters are the same as for
constructor, except with the extra html_mode which works like the
$mode parameter of html method.
All options are given as named parameters to constructor (when using OO style) and aren't then changeble - a CGI::Pager instance is not meant to persist between requests. Below is a list of valid options:
total_countpage_lenoffset_paramhide_zero_offseturl$ENV{REQUEST_URI}, which should be fine in most web application
environments.
labelslinks_orderlinks_delimpages_delim
This module operates on the assumption that current offset is passed as a GET request variable (except that for the first page, where it's OK for it to be absent.)
An instance of CGI::Pager is meant to last only for the duration of the request and isn't designed to be reused, like one might try in a mod_perl environment.
Egor Shipovalov, http://pragmaticware.com/
Copyright 2006 by Egor Shipovalov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
CGI::Pager - generate HTML pagination linkage easily. |