The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Page::FlickrLike - Generates flickr-like navigation links

SYNOPSIS

    use Data::Page;
    use Data::Page::FlickrLike;

    my $page = Data::Page->new();
    $page->total_entries($total_entries);
    $page->entries_per_page($entries_per_page);
    $page->current_page($current_page);
   
    print join (" ",
            map { $_ == 0
              ? q{<span>...</span>}
              : qq{<a href="/page/$_">$_</a>}
            } $page->navigations);  

    # 1*2 3 4 5 6 7 ... 76 77
    # 1 2 ... 10 11 12 13*14 15 16 ... 76 77
    # 1 2 ... 71 72 73 74 75 76 77*
    # Note: * means the current page

DESCRIPTION

Data::Page::FlickrLike is an extension to Data::Page to generate flickr-like navigation links.

METHODS

This method returns an array reference consisting of the the pages to display.

   $nav = $page->navigations

It calculates: how many pages should be displayed after the first and before the last page, whether or not there's a big enough gap between the first page and the current page to put an ellipsis and more. As the name of this modules says, the array ref should make it easy to generate a "Flickr-Like" navigation.

This methods uses "0" to represent an ellipsis between two sets of page numbers. For example, if you have enough pages, navigations() returns like this:

  [ 1, 2, 3, 4, 5, 6, 7, 0, 76, 77 ] 

So, to display an ellipsis(...) you would write:

    for my $num ($page->navigations) {
        if ($num == 0 ) {
            print "...";
        } else {
            print qq{<a href="/page/$_">$_</a>};
        }
    }

CONFIGURATION VARIABLES

By default, navigation() generates an array reference to create the same pagination than Flickr.com. But if you do not like this behavior, you can tweak the following configuration variables:

$Data::Page::FlickrLike::InnerWindow or $page->navigations({inner_window => $val})

Customises the minimum number of pages before and after the current page.

$Data::Page::FlickrLike::OuterWindow or $page->navigations({outer_window => $val})

Customises the number of pages at the start and end of the pager.

$Data::Page::FlickrLike::MinLength or $page->navigations({min_length => $val})

If current page is adjacent to an edge, the number of pages returned around current page will be extended to meet c<$Data::Page::FlickrLike::MinLength>

$Data::Page::FlickrLike::GlueLength or $page->navigations({glue_length => $val})

Customises the glue capability of the page. "Gluing" means that if the set containing the current page is isolated of an edge, we merge the two sets together by adding the interleaved pages to form a bigger set. This variable defines the maximum distance between two sets required to glue them together.

For example, these "3g" and "4g" are displayed because of the glue length (= 2).

 1   2   3   4   5   6*  7   8   9     ...   21   22
 1   2   3g  4   5   6   7*  8   9   10     ...   21   22
 1   2   3g  4g  5   6   7   8*  9   10   11     ...  21   22 
 1   2     ...   5   6   7   8   9*  10   11   12     ...   21   22

 (* represents the current page)

AUTHOR

Masayoshi Sekimura <sekimura@cpan.org> Yann Kerherve <yannk@cpan.org>

LICENSE

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

SEE ALSO

Data::Page, Data::Page::Navigation, http://flickr.com/