The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.




In Perl module

  my $s = Data::Scroller->new(
    max_value => $max_value,
    selected  => $selected,
    increment => $increment,
  my $page_params = $s->display;


  my $page_params = Data::Scroller->new(
    max_value => $max_value,
    selected  => $selected,
    increment => $increment,

You would then make the $page_params hashref returned via the display method available for use within your templating system.

For example if you were in a Catalyst based application:

        $c->stash->{page_params} = $page_params;

You also want the current 'increment' value available in your templates, so for example you could display/change the number of pages displayed per page via your template.

        $c->stash->{page_increment} = $s->increment;

Note: when using this module within the Catalyst framework, say for the 'page' attribute of a search, setting that attribute to 'selected' ( the currently selected page ) will not work as you expect. This is because this module expects 'selected' to be relevant to the database row you want whereas the catalyst 'page' attribute expects it to be the display page number. A work around for this problem is as such:

my $catalyst_attributes = { page => $selected == 0 ? $selected : int(($selected / 10) + 1), };

In Template

Here is an example of how to set up paging in your templates assuming Template::Toolkit and Catalyst:

        [% IF page_params %]
                <br />
                  [% IF page_params.page_first || page_params.page_first == 0 %]
                    <a class="paging" href="[% base _ c.namespace _ '/list?page=' _ page_params.page_first _ '&order=' _ order _ '&o2=' _ o2%]">&laquo; first</a>
                  [% END %]
                  [% IF page_params.page_prev || page_params.page_prev == 0 %]
                    <a class="paging" href="[% base _ c.namespace _ '/list?page=' _ page_params.page_prev _ '&order=' _ order _ '&o2=' _ o2 %]">&laquo; prev</a>
                  [% END %]
                  [% FOR p IN page_params.page_list %]
                    [% IF p.page_current %]
                      <span class="paging">[% p.page_display %]</span>
                    [% ELSE %]
                      <a class="paging" href="[% base _ c.namespace _ '/list?page=' _ p.page_value _ '&order=' _ order _ '&o2=' _ o2 %]">[% p.page_display %]</a>
                    [% END %]
                  [% END %]
                  [% IF page_params.page_next %]
                    <a class="paging" href="[% base _ c.namespace _ '/list?page=' _ page_params.page_next _ '&order=' _ order _ '&o2=' _ o2 %]">next &raquo;</a>
                  [% END %]
                  [% IF page_params.page_last %]
                    <a class="paging" href="[% base _ c.namespace _ '/list?page=' _ page_params.page_last _ '&order=' _ order _ '&o2=' _ o2 %]">last &raquo;</a>
                  [% END %]
        [% END %]

As you can see, you can simply add any additional parameters you wish to the paging links via your template.


Handle navigation of data over multiple pages in a 'rolling' pageset fashion, similar to that of google.

An alternative to Data::Page by Leon Brocard ( written long before I'd heard of that :)



The total number of elements, eg; table rows, to be displayed. Required.



The input parameter passed in from templates that indicates the new page currently being requested. Default 0 ( page 1 ).


Indicates the number of elements to display per page. Default 10.


The maximum number of pages to increment by in either direction for rolling page number display. Default $increment.


The name of the input parameter passed in from templates that indicates the current selected page. Default 'row_num'.


new( %args )

  %args = (
    max_value      => $max_value,
    selected       => $selected,
    increment      => $increment,
    page_increment => $page_increment,
    name           => $name

Constructor. Takes hash of both required and optional input parameters as arguments. For full descriptions of the available input options see the 'REQUIRED INPUT PARAMETERS' and 'OPTIONAL INPUT PARAMETERS' sections.


Determines the appropriate "set" of page numbers / links to display for the given arguments and returns a hashref of parameters for use in your template with the following structure:

  $page_params = {
    'page_increment' => $page_increment,
    'page_name' => $page_name,
    'page_list' => [
        'page_value' => $page_value,
        'page_display' => $page_number,
        'page_current' => $boolean
    'page_first' => $page_first,
    'page_last' => $page_last,
    'page_prev' => $page_prev,
    'page_next' => $page_next,
    'page_total' => $page_total,


return value of max_value config param.


return value of increment config param.


return value of max_display config param.


return value of name config param.


return value of selected param.


return value of page_increment config param.


Ben Hare for Fotango Ltd, London, <>,, (c) 2004/5.

Based on '', originally conceived and written by <>.


Copyright (c) 2004/5 Fotango, London

This module is free software. You can redistribute it or modify it under the same terms as Perl itself.