README
1This is Perl module Data::Page::NoTotalEntries.
2
3INSTALLATION
4
5Data::Page::NoTotalEntries installation is straightforward. If your CPAN shell is set up,
6you should just be able to do
7
8% cpan Data::Page::NoTotalEntries
9
10Download it, unpack it, then build it as per the usual:
11
12% perl Makefile.PL
13% make && make test
14
15Then install it:
16
17% make install
18
19DOCUMENTATION
20
21Data::Page::NoTotalEntries documentation is available as in POD. So you can do:
22
23% perldoc Data::Page::NoTotalEntries
24
README.pod
1package Data::Page::NoTotalEntries;
2use strict;
3use warnings;
4use 5.008001;
5our $VERSION = '0.02';
6use Class::Accessor::Lite 0.05 (
7 new => 1,
8 rw => [qw/has_next entries_per_page current_page entries_on_this_page/]
9);
10
11sub next_page {
12 my $self = shift;
13 $self->has_next ? $self->current_page + 1 : undef;
14}
15
16sub previous_page { goto &prev_page }
17sub prev_page {
18 my $self = shift;
19 $self->current_page > 1 ? $self->current_page - 1 : undef;
20}
21
22sub first {
23 my $self = shift;
24 Carp::croak("'first' method requires 'entries_on_this_page'") unless defined $self->entries_on_this_page;
25
26 if ( $self->entries_on_this_page == 0 ) {
27 return 0;
28 }
29 else {
30 return ( ( $self->current_page - 1 ) * $self->entries_per_page ) + 1;
31 }
32}
33
34sub last {
35 my $self = shift;
36 Carp::croak("'last' method requires 'entries_on_this_page'") unless defined $self->entries_on_this_page;
37
38 if ( !$self->has_next ) {
39 if ($self->entries_on_this_page == 0) {
40 return 0;
41 } else {
42 return $self->first + $self->entries_on_this_page - 1;
43 }
44 }
45 else {
46 return ( $self->current_page * $self->entries_per_page );
47 }
48}
49
501;
51__END__
52
53=encoding utf8
54
55=head1 NAME
56
57Data::Page::NoTotalEntries - help when paging through sets of results without total entries
58
59=head1 SYNOPSIS
60
61 use Data::Page::NoTotalEntries;
62
63=head1 DESCRIPTION
64
65Data::Page::NoTotalEntries is a generic pager object, so it's very similar with L<Data::Page>.
66But so Data::Page::NoTotalEntries doesn't support C<< $pager->total_entries >> and other some methods.
67
68In sometime, I don't want to count total entries, because counting total entries from database are very slow.
69
70=head1 METHODS
71
72=over 4
73
74=item my $pager = Data::Page::NoTotalEntries->new(%args);
75
76Create new instance of Data::Page::NoTotalEntries.
77You can initialize attributes at constructor with C<< %args >>.
78
79=item $pager->next_page()
80
81This method returns the next page number, if one exists. Otherwise
82it returns undefined:
83
84 if ($page->next_page) {
85 print "Next page number: ", $page->next_page, "\n";
86 }
87
88=item $pager->previous_page()
89
90This method returns the previous page number, if one exists. Otherwise
91it returns undefined:
92
93 if ($page->previous_page) {
94 print "Previous page number: ", $page->previous_page, "\n";
95 }
96
97=item $pager->prev_page()
98
99This is a alias for C<< $pager->previous_page() >>
100
101=item $pager->first()
102
103This method returns the number of the first entry on the current page.
104
105=item $pager->last()
106
107This method returns the number of the last entry on the current page.
108
109=back
110
111=head1 ATTRIBUTES
112
113=over 4
114
115=item has_next: Bool
116
117Does this page has a next page?
118
119=item entries_per_page: Int
120
121The number of entries in each page.
122
123=item current_page : Int
124
125This attribute is the current page number:
126
127=item entries_on_this_page: Int
128
129This attribute is the number of entries on the current page
130
131=back
132
133=head1 AUTHOR
134
135Tokuhiro Matsuno E<lt>tokuhirom AAJKLFJEF GMAIL COME<gt>
136
137=head1 SEE ALSO
138
139L<Data::Page> is a pager component but requires the number of total entries.
140
141=head1 LICENSE
142
143Copyright (C) Tokuhiro Matsuno
144
145This library is free software; you can redistribute it and/or modify
146it under the same terms as Perl itself.
147
148=cut
149