File Coverage

blib/lib/RDF/Flow/Pipeline.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1 1     1   1170 use strict;
  1         2  
  1         31  
2 1     1   6 use warnings;
  1         2  
  1         48  
3             package RDF::Flow::Pipeline;
4             {
5             $RDF::Flow::Pipeline::VERSION = '0.178';
6             }
7             #ABSTRACT: Pipelines multiple sources
8              
9 1     1   5 use Log::Contextual::WarnLogger;
  1         2  
  1         37  
10 1         7 use Log::Contextual qw(:log), -default_logger
11 1     1   5 => Log::Contextual::WarnLogger->new({ env_prefix => __PACKAGE__ });
  1         2  
12              
13 1     1   1235 use parent 'RDF::Flow::Source';
  1         2  
  1         5  
14             use RDF::Flow::Source qw(:util);
15              
16             sub new {
17             my $class = shift;
18             my ($inputs, $args) = sourcelist_args( @_ );
19              
20             my $self = bless {
21             inputs => $inputs,
22             name => ($args->{name} || 'anonymous pipeline'),
23             }, $class;
24              
25             $self->match( $args->{match} );
26              
27             return $self;
28             }
29              
30             sub retrieve_rdf {
31             my ($self, $env) = @_;
32              
33             foreach my $src ( $self->inputs ) {
34             my $rdf = $src->retrieve( $env );
35             $env->{'rdflow.data'} = $rdf;
36             last if empty_rdf( $rdf );
37             }
38              
39             $env->{'rdflow.data'};
40             }
41              
42             # experimental
43             sub _graphviz_edgeattr {
44             my ($self,$n) = @_;
45             return (label => sprintf("%d.",$n));
46             }
47              
48             1;
49              
50              
51             __END__
52             =pod
53              
54             =head1 NAME
55              
56             RDF::Flow::Pipeline - Pipelines multiple sources
57              
58             =head1 VERSION
59              
60             version 0.178
61              
62             =head1 SYNOPSIS
63              
64             use RDF::Flow::Pipeline;
65              
66             $src = pipeline( @sources ); # shortcut
67              
68             $src = RDF::Flow::Pipeline->new( @sources ); # explicit
69              
70             $rdf = $src->retrieve( $env );
71             $rdf == $env->{'rdflow.data'}; # always true
72              
73             # pipeline as conditional: if $s1 has content then union of $s1 and $s2
74             use RDF::Flow qw(pipeline union previous);
75             pipeline( $s1, union( previous, $s2 ) );
76             $s1->pipe_to( union( previous, $s2) ); # equivalent
77              
78             =head1 DESCRIPTION
79              
80             This L<RDF::Flow::Source> wraps other sources as pipeline. Sources are
81             retrieved one after another. The response of each source is saved in the
82             environment variable C<rdflow.data> which is accesible to the next source.
83             The pipeline is aborted without error if C<rdflow.data> has not content, so
84             you can also use a pipleline as conditional branch. To pipe one source after
85             another, you can also use a source's C<pipe_to> method.
86              
87             The module L<RDF::Flow> exports functions C<pipeline> and C<previous> on
88             request.
89              
90             =head1 SEE ALSO
91              
92             L<RDF::Flow::Cascade>, L<RDF::Flow::Union>
93              
94             =head1 AUTHOR
95              
96             Jakob Voß <voss@gbv.de>
97              
98             =head1 COPYRIGHT AND LICENSE
99              
100             This software is copyright (c) 2011 by Jakob Voß.
101              
102             This is free software; you can redistribute it and/or modify it under
103             the same terms as the Perl 5 programming language system itself.
104              
105             =cut
106