File Coverage

blib/lib/Teng/Plugin/SearchBySQLAbstractMore/Pager.pm
Criterion Covered Total %
statement 34 34 100.0
branch 5 6 83.3
condition n/a
subroutine 9 9 100.0
pod 1 2 50.0
total 49 51 96.0


line stmt bran cond sub pod time code
1             package Teng::Plugin::SearchBySQLAbstractMore::Pager;
2              
3 9     9   6528 use strict;
  9         24  
  9         273  
4 9     9   48 use warnings;
  9         19  
  9         248  
5 9     9   44 use utf8;
  9         21  
  9         57  
6 9     9   233 use Carp ();
  9         20  
  9         185  
7 9     9   43 use Teng::Iterator;
  9         22  
  9         241  
8 9     9   4152 use Data::Page::NoTotalEntries;
  9         5440  
  9         252  
9 9     9   558 use Teng::Plugin::SearchBySQLAbstractMore ();
  9         24  
  9         2951  
10              
11             our @EXPORT = qw/search_by_sql_abstract_more_with_pager/;
12              
13             sub init {
14 10     10 0 781 $_[1]->Teng::Plugin::SearchBySQLAbstractMore::_init();
15             }
16              
17             # work around
18             push @EXPORT, qw/sql_abstract_more_instance/;
19             *sql_abstract_more_instance = \&Teng::Plugin::SearchBySQLAbstractMore::sql_abstract_more_instance;
20              
21             sub search_by_sql_abstract_more_with_pager {
22 6     6 1 65161 my ($self, $table_name, $where, $_opt) = @_;
23 6         27 ($table_name, my($args, $rows, $page)) = Teng::Plugin::SearchBySQLAbstractMore::_arrange_args($table_name, $where, $_opt);
24              
25 6 50       25 my $table = $self->schema->get_table($table_name) or Carp::croak("No such table $table_name");
26 6         81 $args->{-limit} += 1;
27 6         17 my ($sql, @binds) = $self->sql_abstract_more_instance->select(%$args);
28              
29 6         6579 my $sth = $self->execute($sql, \@binds);
30 6         1673 my $ret = [ Teng::Iterator->new(
31             teng => $self,
32             sth => $sth,
33             sql => $sql,
34             row_class => $self->schema->get_row_class($table_name),
35             table_name => $table_name,
36             suppress_object_creation => $self->suppress_row_objects,
37             )->all];
38              
39 6 100       1659 my $has_next = ( $rows + 1 == scalar(@$ret) ) ? 1 : 0;
40 6 100       22 if ($has_next) {
41 3         6 pop @$ret;
42             }
43              
44 6         32 my $pager = Data::Page::NoTotalEntries->new
45             (
46             entries_per_page => $rows,
47             current_page => $page,
48             has_next => $has_next,
49             entries_on_this_page => scalar(@$ret),
50             );
51 6         200 return ($ret, $pager);
52             }
53              
54             =pod
55              
56             =head1 NAME
57              
58             Teng::Plugin::SearchBySQLAbstractMore::Pager - pager plugin using SQL::AbstractMore as Query Builder for Teng
59              
60             =head1 SYNOPSIS
61              
62             see Teng::Plugin::SearchBySQLAbstractMore
63              
64             =head1 METHODS
65              
66             =head2 search_by_sql_abstract_more_with_pager
67              
68             C<search_by_sql_abstract_more> with paging feature.
69             additional parameter can be taken, C<page> and C<rows>.
70              
71             =head1 AUTHOR
72              
73             Ktat, C<< <ktat at cpan.org> >>
74              
75             =head1 BUGS
76              
77             Please report any bugs or feature requests to C<bug-teng-plugin-searchbysqlabstractmore at rt.cpan.org>, or through
78             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Teng-Plugin-SearchBySQLAbstractMore>. I will be notified, and then you'll
79             automatically be notified of progress on your bug as I make changes.
80              
81             =head1 SUPPORT
82              
83             You can find documentation for this module with the perldoc command.
84              
85             perldoc Teng::Plugin::SearchBySQLAbstractMore
86              
87             You can also look for information at:
88              
89             =over 4
90              
91             =item * RT: CPAN's request tracker
92              
93             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Teng-Plugin-SearchBySQLAbstractMore>
94              
95             =item * AnnoCPAN: Annotated CPAN documentation
96              
97             L<http://annocpan.org/dist/Teng-Plugin-SearchBySQLAbstractMore>
98              
99             =item * CPAN Ratings
100              
101             L<http://cpanratings.perl.org/d/Teng-Plugin-SearchBySQLAbstractMore>
102              
103             =item * Search CPAN
104              
105             L<http://search.cpan.org/dist/Teng-Plugin-SearchBySQLAbstractMore/>
106              
107             =back
108              
109              
110             =head1 ACKNOWLEDGEMENTS
111              
112              
113             =head1 LICENSE AND COPYRIGHT
114              
115             Copyright 2012 Ktat.
116              
117             This program is free software; you can redistribute it and/or modify it
118             under the terms of either: the GNU General Public License as published
119             by the Free Software Foundation; or the Artistic License.
120              
121             See http://dev.perl.org/licenses/ for more information.
122              
123              
124             =cut
125              
126             1; # End of Teng::Plugin::SearchBySQLAbstractMore::Pager