line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Paginated; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
35703
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use base 'Data::Pageset'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
876
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
10827
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
268
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Data::Paginated - paginate a list of data |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $paginator = Data::Paginated->new({ |
19
|
|
|
|
|
|
|
entries => \@my_list, |
20
|
|
|
|
|
|
|
entries_per_page => $entries_per_page, |
21
|
|
|
|
|
|
|
current_page => $current_page, |
22
|
|
|
|
|
|
|
}); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my @to_print = $paginator->page_data; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Data::Paginated is a thin wrapper around Data::Pageset which adds the |
29
|
|
|
|
|
|
|
extra functionality of being able to get all the entries from a list |
30
|
|
|
|
|
|
|
that are on a given page. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 new |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $paginator = Data::Paginated->new({ |
37
|
|
|
|
|
|
|
entries => \@my_list, |
38
|
|
|
|
|
|
|
entries_per_page => $entries_per_page, |
39
|
|
|
|
|
|
|
current_page => $current_page, |
40
|
|
|
|
|
|
|
}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This can take all the arguments that can be passed to Data::Pageset, |
43
|
|
|
|
|
|
|
with the exception that instead of passing simply the total number of |
44
|
|
|
|
|
|
|
items in question, you actually pass the items as a reference. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 page_data |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my @to_print = $paginator->page_data; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This returns a list of the entries that will be on the current page. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
So, if you have a list of [ 1 .. 10 ], 3 entries per page, and current |
53
|
|
|
|
|
|
|
page is 2, this will return (4, 5, 6). |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub new { |
58
|
2
|
|
|
2
|
1
|
774
|
my ($class, $conf) = @_; |
59
|
2
|
50
|
|
|
|
10
|
my $entries = delete $conf->{entries} or croak "entries must be supplied"; |
60
|
2
|
|
|
|
|
20
|
my $self = $class->SUPER::new({ %$conf, total_entries => scalar @$entries }); |
61
|
2
|
|
|
|
|
470
|
$self->{__DATA_PAGINATED_ENTRIES} = $entries; |
62
|
2
|
|
|
|
|
5
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub page_data { |
66
|
2
|
|
|
2
|
1
|
9
|
my $self = shift; |
67
|
2
|
|
|
|
|
9
|
return @{ $self->{__DATA_PAGINATED_ENTRIES} } |
|
2
|
|
|
|
|
352
|
|
68
|
|
|
|
|
|
|
[ $self->first - 1 .. $self->last - 1 ]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Tony Bowden |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 BUGS and QUERIES |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Please direct all correspondence regarding this module to: |
78
|
|
|
|
|
|
|
bug-Data-Paginated@rt.cpan.org |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Copyright (C) 2004-2005 Kasei |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
85
|
|
|
|
|
|
|
the terms of the GNU General Public License; either version 2 of the License, |
86
|
|
|
|
|
|
|
or (at your option) any later version. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT |
89
|
|
|
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
90
|
|
|
|
|
|
|
FOR A PARTICULAR PURPOSE. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SEE ALSO |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L, L. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|