Karim A. Nassar > Activator-0.91 > Activator::Pager

Download:
Activator-0.91.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Activator::Pager - Object to assist in implementing pagination interfaces

SYNOPSIS ^

      use Activator::Pager;
      my $pager = new Activator::Pager( $offset, $length, $count, $total );

METHODS ^

new

Constructor to set internal variables.

Arguments: $offset - offset of the first item in this set ( 0 indexed ) $page_size - number of items per page $set_size - actual number of items in this set $total - total items available

Returns: $self

Sample:

  n == highest possible offset
  p == highest possbile page

  $self = bless( {
    next_offset => 5,  -- offset of next page ( 0..n ) or undef if you are 
                          on last page
    set_size => 5,     -- constructor argument
    prev_offset => 0,  -- offset of previous page ( 0..n ) or undef if you 
                          are on first page
    cur_page => 1,     -- the current page number of $offset
    last_page => 21,   -- the last page page for the total passed in ( 1..p )
    last_offset => 100,-- the last possible offset based on number pages ( 0..n )
    total => 103,      -- constructor argument
    next_page => 2,    -- the next possible page ( 1..p ) or undef if on 
                          last page ( offset == last_offset )
    page_size => 5     -- constructor argument
    to => 5,           -- the last member number of current page ( 1..n+1 )
    from => 1,         -- the first member number of current page ( offset+1 )
    prev_page => 1,    -- the previous page ( 1..p ) or undef if on first 
                          page ( offset == 0 )
    offset => 0        -- constructor argument
  }, Activator::Pager );

NOTE: we need to document the assuption of offset not being $to

FUTURE WORK

Implement getter functions if anyone wants it. We just access the vars directly at this time.

This module would be nicer if it did more magic such that I can include pagination trivially in a template.

AUTHOR ^

Karim A. Nassar

COPYRIGHT ^

Copyright (c) 2007 Karim A. Nassar <karim.nassar@acm.org>

You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

syntax highlighting: