File Coverage

blib/lib/RDF/Flow.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1 7     7   151579 use strict;
  7         17  
  7         256  
2 7     7   37 use warnings;
  7         12  
  7         453  
3             package RDF::Flow;
4             {
5             $RDF::Flow::VERSION = '0.178';
6             }
7             #ABSTRACT: RDF data flow pipeline
8              
9 7     7   3430 use RDF::Flow::Source qw(rdflow_uri);
  0            
  0            
10             use RDF::Flow::Union;
11             use RDF::Flow::Cascade;
12             use RDF::Flow::Pipeline;
13             use RDF::Flow::Cached;
14              
15             use base 'Exporter';
16             our @EXPORT = qw(rdflow);
17             our @EXPORT_OK = qw(rdflow cached union cascade pipeline previous rdflow_uri);
18             our %EXPORT_TAGS = (
19             all => [qw(rdflow cached union cascade pipeline previous)] );
20              
21             our $PREVIOUS = RDF::Flow::Source->new( sub { shift->{'rdflow.data'} } );
22              
23             sub rdflow { RDF::Flow::Source->new(@_) }
24             sub union { RDF::Flow::Union->new( @_ ) }
25             sub cascade { RDF::Flow::Cascade->new( @_ ) }
26             sub pipeline { RDF::Flow::Pipeline->new( @_ ) }
27             sub cached { RDF::Flow::Cached->new( @_ ); }
28              
29             sub previous { $RDF::Flow::PREVIOUS; }
30              
31             1;
32              
33              
34             __END__
35             =pod
36              
37             =head1 NAME
38              
39             RDF::Flow - RDF data flow pipeline
40              
41             =head1 VERSION
42              
43             version 0.178
44              
45             =head1 SYNOPSIS
46              
47             # define RDF sources (see RDF::Flow::Source)
48             $src = rdflow( "mydata.ttl", name => "RDF file as source" );
49             $src = rdflow( "mydirectory", name => "directory with RDF files as source" );
50             $src = rdflow( \&mysub, name => "code reference as source" );
51             $src = rdflow( $model, name => "RDF::Trine::Model as source" );
52              
53             # using a RDF::Trine::Model as source is equivalent to:
54             $src = RDF::Flow->new( sub {
55             my $env = shift;
56             my $uri = RDF::Flow::uri( $env );
57             return $model->bounded_description( RDF::Trine::iri( $uri ) );
58             } );
59              
60             # retrieve RDF data
61             $rdf = $src->retrieve( $uri );
62             $rdf = $src->retrieve( $env ); # uri constructed from $env
63              
64             # code reference as source (more detailed example)
65             $src = rdflow( sub {
66             my $uri = RDF::Flow::uri( $env );
67             my $model = RDF::Trine::Model->temporary_model;
68             add_some_statements( $uri, $model );
69             return $model;
70             });
71              
72             =head1 DESCRIPTION
73              
74             RDF::Flow provides a simple framework on top of L<RDF::Trine> to define and
75             connect RDF sources in data flow pipes. In a nutshell, a source is connected
76             to some data (possibly RDF but it could also wrap any other forms) and you
77             can retrieve RDF data from it, based on a request URI:
78              
79             +--------+
80             Request (URI)--->+ Source +-->Response (RDF)
81             +---+----+
82             ^
83             Data (possibly RDF)
84              
85             The base class to define RDF sources is L<RDF::Flow::Source>, so please have a
86             look at the documentation of this class. Multiple sources can be connected to
87             data flow networks: Predefined sources exist to combine sources
88             (L<RDF::Flow::Union>, L<RDF::Flow::Pipeline>, L<RDF::Flow::Cascade>), to access
89             LinkedData (L<RDF::Flow::LinkedData>), to cache requests
90             (L<RDF::Flow::Cached>), and for testing (L<RDF::Flow::Dummy>).
91              
92             =head1 EXPORTED FUNCTIONS
93              
94             By default this module only exports C<rdflow> as constructor shortcut.
95             Additional shortcut functions can be exported on request. The C<:all>
96             tag exports all functions.
97              
98             =over 4
99              
100             =item C<rdflow>
101              
102             Shortcut to create a new source with L<RDF::Flow::Source>.
103              
104             =item C<cached>
105              
106             Shortcut to create a new cached source with L<RDF::Flow::Cached>.
107              
108             =item C<cascade>
109              
110             Shortcut to create a new source cascade with L<RDF::Flow::Cascade>.
111              
112             =item C<pipeline>
113              
114             Shortcut to create a new source pipeline with L<RDF::Flow::Pipeline>.
115              
116             =item C<previous>
117              
118             A source that always returns C<rdflow.data> without modification.
119              
120             =item C<union>
121              
122             Shortcut to create a new union of sources with L<RDF::Flow::Union>.
123              
124             =back
125              
126             =head2 LOGGING
127              
128             RDF::Flow uses L<Log::Contextual> for logging. By default no logging messages
129             are created, unless you enable a logger. To simply see what's going on in
130             detail, enable a simple logger:
131              
132             use Log::Contextual::SimpleLogger;
133             use Log::Contextual qw( :log ),
134             -logger => Log::Contextual::SimpleLogger->new({ levels => [qw(trace)]});
135              
136             =head1 DEFINING NEW SOURCE TYPES
137              
138             Basically you must only derive from L<RDF::Flow::Source> and create the method
139             C<retrieve_rdf>:
140              
141             package MySource;
142             use parent 'RDF::Flow::Source';
143             use RDF::Flow::Source qw(:util); # if you need utilty functions
144              
145             sub retrieve_rdf {
146             my ($self, $env) = @_;
147             my $uri = $env->{'rdflow.uri'};
148              
149             # ... your logic here ...
150              
151             return $model;
152             }
153              
154             =head1 LIMITATIONS
155              
156             The current version of this module does not check for circular references if
157             you connect multiple sources. Maybe environment variable such as C<rdflow.depth>
158             or C<rdflow.stack> will be introduced. Surely performance can also be increased.
159              
160             =head1 SEE ALSO
161              
162             You can use this module together with L<Plack::Middleware::RDF::Flow> (available
163             at L<at github|https://github.com/nichtich/Plack-Middleware-RDF-Flow>) to create
164             Linked Data applications.
165              
166             There are some CPAN modules for general data flow processing, such as L<Flow>
167             and L<DataFlow>. As RDF::Flow is inspired by L<PSGI>, you should also have a
168             look at the PSGI toolkit L<Plack>. Some RDF sources can also be connected
169             with L<RDF::Trine::Model::Union> and L<RDF::Trine::Model::StatementFilter>.
170             More RDF-related Perl modules are collected at L<http://www.perlrdf.org/>.
171              
172             Research references on RDF pipelining can be found in the presentation "RDF
173             Data Pipelines for Semantic Data Federation", more elaborated and not connected
174             to this module: L<http://dbooth.org/2011/pipeline/>. Another framework for
175             RDF integration based on a pipe model is RDF Gears:
176             L<https://bitbucket.org/feliksik/rdfgears/>.
177              
178             =head1 AUTHOR
179              
180             Jakob Voß <voss@gbv.de>
181              
182             =head1 COPYRIGHT AND LICENSE
183              
184             This software is copyright (c) 2011 by Jakob Voß.
185              
186             This is free software; you can redistribute it and/or modify it under
187             the same terms as the Perl 5 programming language system itself.
188              
189             =cut
190