File Coverage

lib/Template/Plugin/Pagination.pm
Criterion Covered Total %
statement 13 13 100.0
branch 1 2 50.0
condition 5 7 71.4
subroutine 4 4 100.0
pod 1 1 100.0
total 24 27 88.8


line stmt bran cond sub pod time code
1             package Template::Plugin::Pagination;
2              
3             $VERSION = '0.90';
4              
5 1     1   110918 use strict;
  1         3  
  1         247  
6 1     1   1113 use Data::Paginated;
  1         19624  
  1         18  
7 1     1   55 use base 'Template::Plugin';
  1         2  
  1         1482  
8              
9             =head1 NAME
10              
11             Template::Plugin::Pagination - a plugin to help paginate pages of results
12              
13             =head1 SYNOPSIS
14              
15             [% USE page = Pagination(items, current_page, entries_per_page) %]
16              
17             [% FOREACH item IN page.page_data; ...; DONE %]
18              
19             First page: [% page.first_page %]
20             Prev page: [% page.previous_page %]
21             Next page: [% page.next_page %]
22             Last page: [% page.last_page %]
23              
24             =head1 DESCRIPTION
25              
26             This plugin helps you construct pages that include subsets of data from
27             a list, such as search results which you'll paginated in groups of 10.
28              
29             It's based heavily on Template::Plugin::Page, which you should see for a
30             detailed example of to use this. (That module is a thin wrapper around
31             Data::Page, whereas this one is a wrapper around Data::Paginated, which
32             is Data::Page + Data::Pageset + some extras).
33              
34             =head1 METHODS
35              
36             =head2 new
37              
38             This is the constructor. It has one mandatory arguments: the list of items
39             we're working with. You can also pass the page number you're currently
40             working with which will otherwise default to 1) and the number of entries
41             there will be on each page (which defaults to 10).
42              
43             =cut
44              
45             sub new {
46 5     5 1 31510 my ($proto, $context, $list, $current, $per_page) = @_;
47 5   33     41 my $class = ref($proto) || $proto;
48              
49 5 50       19 ($list, $per_page, $current) = ($context, $list, $per_page)
50             unless ref($context) eq 'Template::Context';
51              
52 5   100     62 return Data::Paginated->new({
      100        
53             entries => $list,
54             entries_per_page => $per_page || 10,
55             current_page => $current || 1,
56             });
57             }
58              
59             =head1 Pageset Methods
60              
61             You now have available all the methods from Data::Page, Data::Pageset
62             and Data::Paginated, including:
63              
64             =over 4
65              
66             =item page_data
67              
68             =item first_page
69              
70             =item last_page
71              
72             =item next_page
73              
74             =item previous_page
75              
76             =back
77              
78             See their manual pages for details.
79              
80             =head1 AUTHOR
81              
82             Tony Bowden,
83              
84             =head1 BUGS and QUERIES
85              
86             Please direct all correspondence regarding this module to:
87             bug-Template-Plugin-Pagination@rt.cpan.org
88              
89             =head1 SEE ALSO
90              
91             L, L, L, L
92              
93             =head1 COPYRIGHT
94              
95             Copyright (C) 2004-2006 Tony Bowden. All rights reserved.
96              
97             This module is free software; you can redistribute it and/or modify it
98             under the same terms as Perl itself
99              
100             =cut