-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
171 lines (120 loc) · 5.73 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Data::Pageset(3) User Contributed Perl Documentation Data::Pageset(3)
NNAAMMEE
Data::Pageset - Page numbering and page sets
SSYYNNOOPPSSIISS
use Data::Pageset;
my $page_info = Data::Pageset->new({
'total_entries' => $total_entries,
'entries_per_page' => $entries_per_page,
# Optional, will use defaults otherwise.
'current_page' => $current_page,
'pages_per_set' => $pages_per_set,
'mode' => 'fixed', # default, or 'slide'
});
# General page information
print " First page: ", $page_info->first_page, "\n";
print " Last page: ", $page_info->last_page, "\n";
print " Next page: ", $page_info->next_page, "\n";
print " Previous page: ", $page_info->previous_page, "\n";
# Results on current page
print "First entry on page: ", $page_info->first, "\n";
print " Last entry on page: ", $page_info->last, "\n";
# Can add in the pages per set after the object is created
$page_info->pages_per_set($pages_per_set);
# Page set information
print "First page of previous page set: ", $page_info->previous_set, "\n";
print " First page of next page set: ", $page_info->next_set, "\n";
# Print the page numbers of the current set
foreach my $page (@{$page_info->pages_in_set()}) {
if($page == $page_info->current_page()) {
print "<b>$page</b> ";
} else {
print "$page ";
}
}
DDEESSCCRRIIPPTTIIOONN
The object produced by Data::Pageset can be used to create page naviga-
tion, it inherits from Data::Page and has access to all methods from
this object.
In addition it also provides methods for dealing with set of pages, so
that if there are too many pages you can easily break them into chunks
for the user to browse through.
You can even choose to view page numbers in your set in a 'sliding'
fassion.
The object can easily be passed to a templating system such as Template
Toolkit or be used within a script.
MMEETTHHOODDSS
_n_e_w_(_)
use Data::Pageset;
my $page_info = Data::Pageset->new({
'total_entries' => $total_entries,
'entries_per_page' => $entries_per_page,
# Optional, will use defaults otherwise.
'current_page' => $current_page,
'pages_per_set' => $pages_per_set,
'mode' => 'slide', # default fixed
});
This is the constructor of the object, it requires an anonymous hash
containing the 'total_entries', how many data units you have, and the
number of 'entries_per_page' to display. Optionally the 'current_page'
(defaults to page 1) and pages_per_set (how many pages to display,
defaults to 10) can be added.
The mode (which defaults to 'fixed') determines how the paging will
work, for example with 10 pages_per_set and the current_page set to 18
you will get the following results:
_F_i_x_e_d_:
Pages in set:
11,12,13,14,15,16,17,18,19,20
Previous page set:
1
Next page set:
21
_S_l_i_d_e_:
Pages in set:
14,15,16,17,18,19,20,21,22,23
Previous page set:
9
Next page set:
24
You can not change modes once the object is created.
_c_u_r_r_e_n_t___p_a_g_e_(_)
$page_info->current_page($page_num);
This method sets the current_page to the argument supplied, it can also
be set in the constructor, but you may want to reuse the object if
printing out multiple pages. It will then return the page number once
set.
If this method is called without any arguments it returns the current
page number.
_p_a_g_e_s___p_e_r___s_e_t_(_)
$page_info->pages_per_set($number_of_pages_per_set);
Calling this method initialises the calculations required to use the
paging methods below. The value can also be passed into the constructor
method _n_e_w_(_).
If called without any arguments it will return the current number of
pages per set.
_p_r_e_v_i_o_u_s___s_e_t_(_)
print "Back to previous set which starts at ", $page_info->previous_set(), "\n";
This method returns the page number at the start of the previous page
set. undef is return if pages_per_set has not been set.
_n_e_x_t___s_e_t_(_)
print "Next set starts at ", $page_info->next_set(), "\n";
This method returns the page number at the start of the next page set.
undef is return if pages_per_set has not been set.
_p_a_g_e_s___i_n___s_e_t_(_)
foreach my $page_num (@{$page_info->pages_in_set()}) {
print "Page: $page_num \n";
}
This method returns an array ref of the the page numbers within the
current set. undef is return if pages_per_set has not been set.
EEXXPPOORRTT
None by default.
AAUUTTHHOORR
Leo Lapworth <lt>[email protected]<gt> - let me know if you've used this
module - go on... you know you want to.
SSEEEE AALLSSOO
Data::Page.
CCOOPPYYRRIIGGHHTT
Copyright (C) 2003, Leo Lapworth
This module is free software; you can redistribute it or modify it
under the same terms as Perl itself.
perl v5.8.6 2006-01-21 Data::Pageset(3)