Giter VIP home page Giter VIP logo

class-dbi-pageset's Introduction

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.

class-dbi-pageset's People

Contributors

mvgrimes avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.