| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Bryar::DataSource::Multiplex; | 
| 2 | 1 |  |  | 1 |  | 23122 | use base qw(Bryar::DataSource::Base); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 174367 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | use warnings; | 
| 5 |  |  |  |  |  |  | use strict; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Bryar::DataSource::Multiplex - multiplex Bryar datasources | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 VERSION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | version 0.122 | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | $Id$ | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =cut | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | our $VERSION = '0.122'; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | This module implements the Bryar::DataSource interface.  It aggregates other | 
| 24 |  |  |  |  |  |  | datasources and provides sets of documents from all the multiplexed sources. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | It expects to find a config entry called "sources" containing a reference to an | 
| 27 |  |  |  |  |  |  | array of sub-configurations.  These elements are used as config data.  The | 
| 28 |  |  |  |  |  |  | class named in their "source" key has called methods relayed to it, with the | 
| 29 |  |  |  |  |  |  | rest of the element passed as the Bryar configuration data.  The elements must | 
| 30 |  |  |  |  |  |  | also have an "id" entry uniquely identifying the datasource. | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head1 METHODS | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =cut | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =head2 search | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | (see: L) | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | If the "subblog" parameter has been passed, only the datasource with the given | 
| 41 |  |  |  |  |  |  | id is searched. | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | =cut | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub search { | 
| 46 |  |  |  |  |  |  | my ($self, $config, %params) = @_; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | if ($params{subblog}) { | 
| 49 |  |  |  |  |  |  | my ($source) = grep { $_->{id} eq $params{subblog} } @{$config->{sources}}; | 
| 50 |  |  |  |  |  |  | return $source->{source}->search($source, %params); | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | if ($params{id} and $params{id} =~ /:/) { | 
| 54 |  |  |  |  |  |  | my ($sourceid, $docid) = $params{id} =~ /(.*?):(.*)/; | 
| 55 |  |  |  |  |  |  | my ($source) = grep { $_->{id} eq $sourceid } @{$config->{sources}}; | 
| 56 |  |  |  |  |  |  | ## no critic (ProhibitStringyEval) | 
| 57 |  |  |  |  |  |  | eval "require $source->{source};"; | 
| 58 |  |  |  |  |  |  | ## use critic | 
| 59 |  |  |  |  |  |  | return $source->{source}->search($source, (%params, id => $docid)); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | my @documents; | 
| 63 |  |  |  |  |  |  | for my $source (@{$config->{sources}}) { | 
| 64 |  |  |  |  |  |  | ## no critic (ProhibitStringyEval) | 
| 65 |  |  |  |  |  |  | eval "require $source->{source};"; | 
| 66 |  |  |  |  |  |  | ## use critic | 
| 67 |  |  |  |  |  |  | push @documents, | 
| 68 |  |  |  |  |  |  | map { $_->{id} = "$source->{id}:$_->{id}"; $_ } | 
| 69 |  |  |  |  |  |  | $source->{source}->search($source, %params); | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  | @documents = sort { $b->epoch <=> $a->epoch } @documents; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | return @documents[0 .. $params{limit} - 1] if $params{limit}; | 
| 74 |  |  |  |  |  |  | return @documents; | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head2 all_documents | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | (see: L) | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =cut | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub all_documents { | 
| 84 |  |  |  |  |  |  | my ($self, $config, %params) = @_; | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | my @documents; | 
| 87 |  |  |  |  |  |  | for my $source (@{$config->{sources}}) { | 
| 88 |  |  |  |  |  |  | ## no critic (ProhibitStringyEval) | 
| 89 |  |  |  |  |  |  | eval "require $source->{source};"; | 
| 90 |  |  |  |  |  |  | ## use critic | 
| 91 |  |  |  |  |  |  | push @documents, | 
| 92 |  |  |  |  |  |  | map { $_->{id} = "$source->{id}:$_->{id}"; $_ } | 
| 93 |  |  |  |  |  |  | $source->{source}->all_documents($source); | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | @documents = sort { $b->epoch <=> $a->epoch } @documents; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head1 AUTHOR | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | Ricardo Signes, C<<  >> | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head1 BUGS | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 106 |  |  |  |  |  |  | C, or through the web interface at | 
| 107 |  |  |  |  |  |  | L.  I will be notified, and then you'll automatically be | 
| 108 |  |  |  |  |  |  | notified of progress on your bug as I make changes. | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | Copyright 2004-2006 Ricardo Signes, All Rights Reserved. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 115 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =cut | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | 1; |