Data::Paginator(3pm)

πŸ“¦
version 0.08 Β· 2 versions
  • 0.08 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.08 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Data::Paginator β€” pagination, but make it Moose πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation corner of your local man setup, and it's all about Data::Paginator. grab a snack, we're doing pagination πŸŽ€


✨ NAME ✨

Data::Paginator β€” Pagination with Moose πŸ¦‹


🌸 VERSION 🌸

version 0.08


🧚 SYNOPSIS 🧚

use Data::Paginator;

my $pager = Data::Paginator->new(
    current_page => 1,
    entries_per_page => 10,
    total_entries => 100,
);

print "First page: ".$pager->first_page."\n";
print "Last page: ".$pager->last_page."\n";
print "First entry on page: ".$pager->first."\n";
print "Last entry on page: ".$pager->last."\n";

like… look at her. clean. composed. she knows exactly where every entry lives πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

okay so real talk: this is yet another pagination module. iconic behavior, honestly. it literally only exists because none of the other pager modules are written using Moose 😭

sometimes there's a Moose feature β€” MooseX::Storage, in the author's case β€” that you genuinely need, and it's a whole pain when you can't use it with an existing module. so this exists. she aims to be completely compatible with the venerable Data::Page. and not even in a sneaky way β€” it's a pretty blatant copy of Data::Page, lifting code from some of its methods. no cap, she said it herself 🫢


🌈 SETS 🌈

this module provides behavior compatible with Data::PageSet, which means you can break your pagination into sets ✨

so like, imagine you've got a huge number of pages to show and you want the user to be able to 'jump' X pages at a time. you set the pages_per_set attribute to X and populate the links in your pagination control with the values from previous_set and next_set. boom. sets. slay πŸŽ€


πŸ‘‘ ATTRIBUTES πŸ‘‘

⭐ current_page

the current page. defaults to 1 πŸ’–

if you set this value to a page number lesser than or greater than the range of the pager, then 1 or the last_page will be returned instead. so it is safe to pass in numbers like -1000 or 1000 when there are only 3 pages. she will not let you embarrass yourself bestie πŸ™ˆ

⭐ entries_per_page

the number of entries per page. required at instantiation β€” no entry-per-page, no pager, periodt.

⭐ last_page

returns the number of the last page. it's lazily computed, so do not set it. she computes herself, thank you πŸ’…

⭐ next_set

returns the number of the next set, or undef if there is no next. 🌸

⭐ pages_per_set

if you've got a large number of pages to show and would like to let the user 'jump' X pages at a time, you set the pages_per_set attribute to X and populate the links in your pagination control with the values from previous_set and next_set. same energy as the SETS section, and yes she's saying it twice because it's important πŸ’–

⭐ previous_set

returns the set number of the previous set, or undef if there is no previous set. πŸ¦‹

⭐ total_entries

the total number of entries this pager is covering. required at instantiation fr fr.

⭐ first

returns the number of the first entry on the current page ✨

⭐ first_page

always returns 1. she's consistent. she's reliable. she's the moment πŸ‘‘


πŸ’… METHODS πŸ’…

πŸŽ€ entries_on_this_page

returns the number of entries on this page.

πŸŽ€ first_set

returns 1 if this Paginator has pages_per_set. otherwise returns undef.

πŸŽ€ last

returns the number of the last entry on the current page.

πŸŽ€ next_page

returns the page number of the next page if one exists, otherwise returns false.

πŸŽ€ page_for ($count)

returns the page number that the $count item appears on. returns undef if $count is outside the bounds of this Paginator.

πŸŽ€ previous_page

returns the page number of the previous page if one exists, otherwise returns undef.

πŸŽ€ set_for $page

returns the set number of the specified page. returns undef if the page exceeds the bounds of the Paginator.

πŸŽ€ splice

takes in an arrayref and returns only the values which are on the current page. like a little filter, but make it pagination πŸ“


🌟 ACKNOWLEDGEMENTS 🌟

Léon Brocard and his work on Data::Page. 🫢


πŸ’– AUTHOR πŸ’–

Cory G Watson <gphat@cpan.org>


This software is copyright (c) 2014 by Cory G Watson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


okay that's the whole page bestie, you ate it πŸ’…βœ¨ this was Data::Paginator as documented for perl v5.34.0, dated 2022-06-12, and she's filed under Data::Paginator(3pm) β€” go paginate something iconic, mwah πŸŽ€πŸ’–πŸ¦‹

πŸ“¦ where this page comes from