1Data::Page::Pageset(3)User Contributed Perl DocumentationData::Page::Pageset(3)
2
3
4
6 Data::Page::Pageset - change long page list to be shorter and well
7 navigate
8
10 Pages number can be very high, and it is not comfortable to show user
11 from the first page to the last page list. Sometimes we need split the
12 page list into some sets to shorten the page list, the form is like:
13
14 1-6 7-12 13 14 15 16 17 18 19-24 25-30 31-36 37-41
15
16 the first two part indicats the two pagesets, and in current pageset,
17 we provide the normal page list from the first one to the last one, and
18 provide the rest pagesets to indicate the pages scope.
19
20 In this module, you can specify the pages_per_set or max_pagesets for
21 fine showing.
22
24 use Data::Page::Pageset;
25 # we use Data::Page object, so do prepare
26 my $page = Data::Page->new($total_entries, $entries_per_page, $current_page);
27 # create the pageset object
28 my $pageset = Data::Page::Pageset->new( $page );
29 my $pageset = Data::Page::Pageset->new( $page, 12 );
30 my $pageset = Data::Page::Pageset->new( $page, { max_pagesets => $max_pagesets } );
31 my $pageset = Data::Page::Pageset->new( $page, { pages_per_set => $pages_per_set } );
32
33 # for using
34 foreach my $chunk ( $pageset->total_pagesets ){
35 if ( $chunk->is_current ){
36 map { print "$_ " } ( $chunk->first .. $chunk->last );
37 }else{
38 print "$chunk ";
39 }
40 }
41
43 new()
44 # default page_per_set is 10
45 my $pageset = Data::Page::Pageset->new( $page );
46
47 # set the page_per_set to be 12
48 my $pageset = Data::Page::Pageset->new( $page, 12 );
49 # another the same by passing hashref
50 my $pageset = Data::Page::Pageset->new( $page, { pages_per_set => $pages_per_set } );
51
52 # set the max_pagesets value, default is 1
53 my $pageset = Data::Page::Pageset->new( $page, { max_pagesets => $max_pagesets } );
54 # if max_pagesets supplies, the pages_per_set setting will be ignore
55 my $pageset = Data::Page::Pageset->new( $page,
56 { max_pagesets => $max_pagesets, pages_per_set => $pages_per_set } );
57
58 We must need $page(isa Data::Page) object.
59
60 max_pagesets( $number )
61 # set the max_pagesets value, and the $pageset's info will changed immediately
62 $pageset->max_pagesets( $number );
63
64 pages_per_set( $number )
65 # set the pages_per_set value, and the $pageset's info will changed immediately
66 $pageset->pages_per_set( $number );
67 my $present_setting = $pageset->pages_per_set();
68
69 $pageset->total_pages
70 return total pages' number.
71
72 $pageset->total_pagesets
73 return the actual pagesets number.
74
75 $pageset->first_pageset
76 my $chunk = $pageset->first_pageset;
77
78 return the first pageset, it's Data::Page::Pageset::Chunk object
79
80 $pageset->last_pageset
81 my $chunk = $pageset->last_pageset;
82
83 return the last pageset, it's Data::Page::Pageset::Chunk object
84
85 $pageset->current_pageset
86 my $chunk = $pageset->current_pageset;
87
88 return the current pageset which current page is in this pageset,
89 it's Data::Page::Pageset::Chunk object
90
91 $pageset->previous_pageset
92 my $chunk = $pageset->previous_pageset;
93
94 return the previous pageset, it's Data::Page::Pageset::Chunk object
95
96 $pageset->next_pageset
97 my $chunk = $pageset->next_pageset;
98
99 return the next pageset, it's Data::Page::Pageset::Chunk object
100
102 a $pageset gives you some $chunk to do more stuff as you see above.
103 Here gives the $chunk methods
104
105 first
106 # return the first page number in this chunk
107 $chunk->first;
108
109 last
110 # return the last page number in this chunk
111 $chunk->last;
112
113 middle
114 # return the middle page number in this chunk
115 $chunk->middle;
116
117 pages
118 # return the pages number in this chunk
119 $chunk->pages;
120
121 is_current
122 # return true if this $chunk contains the current_page
123 $chunk->is_current;
124
125 as_string
126 # if this chunk is from page 3 to 7, then print '3-7'
127 print $chunk;
128 print $chunk->as_string;
129 print $chunk->as_string('-');
130
131 # you can change default '-' as:
132 print $chunk->as_string('~');
133
134 if the $chunk only contains one page, it will only return the page
135 number.
136
138 Data::Page is what we need, Data::Pageset is the similar one,
139 Template::Plugin::Pageset is the wrapper for this to using it more
140 converiently in TT2 tempale.
141
143 just mail me to <me@chunzi.org>
144
146 Copyright 2004 by Chun Sheng.
147
148 This library is free software; you can redistribute it and/or modify it
149 under the same terms as Perl itself.
150
152 Chun Sheng, <me@chunzi.org>
153
154
155
156perl v5.34.0 2021-07-22 Data::Page::Pageset(3)