line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
########################################### |
2
|
|
|
|
|
|
|
package Rose::DBx::Object::InternalPager; |
3
|
|
|
|
|
|
|
########################################### |
4
|
1
|
|
|
1
|
|
23020
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
1445
|
use Log::Log4perl qw(:easy); |
|
1
|
|
|
|
|
70989
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
########################################### |
11
|
|
|
|
|
|
|
sub new { |
12
|
|
|
|
|
|
|
########################################### |
13
|
0
|
|
|
0
|
0
|
|
my($class, %options) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $self = { |
16
|
|
|
|
|
|
|
%options, |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
$self->{pager_options}->{per_page} = 50 unless defined |
20
|
|
|
|
|
|
|
$self->{pager_options}->{per_page}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
$self->{pager_options}->{start_page} = 1 unless defined |
23
|
|
|
|
|
|
|
$self->{pager_options}->{start_page}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
for my $param (qw(manager_options class_name manager_method)) { |
26
|
0
|
0
|
|
|
|
|
if(!defined $options{ $param}) { |
27
|
0
|
|
|
|
|
|
LOGDIE "Missing mandatory paramter $param"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
bless $self, $class; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->{pager} = $self->make_pager( |
34
|
|
|
|
|
|
|
$self->{ class_name }, |
35
|
|
|
|
|
|
|
$self->{ manager_method }, |
36
|
|
|
|
|
|
|
$self->{ pager_options }, |
37
|
|
|
|
|
|
|
$self->{ manager_options }, |
38
|
0
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
########################################### |
44
|
|
|
|
|
|
|
sub next { |
45
|
|
|
|
|
|
|
########################################### |
46
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $self->{pager}->(); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
########################################### |
52
|
|
|
|
|
|
|
sub make_pager { |
53
|
|
|
|
|
|
|
########################################### |
54
|
0
|
|
|
0
|
0
|
|
my($self, $class, $method, $options, $moptions) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
$options = {} unless $options; |
57
|
0
|
0
|
|
|
|
|
$moptions = {} unless $moptions; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $manager_class = "${class}::Manager"; |
60
|
0
|
|
|
|
|
|
my $iterator_method = "${method}_iterator"; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $per_page = $options->{per_page}; |
63
|
0
|
|
|
|
|
|
my $page = $options->{start_page}; |
64
|
0
|
|
|
|
|
|
my $page_items_done = 0; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if(!defined $per_page) { |
67
|
0
|
|
|
|
|
|
LOGDIE "Parameter per_page not defined"; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
0
|
|
|
|
|
if(!defined $page) { |
70
|
0
|
|
|
|
|
|
LOGDIE "Parameter start_page not defined"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
DEBUG "Creating first pager iterator ", |
74
|
|
|
|
|
|
|
"class=$class per_page=$per_page"; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $itr = $manager_class->$iterator_method( |
77
|
|
|
|
|
|
|
page => $page, |
78
|
|
|
|
|
|
|
per_page => $per_page, |
79
|
|
|
|
|
|
|
%$moptions, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return sub { |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
0
|
|
|
if($page_items_done == $per_page) { |
85
|
|
|
|
|
|
|
# Page done? Get next iterator. |
86
|
0
|
|
|
|
|
|
$page++; |
87
|
0
|
|
|
|
|
|
DEBUG "Getting next iterator for ", |
88
|
|
|
|
|
|
|
"class=$class (page=$page)"; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$itr = $manager_class->$iterator_method( |
91
|
|
|
|
|
|
|
page => $page, |
92
|
|
|
|
|
|
|
per_page => $per_page, |
93
|
|
|
|
|
|
|
%$moptions); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$page_items_done = 0; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$page_items_done++; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $itr->next(); |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |