File Coverage

lib/DBIx/Skinny/Pager/Logic/PlusOne.pm
Criterion Covered Total %
statement 29 29 100.0
branch 3 4 75.0
condition 2 2 100.0
subroutine 7 7 100.0
pod 0 3 0.0
total 41 45 91.1


line stmt bran cond sub pod time code
1             package DBIx::Skinny::Pager::Logic::PlusOne;
2 5     5   53563 use strict;
  5         11  
  5         166  
3 5     5   25 use warnings;
  5         8  
  5         139  
4 5     5   25 use base qw(DBIx::Skinny::Pager);
  5         8  
  5         1437  
5 5     5   2941 use DBIx::Skinny::Pager::Page::PlusOne;
  5         11  
  5         61  
6              
7             sub as_sql {
8 4     4 0 387 my $self = shift;
9 4         11 my $original_limit = $self->limit;
10 4         21 $self->limit($original_limit + 1);
11 4         67 my $result = $self->SUPER::as_sql;
12 4         603 $self->limit($original_limit);
13 4         26 return $result;
14             }
15              
16             sub pager_class {
17 3     3 0 9 "DBIx::Skinny::Pager::Page::PlusOne";
18             }
19              
20             sub get_total_entries {
21 3     3 0 5 my ($self, $iter) = @_;
22 3         3 my $has_next;
23             # XXX: iterがno cacheの場合はうまくいかないが、
24             # ここはPagerで拡張したretrieve以外から呼ばれることは想定されていないので
25             # 大丈夫な気もする
26 3 100       8 if ( $iter->count > $self->limit ) {
27 2         564 pop @{$iter->{_rows_cache}};
  2         4  
28             # for date2itr
29 2 50       10 if ( $iter->{data} ) {
30 2         3 pop @{$iter->{data}};
  2         3  
31             }
32 2         3 $has_next++;
33             }
34 3   100     305 return $self->offset + $self->limit + ( $has_next || 0 );
35             }
36              
37             1;
38             __END__