| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Page; # git description: 090534c |
|
2
|
2
|
|
|
2
|
|
1215
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
99
|
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
36
|
|
|
4
|
2
|
|
|
2
|
|
7
|
use base 'Class::Accessor::Chained::Fast'; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
700
|
|
|
5
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(total_entries entries_per_page current_page)); |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '2.03'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
75
|
|
|
75
|
1
|
32248
|
my $class = shift; |
|
11
|
75
|
|
|
|
|
110
|
my $self = {}; |
|
12
|
75
|
|
|
|
|
108
|
bless( $self, $class ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
75
|
|
|
|
|
131
|
my ( $total_entries, $entries_per_page, $current_page ) = @_; |
|
15
|
75
|
|
100
|
|
|
255
|
$self->total_entries( $total_entries || 0 ); |
|
16
|
75
|
|
100
|
|
|
688
|
$self->entries_per_page( $entries_per_page || 10 ); |
|
17
|
74
|
|
100
|
|
|
536
|
$self->current_page( $current_page || 1 ); |
|
18
|
74
|
|
|
|
|
475
|
return $self; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub entries_per_page { |
|
22
|
2077
|
|
|
2077
|
1
|
8949
|
my $self = shift; |
|
23
|
2077
|
|
|
|
|
2070
|
my $entries_per_page = $_[0]; |
|
24
|
2077
|
100
|
|
|
|
2662
|
if (@_) { |
|
25
|
181
|
100
|
|
|
|
322
|
croak("Fewer than one entry per page!") if $entries_per_page < 1; |
|
26
|
180
|
|
|
|
|
276
|
return $self->_entries_per_page_accessor(@_); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
1896
|
|
|
|
|
2528
|
return $self->_entries_per_page_accessor(); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub current_page { |
|
32
|
1234
|
|
|
1234
|
1
|
2300
|
my $self = shift; |
|
33
|
1234
|
100
|
|
|
|
1829
|
if (@_) { |
|
34
|
184
|
|
|
|
|
283
|
return $self->_current_page_accessor(@_); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
1050
|
100
|
|
|
|
1557
|
return $self->first_page unless defined $self->_current_page_accessor; |
|
37
|
1049
|
100
|
|
|
|
5596
|
return $self->first_page |
|
38
|
|
|
|
|
|
|
if $self->_current_page_accessor < $self->first_page; |
|
39
|
1048
|
100
|
|
|
|
1672
|
return $self->last_page |
|
40
|
|
|
|
|
|
|
if $self->_current_page_accessor > $self->last_page; |
|
41
|
1047
|
|
|
|
|
1716
|
return $self->_current_page_accessor(); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub total_entries { |
|
45
|
2088
|
|
|
2088
|
1
|
2761
|
my $self = shift; |
|
46
|
2088
|
100
|
|
|
|
2912
|
if (@_) { |
|
47
|
111
|
|
|
|
|
216
|
return $self->_total_entries_accessor(@_); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
1977
|
|
|
|
|
2871
|
return $self->_total_entries_accessor; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub entries_on_this_page { |
|
53
|
71
|
|
|
71
|
1
|
30380
|
my $self = shift; |
|
54
|
|
|
|
|
|
|
|
|
55
|
71
|
100
|
|
|
|
127
|
if ( $self->total_entries == 0 ) { |
|
56
|
3
|
|
|
|
|
25
|
return 0; |
|
57
|
|
|
|
|
|
|
} else { |
|
58
|
68
|
|
|
|
|
455
|
return $self->last - $self->first + 1; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub first_page { |
|
63
|
1124
|
|
|
1124
|
1
|
26999
|
my $self = shift; |
|
64
|
|
|
|
|
|
|
|
|
65
|
1124
|
|
|
|
|
1965
|
return 1; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub last_page { |
|
69
|
1433
|
|
|
1433
|
1
|
6120
|
my $self = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
1433
|
|
|
|
|
1650
|
my $pages = $self->total_entries / $self->entries_per_page; |
|
72
|
1433
|
|
|
|
|
7403
|
my $last_page; |
|
73
|
|
|
|
|
|
|
|
|
74
|
1433
|
100
|
|
|
|
2338
|
if ( $pages == int $pages ) { |
|
75
|
377
|
|
|
|
|
392
|
$last_page = $pages; |
|
76
|
|
|
|
|
|
|
} else { |
|
77
|
1056
|
|
|
|
|
1258
|
$last_page = 1 + int($pages); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
1433
|
100
|
|
|
|
1943
|
$last_page = 1 if $last_page < 1; |
|
81
|
1433
|
|
|
|
|
2563
|
return $last_page; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub first { |
|
85
|
350
|
|
|
350
|
1
|
719
|
my $self = shift; |
|
86
|
|
|
|
|
|
|
|
|
87
|
350
|
100
|
|
|
|
466
|
if ( $self->total_entries == 0 ) { |
|
88
|
8
|
|
|
|
|
56
|
return 0; |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
342
|
|
|
|
|
1992
|
return ( ( $self->current_page - 1 ) * $self->entries_per_page ) + 1; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub last { |
|
95
|
242
|
|
|
242
|
1
|
29159
|
my $self = shift; |
|
96
|
|
|
|
|
|
|
|
|
97
|
242
|
100
|
|
|
|
354
|
if ( $self->current_page == $self->last_page ) { |
|
98
|
122
|
|
|
|
|
195
|
return $self->total_entries; |
|
99
|
|
|
|
|
|
|
} else { |
|
100
|
120
|
|
|
|
|
154
|
return ( $self->current_page * $self->entries_per_page ); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub previous_page { |
|
105
|
71
|
|
|
71
|
1
|
30228
|
my $self = shift; |
|
106
|
|
|
|
|
|
|
|
|
107
|
71
|
100
|
|
|
|
134
|
if ( $self->current_page > 1 ) { |
|
108
|
30
|
|
|
|
|
160
|
return $self->current_page - 1; |
|
109
|
|
|
|
|
|
|
} else { |
|
110
|
41
|
|
|
|
|
314
|
return undef; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub next_page { |
|
115
|
71
|
|
|
71
|
1
|
29972
|
my $self = shift; |
|
116
|
|
|
|
|
|
|
|
|
117
|
71
|
100
|
|
|
|
128
|
$self->current_page < $self->last_page ? $self->current_page + 1 : undef; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# This method would probably be better named 'select' or 'slice' or |
|
121
|
|
|
|
|
|
|
# something, because it doesn't modify the array the way |
|
122
|
|
|
|
|
|
|
# CORE::splice() does. |
|
123
|
|
|
|
|
|
|
sub splice { |
|
124
|
72
|
|
|
72
|
1
|
3824
|
my ( $self, $array ) = @_; |
|
125
|
72
|
100
|
|
|
|
128
|
my $top = @$array > $self->last ? $self->last : @$array; |
|
126
|
72
|
100
|
|
|
|
473
|
return () if $top == 0; # empty |
|
127
|
68
|
|
|
|
|
99
|
return @{$array}[ $self->first - 1 .. $top - 1 ]; |
|
|
68
|
|
|
|
|
510
|
|
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub skipped { |
|
131
|
71
|
|
|
71
|
1
|
29539
|
my $self = shift; |
|
132
|
|
|
|
|
|
|
|
|
133
|
71
|
|
|
|
|
147
|
my $skipped = $self->first - 1; |
|
134
|
71
|
100
|
|
|
|
422
|
return 0 if $skipped < 0; |
|
135
|
68
|
|
|
|
|
198
|
return $skipped; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub change_entries_per_page { |
|
139
|
70
|
|
|
70
|
1
|
124
|
my ( $self, $new_epp ) = @_; |
|
140
|
|
|
|
|
|
|
|
|
141
|
2
|
|
|
2
|
|
7239
|
use integer; |
|
|
2
|
|
|
|
|
24
|
|
|
|
2
|
|
|
|
|
8
|
|
|
142
|
70
|
50
|
|
|
|
175
|
croak("Fewer than one entry per page!") if $new_epp < 1; |
|
143
|
70
|
|
|
|
|
130
|
my $new_page = 1 + ( $self->first / $new_epp ); |
|
144
|
70
|
|
|
|
|
444
|
$self->entries_per_page($new_epp); |
|
145
|
70
|
|
|
|
|
417
|
$self->current_page($new_page); |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |