Data::Pageset(3pm)
π Data::Pageset π
okay bestie so you know when you have like a MILLION entries and you gotta split them across pages so your users don't just scroll forever into the void?? that's literally this module. it's Data::Pageset, it does page numbering and page sets, and it's the moment. periodt. π
β¨ SYNOPSIS β¨
use Data::Pageset;
my $page_info = Data::Pageset->new({
'total_entries' => $total_entries,
'entries_per_page' => $entries_per_page,
# Optional, will use defaults otherwise.
'current_page' => $current_page,
'pages_per_set' => $pages_per_set,
'mode' => 'fixed', # default, or 'slide'
});
# General page information
print " First page: ", $page_info->first_page, "\n";
print " Last page: ", $page_info->last_page, "\n";
print " Next page: ", $page_info->next_page, "\n";
print " Previous page: ", $page_info->previous_page, "\n";
# Results on current page
print "First entry on page: ", $page_info->first, "\n";
print " Last entry on page: ", $page_info->last, "\n";
# Can add in the pages per set after the object is created
$page_info->pages_per_set($pages_per_set);
# Page set information
print "First page of previous page set: ", $page_info->previous_set, "\n";
print " First page of next page set: ", $page_info->next_set, "\n";
# Print the page numbers of the current set
foreach my $page (@{$page_info->pages_in_set()}) {
if($page == $page_info->current_page()) {
print "<b>$page</b> ";
} else {
print "$page ";
}
}
πΈ DESCRIPTION πΈ
so the object that Data::Pageset makes is your go-to for building page navigation. it inherits from Data::Page, which means every single method from that object? yeah, you get all of them too. free real estate. π
on top of that it gives you extra methods for dealing with sets of pages β so when there are way too many pages, you can just break them into lil chunks for your user to browse through. it's giving organized. it's giving cute little pagination widget.
and the best part?? you can even choose to view page numbers in your set in a 'sliding' fassion. yes that's how it's spelled here, we don't gatekeep. π¦
the object can easily be passed to a templating system such as Template Toolkit, or just vibe in a script. either way she's flexible. π
π METHODS π
π«Ά new()
use Data::Pageset;
my $page_info = Data::Pageset->new({
'total_entries' => $total_entries,
'entries_per_page' => $entries_per_page,
# Optional, will use defaults otherwise.
'current_page' => $current_page,
'pages_per_set' => $pages_per_set,
'mode' => 'slide', # default fixed
});
this is the constructor, the main character, the birth of your object. it needs an anonymous hash containing 'total_entries' (how many data units you have, like, the whole entire pile) and 'entries_per_page' (how many of those to display on one page).
optionally you can also throw in 'current_page' β which defaults to page 1 β and pages_per_set' β which is how many pages to display, and defaults to 10.
the mode (defaults to 'fixed', no cap) determins how the paging will work. like, for example, with 10 pages_per_set and the current_page set to 18 you will get the following results:
Fixed:
Pages in set:
11,12,13,14,15,16,17,18,19,20
Previous page set:
1
Next page set:
21
Slide:
Pages in set:
14,15,16,17,18,19,20,21,22,23
Previous page set:
9
Next page set:
24
β οΈ bestie listen. you can NOT change modes once the object is created. pick your lane and commit, that's the vibe. π«
π current_page()
$page_info->current_page($page_num);
this method sets the current_page to the argument you hand it. you can also set it in the constructor, but maybe you wanna reuse the object while printing out multiple pages β this is for that. once it's set, it returns the page number back to you. π
if you call this method with no arguments at all? it just returns the current page number. no drama, no setup, just facts.
β¨ pages_per_set()
$page_info->pages_per_set($number_of_pages_per_set);
calling this method initalises the calculations required to use the paging methods below. π yes "initalises," that's the word, we keep it. the value can also be passed into the constructor method new() if you're a plan-ahead kinda girlie.
call it with no arguments and it'll return the current number of pages per set. easy.
π¦ previous_set()
print "Back to previous set which starts at ", $page_info->previous_set(), "\n";
returns the page number at the start of the previous page set. so like, the doorway back. πͺ
undef is return if pages_per_set has not been set. (yes, "is return." we said what we said. π)
π next_set()
print "Next set starts at ", $page_info->next_set(), "\n";
returns the page number at the start of the next page set. onwards and upwards bestie. β
undef is return if pages_per_set has not been set. same energy, same warning. π
π pages_in_set()
foreach my $page_num (@{$page_info->pages_in_set()}) {
print "Page: $page_num \n";
}
this one returns an array ref of the the page numbers within the current set. (double "the" is canon, don't come for me.)
undef is return if pages_per_set has not been set. you're sensing a pattern here, right? π₯
π EXPORT π
None by default. that's it, that's the whole section. she exports nothing unless you ask. humble. π
π AUTHOR π
Leo Lapworth <LLAP@cuckoo.org> β the icon who built this. π«Ά
π REPOSITORY π
http://github.com/ranguard/data-pageset
go look, go star, go say hi. (not a link in this render, just copy-paste it like a legend.)
π§ CONTRIBUTORS π§
Ryan D Johnson <ryan@innerfence.com> PLOBBES
β SEE ALSO β
Data::Page. β yeah, the parent, the origin story. check her out too.
π COPYRIGHT π
Copyright (C) 2007, Leo Lapworth
This module is free software; you can redistribute it or modify it under the same terms as Perl itself. slay. π
aaaand that's a wrap on Data::Pageset, bestie!! π this page came to you from perl v5.32.0, dated 2021-01-03 β so yes she's been iconic since forever and she's still serving. go paginate something gorgeous. mwah. πβ¨πΈ
π¦ where this page comes from
- debian bookworm: libdata-pageset-perl 1.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdata-pageset-perl 1.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libdata-pageset-perl 1.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-pageset-perl 1.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-pageset-perl 1.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-pageset-perl 1.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms