Bryar::Collector - Determine which documents to show


Bryar documentation Contained in the Bryar distribution.

Index


Code Index:

NAME

Top

Bryar::Collector - Determine which documents to show

SYNOPSIS

Top

	$self->collect(...);
	$self->collect_current(...);

DESCRIPTION

Top

This class is called upon to pick out the right number of the relevant blog documents, so that they can be shipped off to the renderer.

METHODS

Top

collect

    $self->collect

Return the right number of documents, based on the arguments passed in by the user.

collect_current

    $self->collect_current

Return the latest set of documents.

TODO: make this configurable as well, to return X number or all posts X units of time back. =cut

LICENSE

Top

This module is free software, and may be distributed under the same terms as Perl itself.

AUTHOR

Top

Copyright (C) 2003, Simon Cozens simon@kasei.com

SEE ALSO

Top


Bryar documentation Contained in the Bryar distribution.
package Bryar::Collector;
use 5.006;
use strict;
use warnings;
use Carp;
our $VERSION = '1.0';


sub collect {
    my $class = shift;
    my $config = shift;
    croak "Must pass in a Bryar::Config object" unless UNIVERSAL::isa($config, "Bryar::Config");
    my %args = @_;
    $config->{arguments} = \%args;
    delete $args{format}; # Not interesting
    if (! keys %args) { # Default operation
        return $class->collect_current($config);
    }
    my @docs = sort {$b->epoch <=> $a->epoch }
        $config->source->search($config, %args);
    return @docs;
}


sub collect_current {
    my $self = shift;
    my $config = shift;
    croak "Must pass in a Bryar::Config object" unless UNIVERSAL::isa($config, "Bryar::Config");

    my @list = sort { $b->epoch <=> $a->epoch } $config->source->search(
        $config,
        limit => $config->recent()
    );
    return @list;
}


1;