File Coverage

blib/lib/Bootylicious/ArticlePager.pm
Criterion Covered Total %
statement 42 43 97.6
branch 13 14 92.8
condition n/a
subroutine 9 9 100.0
pod 0 5 0.0
total 64 71 90.1


line stmt bran cond sub pod time code
1             package Bootylicious::ArticlePager;
2              
3 5     5   643 use strict;
  5         7  
  5         215  
4 5     5   25 use warnings;
  5         6  
  5         218  
5              
6 5     5   22 use base 'Mojo::Base';
  5         8  
  5         419  
7              
8 5     5   378 use Bootylicious::Timestamp;
  5         8  
  5         38  
9              
10             __PACKAGE__->attr('timestamp');
11             __PACKAGE__->attr(limit => 10);
12             __PACKAGE__->attr('iterator');
13              
14             sub prev {
15 6     6 0 13 my $self = shift;
16              
17 6         26 my $i = $self->iterator;
18              
19 6         42 my $first = $self->articles->first;
20              
21 6         24 $i->rewind;
22 6         27 while (my $article = $i->next) {
23 8 100       56 if ($article->created->epoch == $first->created->epoch) {
24 5         42 return $i->prev($self->limit)->last;
25             }
26             }
27              
28 1         2 return;
29             }
30              
31             sub prev_timestamp {
32 5     5 0 10540 my $self = shift;
33              
34 5         26 my $prev = $self->prev;
35 5 50       70 return '' unless $prev;
36              
37 0         0 return $prev->created->timestamp;
38             }
39              
40             sub next {
41 6     6 0 398 my $self = shift;
42              
43 6         19 my $i = $self->iterator;
44              
45 6         37 my $last = $self->articles->last;
46              
47 6         21 $i->rewind;
48 6         20 while (my $article = $i->next) {
49 12 100       32 last if $article->created->epoch == $last->created->epoch;
50             }
51              
52 6         50 return $i->next;
53             }
54              
55             sub next_timestamp {
56 5     5 0 534 my $self = shift;
57              
58 5         18 my $next = $self->next;
59 5 100       45 return '' unless $next;
60              
61 1         5 return $next->created->timestamp;
62             }
63              
64             sub articles {
65 31     31 0 872 my $self = shift;
66              
67 31 100       377 return $self->{articles} if $self->{articles};
68              
69 10         40 my $i = $self->iterator;
70              
71 10 100       78 if ($self->timestamp) {
72 1         7 while (my $article = $i->next) {
73             last
74 4 100       9 if $article->created->epoch
75             <= Bootylicious::Timestamp->new(timestamp => $self->timestamp)->epoch;
76             }
77             }
78              
79 10         82 $i->prev;
80              
81 10         36 return $self->{articles} = $i->next($self->limit);
82             }
83              
84             1;