Data::Page::Pageset - change long page list to be shorter and well navigate


Pages number can be very high, and it is not comfortable to show user from the first page to the last page list. Sometimes we need split the page list into some sets to shorten the page list, the form is like:

 1-6 7-12 13 14 15 16 17 18 19-24 25-30 31-36 37-41

the first two part indicats the two pagesets, and in current pageset, we provide the normal page list from the first one to the last one, and provide the rest pagesets to indicate the pages scope.

In this module, you can specify the pages_per_set or max_pagesets for fine showing.


 use Data::Page::Pageset;
 # we use Data::Page object, so do prepare
 my $page = Data::Page->new($total_entries, $entries_per_page, $current_page);
 # create the pageset object
 my $pageset = Data::Page::Pageset->new( $page );
 my $pageset = Data::Page::Pageset->new( $page, 12 );
 my $pageset = Data::Page::Pageset->new( $page, { max_pagesets => $max_pagesets } );
 my $pageset = Data::Page::Pageset->new( $page, { pages_per_set => $pages_per_set } );

 # for using
 foreach my $chunk ( $pageset->total_pagesets ){
        if ( $chunk->is_current ){
                map { print "$_ " } ( $chunk->first .. $chunk->last );
                print "$chunk ";


 # default page_per_set is 10
 my $pageset = Data::Page::Pageset->new( $page );

 # set the page_per_set to be 12
 my $pageset = Data::Page::Pageset->new( $page, 12 );
 # another the same by passing hashref
 my $pageset = Data::Page::Pageset->new( $page, { pages_per_set => $pages_per_set } );

 # set the max_pagesets value, default is 1
 my $pageset = Data::Page::Pageset->new( $page, { max_pagesets => $max_pagesets } );
 # if max_pagesets supplies, the pages_per_set setting will be ignore
 my $pageset = Data::Page::Pageset->new( $page, 
        { max_pagesets => $max_pagesets, pages_per_set => $pages_per_set } );

We must need $page(isa Data::Page) object.

max_pagesets( $number )
 # set the max_pagesets value, and the $pageset's info will changed immediately
 $pageset->max_pagesets( $number );
pages_per_set( $number )
 # set the pages_per_set value, and the $pageset's info will changed immediately
 $pageset->pages_per_set( $number );
 my $present_setting = $pageset->pages_per_set();

return total pages' number.


return the actual pagesets number.

 my $chunk = $pageset->first_pageset;

return the first pageset, it's Data::Page::Pageset::Chunk object

 my $chunk = $pageset->last_pageset;

return the last pageset, it's Data::Page::Pageset::Chunk object

 my $chunk = $pageset->current_pageset;

return the current pageset which current page is in this pageset, it's Data::Page::Pageset::Chunk object

 my $chunk = $pageset->previous_pageset;

return the previous pageset, it's Data::Page::Pageset::Chunk object

 my $chunk = $pageset->next_pageset;

return the next pageset, it's Data::Page::Pageset::Chunk object

Data::Page::Pageset::Chunk object

a $pageset gives you some $chunk to do more stuff as you see above. Here gives the $chunk methods

 # return the first page number in this chunk
 # return the last page number in this chunk
 # return the middle page number in this chunk
 # return the pages number in this chunk
 # return true if this $chunk contains the current_page
 # if this chunk is from page 3 to 7, then print '3-7'
 print $chunk;
 print $chunk->as_string;
 print $chunk->as_string('-');

 # you can change default '-' as:
 print $chunk->as_string('~');

if the $chunk only contains one page, it will only return the page number.


Data::Page is what we need, Data::Pageset is the similar one, Template::Plugin::Pageset is the wrapper for this to using it more converiently in TT2 tempale.


just mail me to <>


Copyright 2004 by Chun Sheng.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Chun Sheng, <>