| 1 | package DBIx::Skinny::Pager; | ||||||||||||
| 2 | |||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 7 | ▶ | use base 'DBIx::Skinny::SQL'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 7 | ▶ | use DBIx::Skinny::Pager::Page::Default; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 7 | ▶ | use DBIx::Skinny::Pager::ResultSet; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 7 | ▶ | use Class::Accessor::Lite; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 7 | our $VERSION = '0.11'; | |||||||||||
| 11 | |||||||||||||
| 12 | 7 | Class::Accessor::Lite->mk_accessors(qw/page/); | |||||||||||
| 13 | |||||||||||||
| 14 | 0 | ▶ | sub get_total_entries { | ||||||||||
|
Subroutine
get_total_entries: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 15 | 0 | die "please override"; | |||||||||||
| 16 | } | ||||||||||||
| 17 | |||||||||||||
| 18 | 3 | ▶ | sub pager_class { | ||||||||||
|
Subroutine
pager_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 19 | 3 | "DBIx::Skinny::Pager::Page::Default"; | |||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | 6 | ▶ | sub retrieve { | ||||||||||
|
Subroutine
retrieve: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||
| 23 | 6 | my $self = shift; | |||||||||||
| 24 | 6 | ▶ | Carp::croak("limit not found") unless defined($self->limit); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | 6 | ▶ | unless ( defined($self->offset) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 2 | ▶ | Carp::croak("limit or page not found") unless defined($self->page); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 2 | ▶ | $self->offset($self->limit * ( (int($self->page) || 1) - 1) ); | ||||||||||
|
Condition50%1/2
int $self->page || 1
MC/DC0%0/1
int $self->page || 1
int $self->page
Truth table50%1/2
A
A= int $self->page
| |||||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 6 | my $iter = $self->SUPER::retrieve(@_); | |||||||||||
| 31 | 6 | my $total_entries = $self->get_total_entries($iter); | |||||||||||
| 32 | 6 | my $pager = $self->pager_class->new($total_entries, $self->limit, ( $self->offset / $self->limit) + 1); | |||||||||||
| 33 | |||||||||||||
| 34 | 6 | ▶ | if ( wantarray ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 4 | return ( $iter, $pager ); | |||||||||||
| 36 | } else { | ||||||||||||
| 37 | 2 | return DBIx::Skinny::Pager::ResultSet->new( | |||||||||||
| 38 | iterator => $iter, | ||||||||||||
| 39 | pager => $pager, | ||||||||||||
| 40 | ); | ||||||||||||
| 41 | } | ||||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 7 | 1; | |||||||||||
| 45 | __END__ | ||||||||||||