Class:...::Pager(3pm)
π Class::DBI::Pager β the pager bestie for Class::DBI π
okay so welcome to Class:...::Pager(3pm), straight out of the User Contributed Perl Documentation collection πΈ and bestie, this page is short, sweet, and genuinely so useful. Let's get into it.
β¨ NAME β¨
Class::DBI::Pager β a Pager utility for Class::DBI. that's it, that's the whole name π
π SYNOPSIS π
here's the vibe, copy it exactly bestie:
package CD;
use base qw(Class::DBI);
__PACKAGE__->set_db(...);
use Class::DBI::Pager; # just use it
# then, in client code!
package main;
use CD;
my $pager = CD->pager(20, 1); # ($items_per_page, $current_page)
my @disks = $pager->retrieve_all;
notice how you literally just use Class::DBI::Pager; and boom, paging is yours? no config, no fuss, iconic behaviour fr fr π
π¦ DESCRIPTION π¦
Class::DBI::Pager is a plugin for Class::DBI that glues Data::Page together with Class::DBI. the way that it just does the work for you?? obsessed ππ
say you're out here needing to:
- retrieve objects from a database
- display objects with 20 items per page
that's it. that's the whole chore. and this module lowkey removes a ton of that work for you.
and the plot twist? if you're using Template-Toolkit as your templating engine, your work gets reduced even more. check out the EXAMPLE section for the receipts β¨
π EXAMPLE π
here's the whole controller/view situation, and ngl it's giving main character energy:
# Controller: (MVC's C)
my $query = CGI->new;
my $template = Template->new;
my $pager = Film->pager(20, $query->param('page') || 1);
my $movies = $pager->retrieve_all;
$template->process($input, {
movies => $movies,
pager => $pager,
});
# View: (MVC's V)
Matched [% pager.total_entries %] items.
[% WHILE (movie = movies.next) %]
Title: [% movie.title | html %]
[% END %]
### navigation like: [1] [2] [3]
[% FOREACH num = [pager.first_page .. pager.last_page] %]
[% IF num == pager.current_page %][[% num %]]
[% ELSE %]<a href="display?page=[% num %]">[[% num %]]</a>[% END %]
[% END %]
### navigation like: prev 20 | next 20
[% IF pager.previous_page %]
<a href="display?page=[% pager.previous_page %]">
prev [% pager.entries_per_page %]</a> |
[% END %]
[% IF pager.next_page %]
<a href="display?page=[% pager.next_page %]">
next [% pager.entries_per_page %]</a>
[% END %]
like, the pager object just walks straight into your template and handles the navigation?? we love a self-sufficient queen π β¨
π NOTE / TODO π
okay real talk, a little caveat so nobody gets got:
this module internally retrieves iterators, and then it creates aData::Pageobject for the paging utility. so if memory is your concern, using SQL clausesLIMITand/orOFFSETtogether withDBIx::Pagermight be more memory efficient. just saying π
no cap, that's the honest tea.
π AUTHOR π
Tatsuhiko Miyagawa <miyagawa@bulknews.net> β the icon behind it all π«Ά
Original idea by Tomohiro Ikebe <ikebe@cpan.org> β the originator, the blueprint, the vision β¨
and legally speaking: this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt π
π SEE ALSO π
Class::DBIData::Page
go read those too, they're the supporting cast and they ate π
that's the whole page bestie! this one came from perl v5.34.0, dated 2022-06-10, and it's filed under Class:...::Pager(3pm). go page some records, you got this ππβ¨
π¦ where this page comes from
- debian bookworm: libclass-dbi-pager-perl 0.08-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-dbi-pager-perl 0.08-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-dbi-pager-perl 0.08-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-dbi-pager-perl 0.08-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-dbi-pager-perl 0.08-6 Β· 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