1Class::DBI::Pager(3)  User Contributed Perl Documentation Class::DBI::Pager(3)
2
3
4

NAME

6       Class::DBI::Pager - Pager utility for Class::DBI
7

SYNOPSIS

9         package CD;
10         use base qw(Class::DBI);
11         __PACKAGE__->set_db(...);
12
13         use Class::DBI::Pager;        # just use it
14
15         # then, in client code!
16         package main;
17
18         use CD;
19         my $pager = CD->pager(20, 1);     # ($items_per_page, $current_page)
20         my @disks = $pager->retrieve_all;
21

DESCRIPTION

23       Class::DBI::Pager is a plugin for Class::DBI, which glues Data::Page
24       with Class::DBI. This module reduces your work a lot, for example when
25       you have to do something like:
26
27         * retrieve objects from a database
28         * display objects with 20 items per page
29
30       In addition, your work will be reduced more, when you use Template-
31       Toolkit as your templating engine. See "EXAMPLE" for details.
32

EXAMPLE

34         # Controller: (MVC's C)
35         my $query    = CGI->new;
36         my $template = Template->new;
37
38         my $pager    = Film->pager(20, $query->param('page') || 1);
39         my $movies   = $pager->retrieve_all;
40         $template->process($input, {
41             movies => $movies,
42             pager  => $pager,
43         });
44
45         # View: (MVC's V)
46         Matched [% pager.total_entries %] items.
47
48         [% WHILE (movie = movies.next) %]
49         Title: [% movie.title | html %]
50         [% END %]
51
52         ### navigation like: [1] [2] [3]
53         [% FOREACH num = [pager.first_page .. pager.last_page] %]
54         [% IF num == pager.current_page %][[% num %]]
55         [% ELSE %]<a href="display?page=[% num %]">[[% num %]]</a>[% END %]
56         [% END %]
57
58         ### navigation like: prev 20 | next 20
59         [% IF pager.previous_page %]
60         <a href="display?page=[% pager.previous_page %]">
61         prev [% pager.entries_per_page %]</a> |
62         [% END %]
63         [% IF pager.next_page %]
64         <a href="display?page=[% pager.next_page %]">
65         next [% pager.entries_per_page %]</a>
66         [% END %]
67

NOTE / TODO

69       This modules internally retrieves itertors, then creates "Data::Page"
70       object for paging utility. Using SQL clauses "LIMIT" and/or "OFFSET"
71       with "DBIx::Pager" might be more memory efficient.
72

AUTHOR

74       Tatsuhiko Miyagawa <miyagawa@bulknews.net>
75
76       Original idea by Tomohiro Ikebe <ikebe@cpan.org>
77
78       This library is free software; you can redistribute it and/or modify it
79       under the same terms as Perl itself.
80

SEE ALSO

82       Class::DBI, Data::Page
83
84
85
86perl v5.32.0                      2020-07-28              Class::DBI::Pager(3)
Impressum