line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::HTML::Pager::Utils; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
73144
|
use base qw(Exporter); |
|
5
|
|
|
|
|
26
|
|
|
5
|
|
|
|
|
541
|
|
4
|
5
|
|
|
5
|
|
30
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
120
|
|
5
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
191
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
1987
|
use Error::Pure qw(err); |
|
5
|
|
|
|
|
40877
|
|
|
5
|
|
|
|
|
91
|
|
8
|
5
|
|
|
5
|
|
2494
|
use POSIX qw(ceil); |
|
5
|
|
|
|
|
32280
|
|
|
5
|
|
|
|
|
22
|
|
9
|
5
|
|
|
5
|
|
6023
|
use Readonly; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
1619
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(adjust_actual_page compute_index_values |
12
|
|
|
|
|
|
|
pages_num); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.04; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub adjust_actual_page { |
17
|
9
|
|
|
9
|
1
|
18537
|
my ($input_actual_page, $pages) = @_; |
18
|
|
|
|
|
|
|
|
19
|
9
|
100
|
|
|
|
22
|
if (! defined $pages) { |
20
|
1
|
|
|
|
|
4
|
err 'Not defined number of pages.'; |
21
|
|
|
|
|
|
|
} |
22
|
8
|
100
|
|
|
|
38
|
if ($pages !~ m/^\d+$/ms) { |
23
|
2
|
|
|
|
|
8
|
err 'Number of pages must be a positive number.'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# No pages. |
27
|
6
|
100
|
|
|
|
14
|
if ($pages == 0) { |
28
|
3
|
|
|
|
|
6
|
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
|
|
|
|
|
2
|
$actual_page = $input_actual_page; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
3
|
100
|
|
|
|
8
|
if ($actual_page > $pages) { |
39
|
1
|
|
|
|
|
3
|
$actual_page = $pages; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
8
|
return $actual_page; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub compute_index_values { |
46
|
4
|
|
|
4
|
1
|
2615
|
my ($items, $actual_page, $items_on_page) = @_; |
47
|
|
|
|
|
|
|
|
48
|
4
|
100
|
|
|
|
10
|
if (! defined $actual_page) { |
49
|
1
|
|
|
|
|
4
|
return (); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
5
|
my ($begin_index, $end_index); |
53
|
3
|
|
|
|
|
6
|
$begin_index = ($actual_page - 1) * $items_on_page; |
54
|
3
|
|
|
|
|
4
|
$end_index = ($actual_page * $items_on_page) - 1; |
55
|
3
|
100
|
|
|
|
9
|
if ($end_index + 1 > $items) { |
56
|
1
|
|
|
|
|
2
|
$end_index = $items - 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
8
|
return ($begin_index, $end_index); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub pages_num { |
63
|
5
|
|
|
5
|
1
|
2069
|
my ($items, $items_on_page) = @_; |
64
|
|
|
|
|
|
|
|
65
|
5
|
|
|
|
|
10
|
my $pages = 0; |
66
|
5
|
100
|
100
|
|
|
20
|
if (defined $items && defined $items_on_page) { |
67
|
2
|
|
|
|
|
31
|
$pages = ceil($items / $items_on_page); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
5
|
|
|
|
|
12
|
return $pages; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |