| 1 | package Mongol::Roles::Pagination; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use Mongol::Models::Page; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use constant { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | PAGINATION_DEFAULT_START => 0, | |||||||||||
| 9 | PAGINATION_DEFAULT_ROWS => 10, | ||||||||||||
| 10 | 1 | }; | |||||||||||
| 11 | |||||||||||||
| 12 | 1 | requires 'count'; | |||||||||||
| 13 | 1 | requires 'find'; | |||||||||||
| 14 | |||||||||||||
| 15 | 0 | ▶ | sub paginate { | ||||||||||
|
Subroutine
paginate: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 16 | 0 | my ( $class, $query, $start, $rows, $options ) = @_; | |||||||||||
| 17 | |||||||||||||
| 18 | 0 | ▶ | $options ||= {}; | ||||||||||
|
Condition0%0/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table0%0/2
A
A= $options
| |||||||||||||
| 19 | 0 | ▶ | $options->{skip} = $start || PAGINATION_DEFAULT_START; | ||||||||||
|
Condition0%0/2
$start || 0
MC/DC0%0/1
$start || 0
$start
Truth table0%0/2
A
A= $start
| |||||||||||||
| 20 | 0 | ▶ | $options->{limit} = $rows || PAGINATION_DEFAULT_ROWS; | ||||||||||
|
Condition0%0/2
$rows || 10
MC/DC0%0/1
$rows || 10
$rows
Truth table0%0/2
A
A= $rows
| |||||||||||||
| 21 | |||||||||||||
| 22 | 0 | my $total = $class->count( $query ); | |||||||||||
| 23 | 0 | my @items = $class->find( $query, $options ) | |||||||||||
| 24 | ->all(); | ||||||||||||
| 25 | |||||||||||||
| 26 | my $page = Mongol::Models::Page->new( | ||||||||||||
| 27 | { | ||||||||||||
| 28 | items => \@items, | ||||||||||||
| 29 | total => $total, | ||||||||||||
| 30 | start => $options->{skip}, | ||||||||||||
| 31 | rows => $options->{limit}, | ||||||||||||
| 32 | } | ||||||||||||
| 33 | 0 | ); | |||||||||||
| 34 | |||||||||||||
| 35 | 0 | return $page; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 1 | ▶ | no Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | |||||||||||||
| 40 | 1 | 1; | |||||||||||
| 41 | |||||||||||||
| 42 | __END__ | ||||||||||||