gitpan / class-dbi-pageset Goto Github PK
View Code? Open in Web Editor NEWRead-only release history for Class-DBI-Pageset
Home Page: http://metacpan.org/release/Class-DBI-Pageset
Read-only release history for Class-DBI-Pageset
Home Page: http://metacpan.org/release/Class-DBI-Pageset
NAME Class::DBI::Pageset - A flexible pager utility for Class::DBI using Data::Pageset SYNOPSIS package CD; use base qw(Class::DBI); use Class::DBI::Pageset; # just use it __PACKAGE__->set_db(...); # then, in client code! package main; use CD; my $pager = CD->pager( { entries_per_page => 20, current_page => 1, pages_per_set => 10, } ); my @disks = $pager->retrieve_all; DESCRIPTION "Class::DBI::Pageset" is a plugin for "Class::DBI" that integrates "Data::Pageset" into "Class::DBI" with minimal fuss. This enables you to search via "Class::DBI" and grouping results into pages and page sets. This module is very similar to Tatsuhiko Miyagawa's very nice "Class::DBI::Pager" module, but uses "Data::Pageset" (or any module that inherits from "Data::Pageset", such as "Data::Pageset::Render") to create the pager. "Data::Pageset" provides a more flexible pager, which is better suited to searches that return many pages. This is not necessarily very efficient (see "NOTE" below for more). EXAMPLE # Controller: (MVC's C) my $query = CGI->new; my $template = Template->new; my $pager = Film->pager({ entries_per_page => 20, current_page => $query->param('page') || 1, pages_per_set => 5, }); 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: ... 5 [6] 7 8 9 ... [% IF pager.previous_set %] <a href="display?page=[% pager.previous_set %]">...</a> [% END %] [% FOREACH num = [ pager.pages_in_set ] %] [% IF num == pager.current_page %] [[% num %]] [% ELSE %]<a href="display?page=[% num %]">[% num %]</a>[% END %] [% END %] [% IF pager.next_set %] <a href="display?page=[% pager.next_set %]">...</a> [% END %] To use one of the modules that inherit from "Data::Pageset" (such as "Data::Pageset::Render") just include the module name as part of the "use" statement. use Class::DBI::Pageset qw(Data::Pageset::Render); ## Then in your code you can use $pager->html( '<a href="index?page=%s">%a</a>' ); METHODS pager() my $pager = Film->pager({ entries_per_page => 20, current_page => $query->param('page') || 1, pages_per_set => 5, mode => 'slide', }); This is the constructor for the pager. See "Data::Pageset" for more on the parameters. The $pager object can then be used as a normal "Class::DBI" object for searching. total_entries() entries_per_page() current_page() entries_on_this_page() first_page() last_page() first() last() previous_page() next_page() pages_in_navigatio() pages_per_set() previous_set() next_set() pages_in_set() See "Data::Pageset". NOTE This modules internally retrieves itertors, then creates Data::Page object for paging utility. Using SQL clauses LIMIT and/or OFFSET with DBIx::Pager might be more memory efficient. As this module is geared to searches that return many pages of results, it maybe more prone to inefficiencies than "Class::DBI::Pager". I had originally wanted to patch "Class::DBI::Pager" to use different pagers, ie, "Data::Page", "Data::Pageset", or "Data::Pageset::Render", but the constructors for "Data::Page" and "Data::Pageset" are incompatible and jamming them together didn't seem like a good fix. SEE ALSO "Class::DBI", "Data::Pageset" Or for alternatives: "Class::DBI::Pager", "DBIx::Class", "DBIx::Class::ResultSet::Data::Pageset" BUGS Please report any bugs or suggestions at <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-DBI-Pageset> AUTHOR Mark Grimes <[email protected]> Most of this code was shamelessly taken from the very nice "Class::DBI::Pager" by Tatsuhiko Miyagawa <[email protected]>. COPYRIGHT AND LICENSE Copyright (C) 2008 by mgrimes This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.