-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
302 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use strict; | ||
use warnings; | ||
package RDF::Light::Source::Cascade; | ||
|
||
use parent 'RDF::Light::Source'; | ||
use Scalar::Util 'blessed'; | ||
use Carp 'croak'; | ||
|
||
our @EXPORT = qw(cascade); | ||
|
||
sub new { | ||
my $class = shift; | ||
bless [ map { RDF::Light::Source::source($_) } @_ ], $class; | ||
} | ||
|
||
sub retrieve { | ||
my ($self, $env) = @_; | ||
|
||
foreach my $src ( @$self ) { | ||
my $rdf = $src->retrieve( $env ); # TODO: failsafe mode? | ||
|
||
next unless defined $rdf; | ||
if ( blessed $rdf and $rdf->isa('RDF::Trine::Model') ) { | ||
return $rdf if $rdf->size > 0; | ||
} elsif ( blessed $rdf and $rdf->isa('RDF::Trine::Iterator') ) { | ||
return $rdf if $rdf->peek; | ||
} else { | ||
# TODO: croak or warn | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
sub cascade { RDF::Light::Source::Cascade->new(@_) } | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 DESCRIPTION | ||
This L<RDF::Light::Source> returns the first non-empty response of a given | ||
sequence of sources. It exports the function 'cascade' as constructor shortcut. | ||
=head1 SYNOPSIS | ||
use RDF::Light::Source::Cascade; | ||
$src = cascade(@sources); # shortcut | ||
$src = RDF::Light::Source::Cascade->new( @sources ); # explicit | ||
$rdf = $src->retrieve( $env ); | ||
=head2 SEE ALSO | ||
L<RDF::Light::Source::Union> | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use strict; | ||
use warnings; | ||
package RDF::Light::Source::Union; | ||
|
||
use parent 'RDF::Light::Source'; | ||
use Carp (); | ||
|
||
our @EXPORT = qw(union); | ||
|
||
sub new { | ||
my $class = shift; | ||
bless [ map { RDF::Light::Source::source($_) } @_ ], $class; | ||
} | ||
|
||
sub retrieve { # TODO: try/catch errors? | ||
my ($self, $env) = @_; | ||
|
||
my $result; | ||
|
||
if ( @$self == 1 ) { | ||
$result = $self->[0]->retrieve( $env ); | ||
} elsif( @$self > 1 ) { | ||
$result = RDF::Trine::Model->temporary_model; | ||
foreach my $src ( @$self ) { # TODO: parallel processing? | ||
my $rdf = $src->retrieve( $env ); | ||
next unless defined $rdf; | ||
$rdf = $rdf->as_stream unless $rdf->isa('RDF::Trine::Iterator'); | ||
$result->add_iterator( $rdf ); | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
sub union { RDF::Light::Source::Union->new(@_) } | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 DESCRIPTION | ||
This L<RDF::Light::Source> returns the union of responses of a set of sources. | ||
It exports the function 'union' as constructor shortcut. | ||
=head1 SYNOPSIS | ||
use RDF::Light::Source::Union; | ||
$src = union(@sources); # shortcut | ||
$src = RDF::Light::Source::Union->new( @sources ); # explicit | ||
$rdf = $src->retrieve( $env ); | ||
=head2 SEE ALSO | ||
L<RDF::Light::Source::Cascade> | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
use strict; | ||
use Test::More tests => 1; | ||
|
||
BEGIN { use_ok 'RDF::Light' } | ||
my @modules; | ||
|
||
BEGIN { @modules = qw( | ||
RDF::Light | ||
RDF::Light::Graph | ||
RDF::Light::Source | ||
RDF::Light::Source::Union | ||
RDF::Light::Source::Cascade | ||
); } | ||
|
||
use Test::More tests => scalar @modules; | ||
|
||
use_ok($_) for @modules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.