Debian Codegraph @

README

raw
1 NAME
2 Data::Pager - flexible data pager
3
4 SYNOPSIS
5 use Data::Pager;
6
7 my $pager = Data::Pager->new({
8 current => 100,
9 perpage => 10,
10 offset => 5,
11 limit => 2000,
12 });
13
14 #~ accessors:
15 $pager->current; # 100
16 $pager->next; # 101
17 $pager->prev; # 99
18 $pager->limit; # 2000
19 $pager->start; # 1 # not typical start of a programmer
20 $pager->final; # \
21 # 400 (which denotes 2000 / 5 pager links)
22 $pager->end; # /
23 $pager->from; # 495 (may serve in SQL LIMIT clause)
24 $pager->to; # 500 (may serve in SQL LIMIT clause)
25 $pager->list; # 95 96 97 98 99 100 101 102 103 104 105
26
27 DESCRIPTION
28 This class implements the familiar pager where the current position is
29 centered.
30
31 CONSTRUCTOR
32 new
33 my $pager = Data::Pager->new({
34 current => 1, # this is the current pager position
35 perpage => 10, # the pager consists of this number of links (defaults to 10)
36 offset => 5, # this is the number of results (fetched from the DB for example) per result
37 limit => 100, # how far is the pager allowed
38 });
39
40 # sample output from html table:
41
42 id ... ..... ...
43 1. ... ..... ...
44 2. ... ..... ...
45 3. ... ..... ...
46 4. ... ..... ...
47 5. ... ..... ...
48
49 1 2 3 4 5 6 7 8 9 10
50
51 Returns object or undef if current position is beyond the limit.
52
53 METHODS
54 current
55 $pager->current();
56
57 Returns the current pager position.
58
59 set_current($digit)
60 $pager->set_current(850);
61 $pager->set_current(850)->next();
62
63 Sets the current pager position. Returns the pager object on succes,
64 undef on false.
65
66 next
67 Returns the next pager position or undef if this is the last one.
68
69 prev
70 Returns the previous pager position or undef if this is the first one.
71
72 start
73 Returns 1 - the start pager position.
74
75 end
76 Returns the end pager position.
77
78 first
79 Returns the first pager position for this result set.
80
81 last
82 Returns the last pager position for this result set.
83
84 from
85 '1' => {
86 'to' => 5,
87 'next' => 2,
88 'prev' => undef,
89 'from' => 0
90 },
91 '2' => {
92 'to' => 10,
93 'next' => 3,
94 'prev' => 1,
95 'from' => 5
96 },
97 ...
98
99 Returns the start result this pager position refers to.
100
101 to
102 Returns the end result this pager position refers to.
103
104 list
105 @_ = $pager->list;
106 $_ = $pager->list;
107
108 Returns the pager links for this result set. In list context returns the
109 resulting list. In scalar context returns reference to the resulting
110 list.
111
112 # note the alignment
113
114 $pager->set_current(10);
115 print $pager->list; # 6 7 8 9 [10] 11 12 13 14 15
116 $pager->set_current(33);
117 print $pager->list; # 28 29 30 31 32 [33] 34 35 36 37 38
118
119 SEE ALSO
120 Data::Page
121
122 BUGS
123 What BUGS?
124
125 AUTHOR
126 Vidul Nikolaev Petrov, [email protected]
127
128 COPYRIGHT
129 This program is free software; you can redistribute it and/or modify it
130 under the same terms as Perl itself.
131
132 The full text of the license can be found in the LICENSE file included
133 with this module.
134