Class:...::Pager(3pm)

πŸ“¦
version 0.08 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 a Data::Page object for the paging utility. so if memory is your concern, using SQL clauses LIMIT and/or OFFSET together with DBIx::Pager might 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::DBI
  • Data::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