File Coverage

blib/lib/Bootylicious/ArticleIteratorFinder.pm
Criterion Covered Total %
statement 29 29 100.0
branch 7 8 87.5
condition n/a
subroutine 8 8 100.0
pod 1 2 50.0
total 45 47 95.7


line stmt bran cond sub pod time code
1             package Bootylicious::ArticleIteratorFinder;
2              
3 5     5   789 use strict;
  5         9  
  5         191  
4 5     5   23 use warnings;
  5         6  
  5         148  
5              
6 5     5   23 use base 'Mojo::Base';
  5         6  
  5         465  
7              
8             __PACKAGE__->attr('iterator');
9              
10 5     5   2128 use Bootylicious::ArticleWithPager;
  5         13  
  5         38  
11 5     5   640 use Bootylicious::IteratorSearchable;
  5         7  
  5         32  
12              
13             sub new {
14 11     11 1 95 my $self = shift->SUPER::new(@_);
15              
16 11 50       122 Carp::croak q/Iterator is a required parameter/ unless $self->iterator;
17              
18 11         108 return $self;
19             }
20              
21             sub find {
22 11     11 0 17 my $self = shift;
23 11         34 my ($year, $month, $name) = @_;
24              
25 11         33 my $iterator = Bootylicious::IteratorSearchable->new($self->iterator);
26              
27             return $iterator->find_first(
28             sub {
29 16     16   75 my ($iterator, $elem) = @_;
30              
31 16 100       77 return unless $elem->created->year == $year;
32 15 100       1096 return unless $elem->created->month == $month;
33 10 100       454 return unless $elem->name eq $name;
34              
35 9         42 my $prev = $iterator->take_prev;
36 9         32 my $next = $iterator->take_next;
37              
38 9         91 return Bootylicious::ArticleWithPager->new(
39             $elem,
40             prev => $prev,
41             next => $next
42             );
43             }
44 11         146 );
45             }
46              
47             1;