| Babble documentation | Contained in the Babble distribution. |
Babble::Document::Collection - Babble document collector class
Babble::Document::Collection is a meta-class. One, that's sole purpose is to collect Babble::Document objects, and group them together with a little meta-info about them.
The author of this collection
The subject of the collection.
The title of the collection.
A unique ID for the collection, usually a hyperlink to the source homepage.
A link to the source of this collection (for example, to an RSS feed).
The creation date of this version of the collection.
A brief description of the collection
The name of the collection. Usually used for subscription lists in the templates. This does not come from the feed, as the others. It must be specified at object creation time. Defaults to author's value if undefined, or title's, if author is undefined too.
The image associated with the collection. It is stored as a HASH reference, containing the following keys:
The URL to the image. (Mandatory)
Title of the image (to be used in ALT attributes or the like)
An image link - where the image points to. (Mandatory)
Width of the image.
Height of the image.
Creates a new, empty Babble::Document::Collection object. All the properties mentioned above are recognised as paramaters.
To add documents to the collection, simply push them to
@{$collection->{documents}}.
Given a list of filters (see Babble::Document::search for a specification of filters) in an arrayref, returns all the documents that match the specified criteria. If no matches are found, returns an empty array.
Return all entries (the lowest level entries) as an array.
Sort all the elements in an aggregation by date, and return the sorted array of items.
Gergely Nagy, algernon@bonehunter.rulez.org
Bugs should be reported at http://bugs.bonehunter.rulez.org/babble.
Babble, Babble::Document
| Babble documentation | Contained in the Babble distribution. |
## Babble/Document/Collection.pm ## Copyright (C) 2004 Gergely Nagy <algernon@bonehunter.rulez.org> ## ## This file is part of Babble. ## ## Babble is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; version 2 dated June, 1991. ## ## Babble is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package Babble::Document::Collection; use strict; use Babble::Document;
sub new { my ($type, %params) = @_; my $self = bless { author => $params{author}, subject => $params{subject}, title => $params{title}, id => $params{id}, link => $params{link}, date => $params{date}, content => $params{content}, name => $params{name} || $params{author} || $params{title}, image => $params{image} || {}, documents => [] }, $type; return $self; }
sub search ($;$) { my ($self, $filters, $params) = @_; my @results; foreach my $doc (@{$self->{documents}}) { my @subres = $doc->search ($filters); push (@results, @subres) if @subres; } return @results; }
sub all () { my ($self) = @_; my @all; foreach my $doc (@{$self->{documents}}) { push (@all, $doc->all ()); } return @all; }
sub sort (;$) { my ($self, $params) = @_; my @sorted = sort { $b->date_iso cmp $a->date_iso } $self->all (); return @sorted; }
1; # arch-tag: 5ac2ff9a-3c8b-4fa7-9b40-33b7e5270eff