1Data::Pageset(3) User Contributed Perl Documentation Data::Pageset(3)
2
3
4
5NNAAMMEE
6 Data::Pageset - Page numbering and page sets
7
8SSYYNNOOPPSSIISS
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
45DDEESSCCRRIIPPTTIIOONN
46 The object produced by Data::Pageset can be used to create page naviga-
47 tion, it inherits from Data::Page and has access to all methods from
48 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
60MMEETTHHOODDSS
61 _n_e_w_(_)
62
63 use Data::Pageset;
64 my $page_info = Data::Pageset->new({
65 'total_entries' => $total_entries,
66 'entries_per_page' => $entries_per_page,
67 # Optional, will use defaults otherwise.
68 'current_page' => $current_page,
69 'pages_per_set' => $pages_per_set,
70 'mode' => 'slide', # default fixed
71 });
72
73 This is the constructor of the object, it requires an anonymous hash
74 containing the 'total_entries', how many data units you have, and the
75 number of 'entries_per_page' to display. Optionally the 'current_page'
76 (defaults to page 1) and pages_per_set (how many pages to display,
77 defaults to 10) can be added.
78
79 The mode (which defaults to 'fixed') determins how the paging will
80 work, for example with 10 pages_per_set and the current_page set to 18
81 you will get the following results:
82
83 _F_i_x_e_d_:
84
85 Pages in set:
86 11,12,13,14,15,16,17,18,19,20
87
88 Previous page set:
89 1
90
91 Next page set:
92 21
93
94 _S_l_i_d_e_:
95
96 Pages in set:
97 14,15,16,17,18,19,20,21,22,23
98
99 Previous page set:
100 9
101
102 Next page set:
103 24
104
105 You can not change modes once the object is created.
106
107 _c_u_r_r_e_n_t___p_a_g_e_(_)
108
109 $page_info->current_page($page_num);
110
111 This method sets the current_page to the argument supplied, it can also
112 be set in the constructor, but you may want to reuse the object if
113 printing out multiple pages. It will then return the page number once
114 set.
115
116 If this method is called without any arguments it returns the current
117 page number.
118
119 _p_a_g_e_s___p_e_r___s_e_t_(_)
120
121 $page_info->pages_per_set($number_of_pages_per_set);
122
123 Calling this method initalises the calculations required to use the
124 paging methods below. The value can also be passed into the constructor
125 method _n_e_w_(_).
126
127 If called without any arguments it will return the current number of
128 pages per set.
129
130 _p_r_e_v_i_o_u_s___s_e_t_(_)
131
132 print "Back to previous set which starts at ", $page_info->previous_set(), "\n";
133
134 This method returns the page number at the start of the previous page
135 set. undef is return if pages_per_set has not been set.
136
137 _n_e_x_t___s_e_t_(_)
138
139 print "Next set starts at ", $page_info->next_set(), "\n";
140
141 This method returns the page number at the start of the next page set.
142 undef is return if pages_per_set has not been set.
143
144 _p_a_g_e_s___i_n___s_e_t_(_)
145
146 foreach my $page_num (@{$page_info->pages_in_set()}) {
147 print "Page: $page_num \n";
148 }
149
150 This method returns an array ref of the the page numbers within the
151 current set. undef is return if pages_per_set has not been set.
152
153EEXXPPOORRTT
154 None by default.
155
156AAUUTTHHOORR
157 Leo Lapworth <lt>LLAP@cuckoo.org<gt> - let me know if you've used this
158 module - go on... you know you want to.
159
160SSEEEE AALLSSOO
161 Data::Page.
162
163CCOOPPYYRRIIGGHHTT
164 Copyright (C) 2003, Leo Lapworth
165
166 This module is free software; you can redistribute it or modify it
167 under the same terms as Perl itself.
168
169
170
171perl v5.8.6 2006-01-21 Data::Pageset(3)
172