Data::...Pageset(3pm)
β¨ NAME β¨
Data::Page::Pageset β bestie, this is the module that takes a long, cursed page list and turns it into a short, navigable one π (it's a Perl module, from the User Contributed Perl Documentation, so you already know it's for us)
π¦ DESCRIPTION π¦
okay so picture this: your page numbers can get very high π and showing a user literally every page from the first to the last is just... not it. Not comfortable. Not the vibe. So sometimes we need to split that page list into some sets to shorten it, and the form is like:
1-6 7-12 13 14 15 16 17 18 19-24 25-30 31-36 37-41
the first two parts are the two pagesets, and in the current pageset we show the normal page list from the first one to the last one, and then we show the rest of the pagesets just to indicate the pages scope π
in this module you can specify the pages_per_set or max_pagesets for fine showing β¨ (yes those are the two knobs, remember them, they come back a LOT)
πΈ SYNOPSIS πΈ
use Data::Page::Pageset;
# we use Data::Page object, so do prepare
my $page = Data::Page->new($total_entries, $entries_per_page, $current_page);
# create the pageset object
my $pageset = Data::Page::Pageset->new( $page );
my $pageset = Data::Page::Pageset->new( $page, 12 );
my $pageset = Data::Page::Pageset->new( $page, { max_pagesets => $max_pagesets } );
my $pageset = Data::Page::Pageset->new( $page, { pages_per_set => $pages_per_set } );
# for using
foreach my $chunk ( $pageset->total_pagesets ){
if ( $chunk->is_current ){
map { print "$_ " } ( $chunk->first .. $chunk->last );
}else{
print "$chunk ";
}
}
π METHODS π
new()
# default page_per_set is 10
my $pageset = Data::Page::Pageset->new( $page );
# set the page_per_set to be 12
my $pageset = Data::Page::Pageset->new( $page, 12 );
# another the same by passing hashref
my $pageset = Data::Page::Pageset->new( $page, { pages_per_set => $pages_per_set } );
# set the max_pagesets value, default is 1
my $pageset = Data::Page::Pageset->new( $page, { max_pagesets => $max_pagesets } );
# if max_pagesets supplies, the pages_per_set setting will be ignore
my $pageset = Data::Page::Pageset->new( $page,
{ max_pagesets => $max_pagesets, pages_per_set => $pages_per_set } );
we must need $page (which isa Data::Page) object. no page object, no pageset, periodt.
π«Ά heads up bestie:page_per_setdefaults to10, andmax_pagesetsdefaults to1. also, ifmax_pagesetssupplies, thepages_per_setsetting will be ignore. the original said "ignore", i'm not fixing it, i'm just relaying the tea β
max_pagesets( $number )
# set the max_pagesets value, and the $pageset's info will changed immediately
$pageset->max_pagesets( $number );
sets the max_pagesets value, and the $pageset's info will changed immediately β like, instantly, no refresh needed π
pages_per_set( $number )
# set the pages_per_set value, and the $pageset's info will changed immediately
$pageset->pages_per_set( $number );
my $present_setting = $pageset->pages_per_set();
same energy: set the pages_per_set value and the $pageset's info will changed immediately. and with no args you can grab the $present_setting you've got going on rn β¨
$pageset->total_pages
return total pages' number. that's it, that's the whole thing π₯
$pageset->total_pagesets
return the actual pagesets number. (actual! as in, after all your settings did their thing)
$pageset->first_pageset
my $chunk = $pageset->first_pageset;
return the first pageset, it's a Data::Page::Pageset::Chunk object π
$pageset->last_pageset
my $chunk = $pageset->last_pageset;
return the last pageset, it's a Data::Page::Pageset::Chunk object π
$pageset->current_pageset
my $chunk = $pageset->current_pageset;
return the current pageset which current page is in this pageset, it's a Data::Page::Pageset::Chunk object β this is the main character pageset, lowkey π
$pageset->previous_pageset
my $chunk = $pageset->previous_pageset;
return the previous pageset, it's a Data::Page::Pageset::Chunk object π
$pageset->next_pageset
my $chunk = $pageset->next_pageset;
return the next pageset, it's a Data::Page::Pageset::Chunk object π
π§ Data::Page::Pageset::Chunk object π§
a $pageset gives you some $chunks to do more stuff with, as you see above. here are the $chunk methods, bestie, come get your food:
first
# return the first page number in this chunk
$chunk->first;
last
# return the last page number in this chunk
$chunk->last;
middle
# return the middle page number in this chunk
$chunk->middle;
pages
# return the pages number in this chunk
$chunk->pages;
is_current
# return true if this $chunk contains the current_page
$chunk->is_current;
as_string
# if this chunk is from page 3 to 7, then print '3-7'
print $chunk;
print $chunk->as_string;
print $chunk->as_string('-');
# you can change default '-' as:
print $chunk->as_string('~');
and if the $chunk only contains one page, it will only return the page number. no dash, no drama, just the number π
π SEE ALSO π
Data::Pageis what we needData::Pagesetis the similar oneTemplate::Plugin::Pagesetis the wrapper for this to using it more converiently in TT2 tempale
(iykyk β the typo energy is preserved, i don't make the rules, i just respect the source material π)
π BUGS π
just mail me to <me@chunzi.org> π§
π COPYRIGHT AND LICENSE π
Copyright 2004 by Chun Sheng.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π«Ά
β AUTHOR β
Chun Sheng, <me@chunzi.org>
and that's the whole page, bestie β you slayed it π
this was Data::...Pageset(3pm), documented for perl v5.34.0 and dated 2022-06-12, so go forth and pageset responsibly β¨ππ¦
π¦ where this page comes from
- debian bookworm: libdata-page-pageset-perl 1.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdata-page-pageset-perl 1.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-page-pageset-perl 1.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-page-pageset-perl 1.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-page-pageset-perl 1.02-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