line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::HTML::Pager::Utils; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
87221
|
use base qw(Exporter); |
|
5
|
|
|
|
|
35
|
|
|
5
|
|
|
|
|
686
|
|
4
|
5
|
|
|
5
|
|
55
|
use strict; |
|
5
|
|
|
|
|
30
|
|
|
5
|
|
|
|
|
137
|
|
5
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
173
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
2335
|
use Error::Pure qw(err); |
|
5
|
|
|
|
|
49235
|
|
|
5
|
|
|
|
|
147
|
|
8
|
5
|
|
|
5
|
|
3111
|
use POSIX qw(ceil); |
|
5
|
|
|
|
|
39032
|
|
|
5
|
|
|
|
|
26
|
|
9
|
5
|
|
|
5
|
|
7377
|
use Readonly; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
2039
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(adjust_actual_page compute_index_values |
12
|
|
|
|
|
|
|
pages_num); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.05; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub adjust_actual_page { |
17
|
9
|
|
|
9
|
1
|
6733
|
my ($input_actual_page, $pages) = @_; |
18
|
|
|
|
|
|
|
|
19
|
9
|
100
|
|
|
|
28
|
if (! defined $pages) { |
20
|
1
|
|
|
|
|
5
|
err 'Not defined number of pages.'; |
21
|
|
|
|
|
|
|
} |
22
|
8
|
100
|
|
|
|
45
|
if ($pages !~ m/^\d+$/ms) { |
23
|
2
|
|
|
|
|
9
|
err 'Number of pages must be a positive number.'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# No pages. |
27
|
6
|
100
|
|
|
|
19
|
if ($pages == 0) { |
28
|
3
|
|
|
|
|
8
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
5
|
my $actual_page; |
32
|
3
|
100
|
|
|
|
8
|
if (! defined $input_actual_page) { |
33
|
1
|
|
|
|
|
2
|
$actual_page = 1; |
34
|
|
|
|
|
|
|
} else { |
35
|
2
|
|
|
|
|
8
|
$actual_page = $input_actual_page; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
3
|
100
|
|
|
|
8
|
if ($actual_page > $pages) { |
39
|
1
|
|
|
|
|
2
|
$actual_page = $pages; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
10
|
return $actual_page; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub compute_index_values { |
46
|
4
|
|
|
4
|
1
|
3235
|
my ($items, $actual_page, $items_on_page) = @_; |
47
|
|
|
|
|
|
|
|
48
|
4
|
100
|
|
|
|
12
|
if (! defined $actual_page) { |
49
|
1
|
|
|
|
|
4
|
return (); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
5
|
my ($begin_index, $end_index); |
53
|
3
|
|
|
|
|
5
|
$begin_index = ($actual_page - 1) * $items_on_page; |
54
|
3
|
|
|
|
|
5
|
$end_index = ($actual_page * $items_on_page) - 1; |
55
|
3
|
100
|
|
|
|
10
|
if ($end_index + 1 > $items) { |
56
|
1
|
|
|
|
|
2
|
$end_index = $items - 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
7
|
return ($begin_index, $end_index); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub pages_num { |
63
|
5
|
|
|
5
|
1
|
2519
|
my ($items, $items_on_page) = @_; |
64
|
|
|
|
|
|
|
|
65
|
5
|
|
|
|
|
7
|
my $pages = 0; |
66
|
5
|
100
|
100
|
|
|
24
|
if (defined $items && defined $items_on_page) { |
67
|
2
|
|
|
|
|
16
|
$pages = ceil($items / $items_on_page); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
5
|
|
|
|
|
13
|
return $pages; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |