1Data::Pageset(3) User Contributed Perl Documentation Data::Pageset(3)
2
3
4
6 Data::Pageset - Page numbering and page sets
7
9 use Data::Pageset;
10 my $page_info = Data::Pageset->new({
11 'total_entries' => $total_entries,
12 'entries_per_page' => $entries_per_page,
13 # Optional, will use defaults otherwise.
14 'current_page' => $current_page,
15 'pages_per_set' => $pages_per_set,
16 'mode' => 'fixed', # default, or 'slide'
17 });
18
19 # General page information
20 print " First page: ", $page_info->first_page, "\n";
21 print " Last page: ", $page_info->last_page, "\n";
22 print " Next page: ", $page_info->next_page, "\n";
23 print " Previous page: ", $page_info->previous_page, "\n";
24
25 # Results on current page
26 print "First entry on page: ", $page_info->first, "\n";
27 print " Last entry on page: ", $page_info->last, "\n";
28
29 # Can add in the pages per set after the object is created
30 $page_info->pages_per_set($pages_per_set);
31
32 # Page set information
33 print "First page of previous page set: ", $page_info->previous_set, "\n";
34 print " First page of next page set: ", $page_info->next_set, "\n";
35
36 # Print the page numbers of the current set
37 foreach my $page (@{$page_info->pages_in_set()}) {
38 if($page == $page_info->current_page()) {
39 print "<b>$page</b> ";
40 } else {
41 print "$page ";
42 }
43 }
44
46 The object produced by Data::Pageset can be used to create page
47 navigation, it inherits from Data::Page and has access to all methods
48 from this object.
49
50 In addition it also provides methods for dealing with set of pages, so
51 that if there are too many pages you can easily break them into chunks
52 for the user to browse through.
53
54 You can even choose to view page numbers in your set in a 'sliding'
55 fassion.
56
57 The object can easily be passed to a templating system such as Template
58 Toolkit or be used within a script.
59
61 new()
62 use Data::Pageset;
63 my $page_info = Data::Pageset->new({
64 'total_entries' => $total_entries,
65 'entries_per_page' => $entries_per_page,
66 # Optional, will use defaults otherwise.
67 'current_page' => $current_page,
68 'pages_per_set' => $pages_per_set,
69 'mode' => 'slide', # default fixed
70 });
71
72 This is the constructor of the object, it requires an anonymous hash
73 containing the 'total_entries', how many data units you have, and the
74 number of 'entries_per_page' to display. Optionally the 'current_page'
75 (defaults to page 1) and pages_per_set (how many pages to display,
76 defaults to 10) can be added.
77
78 The mode (which defaults to 'fixed') determins how the paging will
79 work, for example with 10 pages_per_set and the current_page set to 18
80 you will get the following results:
81
82 Fixed:
83
84 Pages in set:
85 11,12,13,14,15,16,17,18,19,20
86
87 Previous page set:
88 1
89
90 Next page set:
91 21
92
93 Slide:
94
95 Pages in set:
96 14,15,16,17,18,19,20,21,22,23
97
98 Previous page set:
99 9
100
101 Next page set:
102 24
103
104 You can not change modes once the object is created.
105
106 current_page()
107 $page_info->current_page($page_num);
108
109 This method sets the current_page to the argument supplied, it can also
110 be set in the constructor, but you may want to reuse the object if
111 printing out multiple pages. It will then return the page number once
112 set.
113
114 If this method is called without any arguments it returns the current
115 page number.
116
117 pages_per_set()
118 $page_info->pages_per_set($number_of_pages_per_set);
119
120 Calling this method initalises the calculations required to use the
121 paging methods below. The value can also be passed into the constructor
122 method new().
123
124 If called without any arguments it will return the current number of
125 pages per set.
126
127 previous_set()
128 print "Back to previous set which starts at ", $page_info->previous_set(), "\n";
129
130 This method returns the page number at the start of the previous page
131 set. undef is return if pages_per_set has not been set.
132
133 next_set()
134 print "Next set starts at ", $page_info->next_set(), "\n";
135
136 This method returns the page number at the start of the next page set.
137 undef is return if pages_per_set has not been set.
138
139 pages_in_set()
140 foreach my $page_num (@{$page_info->pages_in_set()}) {
141 print "Page: $page_num \n";
142 }
143
144 This method returns an array ref of the the page numbers within the
145 current set. undef is return if pages_per_set has not been set.
146
148 None by default.
149
151 Leo Lapworth "<LLAP@cuckoo.org>"
152
154 http://github.com/ranguard/data-pageset
155
157 Ryan D Johnson "<ryan@innerfence.com>" PLOBBES
158
160 Data::Page.
161
163 Copyright (C) 2007, Leo Lapworth
164
165 This module is free software; you can redistribute it or modify it
166 under the same terms as Perl itself.
167
169 Hey! The above document had some coding errors, which are explained
170 below:
171
172 Around line 112:
173 =back doesn't take any parameters, but you said =back 4
174
175 Around line 130:
176 =back doesn't take any parameters, but you said =back 4
177
178
179
180perl v5.36.0 2023-01-20 Data::Pageset(3)