line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Paging::Collection; |
2
|
5
|
|
|
5
|
|
99924
|
use common::sense; |
|
5
|
|
|
|
|
35
|
|
|
5
|
|
|
|
|
29
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
5
|
5
|
|
|
|
|
46
|
new => 0, |
6
|
|
|
|
|
|
|
ro => [qw/ |
7
|
|
|
|
|
|
|
entries |
8
|
|
|
|
|
|
|
total_count |
9
|
|
|
|
|
|
|
per_page |
10
|
|
|
|
|
|
|
current_page |
11
|
|
|
|
|
|
|
base_url |
12
|
|
|
|
|
|
|
window |
13
|
|
|
|
|
|
|
/], |
14
|
|
|
|
|
|
|
rw => [qw/renderer/], |
15
|
5
|
|
|
5
|
|
3554
|
); |
|
5
|
|
|
|
|
4463
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
694
|
use Carp qw/croak/; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
329
|
|
18
|
5
|
|
|
5
|
|
4973
|
use POSIX qw/ceil/; |
|
5
|
|
|
|
|
42283
|
|
|
5
|
|
|
|
|
36
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
35
|
|
|
35
|
0
|
60722
|
my ($class, %args) = @_; |
22
|
35
|
|
|
|
|
161
|
bless \%args, $class; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub render { |
26
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
27
|
0
|
0
|
|
|
|
0
|
croak "don't set renderer" unless $self->renderer; |
28
|
0
|
|
|
|
|
0
|
$self->renderer->render($self); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub sliced_entries { |
32
|
29
|
|
|
29
|
0
|
3801
|
my $self = shift; |
33
|
29
|
|
|
|
|
88
|
scalar(@{$self->entries}) > $self->per_page ? |
|
9
|
|
|
|
|
136
|
|
34
|
29
|
100
|
|
|
|
32
|
[@{$self->entries}[0..($self->per_page-1)]] : $self->entries; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub current_visit_count { |
38
|
18
|
|
|
18
|
0
|
3025
|
my $self = shift; |
39
|
18
|
|
|
|
|
26
|
scalar(@{$self->sliced_entries}); |
|
18
|
|
|
|
|
38
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub already_visited_count { |
43
|
26
|
|
|
26
|
0
|
2470
|
my $self = shift; |
44
|
26
|
|
|
|
|
79
|
$self->per_page * ($self->current_page - 1) |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub visited_count { |
48
|
13
|
|
|
13
|
0
|
2244
|
my $self = shift; |
49
|
13
|
|
|
|
|
42
|
$self->already_visited_count + $self->current_visit_count; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub begin_count { |
53
|
8
|
|
|
8
|
0
|
2789
|
my $self = shift; |
54
|
8
|
|
|
|
|
30
|
$self->already_visited_count + 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub begin_position { |
58
|
5
|
|
|
5
|
0
|
2359
|
my $self = shift; |
59
|
5
|
|
|
|
|
37
|
1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub end_count { |
63
|
8
|
|
|
8
|
0
|
2475
|
my $self = shift; |
64
|
8
|
|
|
|
|
23
|
$self->visited_count; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub end_position { |
68
|
5
|
|
|
5
|
0
|
11
|
my $self = shift; |
69
|
5
|
|
|
|
|
10
|
scalar(@{$self->sliced_entries}); |
|
5
|
|
|
|
|
12
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub begin_entry { |
73
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
74
|
0
|
|
|
|
|
0
|
$self->sliced_entries->[$self->begin_position]; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub end_entry { |
78
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
79
|
0
|
|
|
|
|
0
|
$self->sliced_entries->[$self->end_position]; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub first_page { |
83
|
42
|
|
|
42
|
0
|
2993
|
my $self = shift; |
84
|
42
|
|
|
|
|
147
|
1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub last_page { |
88
|
56
|
|
|
56
|
0
|
2047
|
my $self = shift; |
89
|
56
|
100
|
|
|
|
140
|
croak "can't calc last_page without total_count" unless defined $self->total_count; |
90
|
53
|
|
|
|
|
348
|
ceil($self->total_count / $self->per_page); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub has_prev { |
94
|
8
|
|
|
8
|
0
|
1445
|
my $self = shift; |
95
|
8
|
|
|
|
|
31
|
$self->current_page > $self->first_page; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub prev_page { |
99
|
17
|
|
|
17
|
0
|
938
|
my $self = shift; |
100
|
17
|
|
|
|
|
50
|
$self->current_page - 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub has_next { |
104
|
8
|
|
|
8
|
0
|
957
|
my $self = shift; |
105
|
3
|
|
|
|
|
26
|
$self->total_count ? $self->current_page < $self->last_page |
106
|
8
|
100
|
|
|
|
29
|
: scalar(@{$self->entries}) > $self->per_page; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub next_page { |
110
|
17
|
|
|
17
|
0
|
2142
|
my $self = shift; |
111
|
17
|
|
|
|
|
48
|
$self->current_page + 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# inspired from Data::Page::Navigation |
115
|
|
|
|
|
|
|
sub navigation { |
116
|
13
|
|
|
13
|
0
|
117
|
my $self = shift; |
117
|
13
|
100
|
|
|
|
37
|
croak "can't calc navigation without window" unless defined $self->window; |
118
|
12
|
100
|
|
|
|
85
|
return [$self->first_page..$self->last_page] if $self->last_page <= $self->window; |
119
|
|
|
|
|
|
|
|
120
|
9
|
|
|
|
|
137
|
my @navigation = ($self->current_page); |
121
|
9
|
|
|
|
|
74
|
my $prev = $self->prev_page; |
122
|
9
|
|
|
|
|
54
|
my $next = $self->next_page; |
123
|
9
|
|
|
|
|
46
|
my $i = 0; |
124
|
9
|
|
|
|
|
23
|
while (@navigation < $self->window) { |
125
|
56
|
100
|
|
|
|
322
|
if ($i % 2) { |
126
|
26
|
100
|
|
|
|
46
|
unshift @navigation, $prev if $self->first_page <= $prev; |
127
|
26
|
|
|
|
|
27
|
$prev -= 1; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
else { |
130
|
30
|
100
|
|
|
|
49
|
push @navigation, $next if $self->last_page >= $next; |
131
|
30
|
|
|
|
|
286
|
$next += 1; |
132
|
|
|
|
|
|
|
} |
133
|
56
|
|
|
|
|
134
|
$i += 1; |
134
|
|
|
|
|
|
|
} |
135
|
9
|
|
|
|
|
88
|
$self->{_navigation} = \@navigation; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub begin_navigation_page { |
139
|
2
|
|
|
2
|
0
|
44
|
my $self = shift; |
140
|
2
|
|
|
|
|
5
|
my $navigation = $self->navigation; |
141
|
2
|
|
|
|
|
23
|
shift @{$navigation}; |
|
2
|
|
|
|
|
6
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub end_navigation_page { |
145
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
146
|
2
|
|
|
|
|
3
|
my $navigation = $self->navigation; |
147
|
2
|
|
|
|
|
15
|
pop @{$navigation}; |
|
2
|
|
|
|
|
5
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |