|
NAMECGI::Pager - generate HTML pagination linkage easily. ABSTRACTGenerates helper data and HTML for paginated representation of results. SYNOPSISUsing with CGI.pm: 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');
}
Specifying custom parameters, combining templating system and built-in HTML generation: 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'),
);
Functional style, built-in HTML generation: print CGI::Pager::quick_html(
total_count => $search_results_count,
page_len => 50,
html_mode => 'combined',
);
DESCRIPTIONCGI::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. METHODS
PARAMETERSAll 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:
NOTESThis 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. SEE ALSOURI::QueryParam AUTHOREgor Shipovalov, <http://pragmaticware.com/> COPYRIGHT AND LICENSECopyright 2006 by Egor Shipovalov This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|