| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::Pager; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26414
|
use 5.008; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
40
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
13
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1062
|
use URI; |
|
|
1
|
|
|
|
|
7305
|
|
|
|
1
|
|
|
|
|
31
|
|
|
8
|
1
|
|
|
1
|
|
802
|
use URI::QueryParam; |
|
|
1
|
|
|
|
|
742
|
|
|
|
1
|
|
|
|
|
1291
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
|
|
|
|
|
|
## The constructor |
|
16
|
3
|
|
|
3
|
1
|
23
|
my $proto = shift; |
|
17
|
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
58
|
my $self = bless { |
|
19
|
|
|
|
|
|
|
url => $ENV{REQUEST_URI}, |
|
20
|
|
|
|
|
|
|
offset_param => 'offset', |
|
21
|
|
|
|
|
|
|
hide_zero_offset => 1, |
|
22
|
|
|
|
|
|
|
page_len => 20, |
|
23
|
|
|
|
|
|
|
labels => { |
|
24
|
|
|
|
|
|
|
first => 'First', |
|
25
|
|
|
|
|
|
|
last => 'Last', |
|
26
|
|
|
|
|
|
|
next => 'Next', |
|
27
|
|
|
|
|
|
|
prev => 'Previous', |
|
28
|
|
|
|
|
|
|
}, |
|
29
|
|
|
|
|
|
|
links_order => [ qw/first prev pages next last/ ], |
|
30
|
|
|
|
|
|
|
links_delim => ' ', |
|
31
|
|
|
|
|
|
|
pages_delim => ' ', |
|
32
|
|
|
|
|
|
|
@_, |
|
33
|
|
|
|
|
|
|
}, $proto; |
|
34
|
|
|
|
|
|
|
|
|
35
|
3
|
|
|
|
|
28
|
$self->{URI} = URI->new($self->{url}); |
|
36
|
3
|
|
100
|
|
|
7028
|
$self->{offset} = $self->{URI}->query_param($self->{offset_param}) || 0; |
|
37
|
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
342
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub url_for_offset { |
|
43
|
|
|
|
|
|
|
## Returns URL for the given offset. |
|
44
|
4
|
|
|
4
|
0
|
5
|
my $self = shift; |
|
45
|
4
|
|
|
|
|
5
|
my ($offset) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
4
|
50
|
|
|
|
12
|
return undef unless defined $offset; |
|
48
|
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
22
|
my $work_uri = $self->{URI}->clone; |
|
50
|
|
|
|
|
|
|
|
|
51
|
4
|
100
|
66
|
|
|
42
|
if ($offset == 0 && $self->{hide_zero_offset}) { |
|
52
|
1
|
|
|
|
|
12
|
$work_uri->query_param_delete($self->{offset_param}); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
else { |
|
55
|
3
|
|
|
|
|
9
|
$work_uri->query_param($self->{offset_param} => $offset); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
539
|
return $work_uri; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub total_count { |
|
63
|
|
|
|
|
|
|
## Return total count of results, as set on initialization. |
|
64
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
return $self->{total_count}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub is_at_start { |
|
71
|
|
|
|
|
|
|
## Returns true if the pager is at the start of recordset. |
|
72
|
6
|
|
|
6
|
1
|
45
|
my $self = shift; |
|
73
|
|
|
|
|
|
|
|
|
74
|
6
|
|
|
|
|
34
|
return !$self->{offset}; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub is_at_end { |
|
79
|
|
|
|
|
|
|
## Returns true if the pager is at the end of recordset. |
|
80
|
6
|
|
|
6
|
1
|
10
|
my $self = shift; |
|
81
|
|
|
|
|
|
|
|
|
82
|
6
|
|
|
|
|
49
|
return $self->{offset} + $self->{page_len} >= $self->{total_count}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub next_offset { |
|
87
|
|
|
|
|
|
|
## Returns offset for the next page. |
|
88
|
3
|
|
|
3
|
1
|
743
|
my $self = shift; |
|
89
|
|
|
|
|
|
|
|
|
90
|
3
|
100
|
|
|
|
13
|
return $self->is_at_end ? undef : $self->{offset} + $self->{page_len}; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub prev_offset { |
|
95
|
|
|
|
|
|
|
## Returns offset for the previous page. |
|
96
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
|
97
|
|
|
|
|
|
|
|
|
98
|
3
|
100
|
|
|
|
7
|
return undef if $self->is_at_start; |
|
99
|
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
6
|
my $prev_offset = $self->{offset} - $self->{page_len}; |
|
101
|
2
|
50
|
|
|
|
8
|
$prev_offset = 0 if $prev_offset < 0; |
|
102
|
|
|
|
|
|
|
|
|
103
|
2
|
|
|
|
|
8
|
return $prev_offset; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub last_offset { |
|
108
|
|
|
|
|
|
|
## Returns offset for the last page. |
|
109
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
110
|
|
|
|
|
|
|
|
|
111
|
0
|
|
0
|
|
|
0
|
my $last_page_len = ($self->{total_count} % $self->{page_len}) |
|
112
|
|
|
|
|
|
|
|| $self->{page_len}; |
|
113
|
0
|
|
|
|
|
0
|
my $last_offset = $self->{total_count} - $last_page_len; |
|
114
|
0
|
0
|
|
|
|
0
|
$last_offset = 0 if $last_offset < 0; |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
return $last_offset; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub first_pos_displayed { |
|
121
|
|
|
|
|
|
|
## Returns position of the first row currently displayed. |
|
122
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
0
|
return $self->{offset} + 1; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub last_pos_displayed { |
|
129
|
|
|
|
|
|
|
## Returns position of the last row currently displayed. |
|
130
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
my $result = $self->{offset} + $self->{page_len}; |
|
133
|
0
|
0
|
|
|
|
0
|
$result = $self->{total_count} if $result > $self->{total_count}; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
return $result; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub prev_url { |
|
140
|
|
|
|
|
|
|
## Returns URL for the previous page as URI object. |
|
141
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
return $self->url_for_offset($self->prev_offset); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub next_url { |
|
148
|
|
|
|
|
|
|
## Returns URL for the next page as URI object. |
|
149
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
return $self->url_for_offset($self->next_offset); |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub first_url { |
|
156
|
|
|
|
|
|
|
## Returns URL for the first page as URI object. |
|
157
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
return $self->url_for_offset(0); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub last_url { |
|
164
|
|
|
|
|
|
|
## Returns URL for the last page as URI object. |
|
165
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
0
|
return $self->url_for_offset($self->last_offset); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub pages { |
|
172
|
|
|
|
|
|
|
## Returns reference to an array of hashes representing pages in |
|
173
|
|
|
|
|
|
|
## the result set. |
|
174
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
175
|
|
|
|
|
|
|
|
|
176
|
1
|
50
|
|
|
|
7
|
unless ($self->{pages}) { |
|
177
|
|
|
|
|
|
|
|
|
178
|
1
|
|
|
|
|
2
|
my $offset = 0; |
|
179
|
1
|
|
|
|
|
3
|
my $page_num = 1; |
|
180
|
|
|
|
|
|
|
|
|
181
|
1
|
|
|
|
|
2
|
do { |
|
182
|
4
|
|
|
|
|
6
|
push @{ $self->{pages} }, { |
|
|
4
|
|
|
|
|
15
|
|
|
183
|
|
|
|
|
|
|
url => $self->url_for_offset($offset), |
|
184
|
|
|
|
|
|
|
number => $page_num, |
|
185
|
|
|
|
|
|
|
offset => $offset, |
|
186
|
|
|
|
|
|
|
is_current => $offset == $self->{offset}, |
|
187
|
|
|
|
|
|
|
}; |
|
188
|
|
|
|
|
|
|
|
|
189
|
4
|
|
|
|
|
8
|
$offset += $self->{page_len}; |
|
190
|
4
|
|
|
|
|
14
|
$page_num++; |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} while ($offset < $self->{total_count}); |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
1
|
50
|
|
|
|
11
|
return wantarray ? @{ $self->{pages} } : $self->{pages}; |
|
|
0
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub html { |
|
200
|
|
|
|
|
|
|
## Returns HTML for specified part(s) of navigation. |
|
201
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
202
|
0
|
|
|
|
|
|
my ($format) = @_; |
|
203
|
|
|
|
|
|
|
|
|
204
|
0
|
0
|
|
|
|
|
if ($format eq 'combined_div') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
|
return @{ $self->pages } > 1 ? |
|
|
0
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
' ' . $self->html('combined') . ' ' : ''; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
elsif ($format eq 'combined') { |
|
209
|
0
|
|
|
|
|
|
return join $self->{links_delim}, |
|
210
|
|
|
|
|
|
|
grep defined, |
|
211
|
|
|
|
|
|
|
map $self->html($_), |
|
212
|
0
|
|
|
|
|
|
@{ $self->{links_order} }; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
elsif ($format eq 'pages') { |
|
215
|
0
|
0
|
|
|
|
|
return join $self->{pages_delim}, |
|
216
|
|
|
|
|
|
|
map $_->{is_current} ? |
|
217
|
|
|
|
|
|
|
"$_->{number}" : |
|
218
|
|
|
|
|
|
|
"{url}\">$_->{number}", |
|
219
|
|
|
|
|
|
|
$self->pages; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
else { |
|
222
|
0
|
0
|
0
|
|
|
|
return undef if $format =~ /^(first|prev)$/ && $self->is_at_start |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|| $format =~ /^(last|next)$/ && $self->is_at_end; |
|
224
|
0
|
|
|
|
|
|
my $url_method = "${format}_url"; |
|
225
|
0
|
|
|
|
|
|
return '$self->{labels}{$format}"; |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub quick_html { |
|
231
|
|
|
|
|
|
|
## Returns HTML generated by automatically created pager instance. |
|
232
|
|
|
|
|
|
|
## Designed to be called as function instead of OO interface. |
|
233
|
0
|
|
|
0
|
1
|
|
my %params = @_; |
|
234
|
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
my $html_mode = delete $params{html_mode}; |
|
236
|
0
|
|
|
|
|
|
my $pager = __PACKAGE__->new(%params); |
|
237
|
0
|
|
|
|
|
|
return $pager->html($html_mode); |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
1; |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
__END__ |