File Coverage

blib/lib/Bryar/Collector.pm
Criterion Covered Total %
statement 12 29 41.3
branch 0 6 0.0
condition n/a
subroutine 4 6 66.6
pod 2 2 100.0
total 18 43 41.8


line stmt bran cond sub pod time code
1             package Bryar::Collector;
2 4     4   783 use 5.006;
  4         15  
  4         285  
3 4     4   23 use strict;
  4         98  
  4         146  
4 4     4   21 use warnings;
  4         10  
  4         122  
5 4     4   21 use Carp;
  4         7  
  4         1395  
6             our $VERSION = '1.0';
7              
8             =head1 NAME
9              
10             Bryar::Collector - Determine which documents to show
11              
12             =head1 SYNOPSIS
13              
14             $self->collect(...);
15             $self->collect_current(...);
16              
17             =head1 DESCRIPTION
18              
19             This class is called upon to pick out the right number of the relevant
20             blog documents, so that they can be shipped off to the renderer.
21              
22             =head1 METHODS
23              
24             =head2 collect
25              
26             $self->collect
27              
28             Return the right number of documents, based on the arguments passed in
29             by the user.
30              
31             =cut
32              
33              
34             sub collect {
35 0     0 1   my $class = shift;
36 0           my $config = shift;
37 0 0         croak "Must pass in a Bryar::Config object" unless UNIVERSAL::isa($config, "Bryar::Config");
38 0           my %args = @_;
39 0           $config->{arguments} = \%args;
40 0           delete $args{format}; # Not interesting
41 0 0         if (! keys %args) { # Default operation
42 0           return $class->collect_current($config);
43             }
44 0           my @docs = sort {$b->epoch <=> $a->epoch }
  0            
45             $config->source->search($config, %args);
46 0           return @docs;
47             }
48              
49              
50             =head2 collect_current
51              
52             $self->collect_current
53              
54             Return the latest set of documents.
55              
56             TODO: make this configurable as well, to return X number or all posts X units of time back.
57             =cut
58              
59             sub collect_current {
60 0     0 1   my $self = shift;
61 0           my $config = shift;
62 0 0         croak "Must pass in a Bryar::Config object" unless UNIVERSAL::isa($config, "Bryar::Config");
63              
64 0           my @list = sort { $b->epoch <=> $a->epoch } $config->source->search(
  0            
65             $config,
66             limit => $config->recent()
67             );
68 0           return @list;
69             }
70              
71              
72             =head1 LICENSE
73              
74             This module is free software, and may be distributed under the same
75             terms as Perl itself.
76              
77              
78             =head1 AUTHOR
79              
80             Copyright (C) 2003, Simon Cozens C
81              
82             =head1 SEE ALSO
83              
84             =cut
85              
86             1;