1NAME 2 Class::DBI::Pager - Pager utility for Class::DBI 3 4SYNOPSIS 5 package CD; 6 use base qw(Class::DBI); 7 __PACKAGE__->set_db(...); 8 9 use Class::DBI::Pager; # just use it 10 11 # then, in client code! 12 package main; 13 14 use CD; 15 my $pager = CD->pager(20, 1); # ($items_per_page, $current_page) 16 my @disks = $pager->retrieve_all; 17 18DESCRIPTION 19 Class::DBI::Pager is a plugin for Class::DBI, which glues Data::Page 20 with Class::DBI. This module reduces your work a lot, for example when 21 you have to do something like: 22 23 * retrieve objects from a database 24 * display objects with 20 items per page 25 26 In addition, your work will be reduced more, when you use 27 Template-Toolkit as your templating engine. See the section on "EXAMPLE" 28 for details. 29 30EXAMPLE 31 # Controller: (MVC's C) 32 my $query = CGI->new; 33 my $template = Template->new; 34 35 my $pager = Film->pager(20, $query->param('page') || 1); 36 my $movies = $pager->retrieve_all; 37 $template->process($input, { 38 movies => $movies, 39 pager => $pager, 40 }); 41 42 # View: (MVC's V) 43 Matched [% pager.total_entries %] items. 44 45 [% WHILE (movie = movies.next) %] 46 Title: [% movie.title | html %] 47 [% END %] 48 49 ### navigation like: [1] [2] [3] 50 [% FOREACH num = [pager.first_page .. pager.last_page] %] 51 [% IF num == pager.current_page %][[% num %]] 52 [% ELSE %]<a href="display?page=[% num %]">[[% num %]]</a>[% END %] 53 [% END %] 54 55 ### navigation like: prev 20 | next 20 56 [% IF pager.previous_page %] 57 <a href="display?page=[% pager.previous_page %]"> 58 prev [% pager.entries_per_page %]</a> | 59 [% END %] 60 [% IF pager.next_page %] 61 <a href="display?page=[% pager.next_page %]"> 62 next [% pager.entries_per_page %]</a> 63 [% END %] 64 65NOTE / TODO 66 This modules internally retrieves itertors, then creates "Data::Page" 67 object for paging utility. Using SQL clauses "LIMIT" and/or "OFFSET" 68 with "DBIx::Pager" might be more memory efficient. 69 70AUTHOR 71 Tatsuhiko Miyagawa <miyagawa@bulknews.net> 72 73 Original idea by Tomohiro Ikebe <ikebe@cpan.org> 74 75 This library is free software; you can redistribute it and/or modify it 76 under the same terms as Perl itself. 77 78SEE ALSO 79 the Class::DBI manpage, the Data::Page manpage 80 81