10 my ($class, $values) = @_;
11 bless [map { tr/{/./; $_ } sort map { s/[^a-z]/{/g; $_ } @$values], $class;
16 my $options = shift || {};
17 my $pagesize = $options->{pagesize} || 50;
18 my $context = $options->{context } // 1 + ($pagesize >> 4);
19 my $length = $options->{length } || 4;
20 my $pages = $options->{pages } || 1 + int $#$self / $pagesize;
22 $pagesize = @$self / $pages;
25 while ($offset < @$self) {
26 my $link = substr $self->[$offset], 0, $length;
29 my $before = $offset > $context ? $self->[$offset - $context] : '';
30 for my $match (split //, $before) {
31 scalar $link =~ /\G\Q$match/g or last;
34 substr($link, $trim) = '' unless $trim > length $link;
41 for my $i (0 .. $#links - 1) {
42 my ($link, $lastchar) = $links[$i + 1]->[0] =~ /(.*)(.)/;
43 $link .= $lastchar eq '.' ? 'z' : chr( ord($lastchar) - 1 )
44 unless $lastchar eq 'a';
45 $links[$i]->[1] = $link;
58 List::Index - Paginate alphabetic entries by finding minimal prefixes
63 my $index = List::Index->new(\@values);
64 my @pages = $index->ranges({pagesize => 50});
65 printf '<a href="?start=%s&end=%s">%1$s</a> ', @$_ for @pages;
73 L<List::Maker|List::Maker> for complex ranges of numeric lists.
77 Mischa POSLAWSKY <perl@shiar.org>
81 Copyright. All rights reserved.