File Coverage

blib/lib/RDF/Trine/Store/LDF.pm
Criterion Covered Total %
statement 30 54 55.5
branch 0 2 0.0
condition n/a
subroutine 10 22 45.4
pod 10 10 100.0
total 50 88 56.8


line stmt bran cond sub pod time code
1             package RDF::Trine::Store::LDF;
2              
3 1     1   1289917 use strict;
  1         8  
  1         26  
4 1     1   4 use warnings;
  1         2  
  1         24  
5 1     1   4 no warnings 'redefine';
  1         2  
  1         27  
6 1     1   4 use feature qw(state);
  1         2  
  1         147  
7 1     1   5 use utf8;
  1         2  
  1         4  
8 1     1   31 use base qw(RDF::Trine::Store);
  1         2  
  1         72  
9              
10 1     1   5 use RDF::Trine::Store;
  1         1  
  1         33  
11 1     1   5 use RDF::Trine::Iterator;
  1         2  
  1         51  
12 1     1   402 use RDF::LDF;
  1         3  
  1         32  
13 1     1   7 use RDF::Trine::Error qw(:try);
  1         2  
  1         8  
14              
15             sub new {
16 0     0 1   my ($class,%opts) = @_;
17 0           my $ref = \%opts;
18 0           $ref->{ldf} = RDF::LDF->new( url => $ref->{url});
19              
20 0 0         return undef unless $ref->{ldf}->is_fragment_server;
21            
22 0           bless $ref , $class;
23             }
24              
25             sub _new_with_string {
26 0     0     my ($class, $cfg) = @_;
27 0           $class->new(url => $cfg);
28             }
29             sub _new_with_config {
30 0     0     my ($class,$cfg) = @_;
31 0           $class->new(url => $cfg->{url});
32             }
33              
34             sub get_statements {
35 0     0 1   my ($self,$subject,$predicate,$object,$context) = @_;
36              
37 0           my $sub = $self->{ldf}->get_statements($subject,$predicate,$object);
38 0           RDF::Trine::Iterator::Graph->new($sub);
39             }
40              
41             sub get_pattern {
42 0     0 1   my ($self,$bgp,$context) = @_;
43              
44 0           $self->{ldf}->get_pattern($bgp,$context);
45             }
46              
47             sub get_contexts {
48 0     0 1   undef;
49             }
50              
51             sub add_statement {
52 0     0 1   throw RDF::Trine::Error::UnimplementedError -text => "LDF add_statement support not implemented";
53             }
54              
55             sub remove_statement {
56 0     0 1   throw RDF::Trine::Error::UnimplementedError -text => "LDF remove_statement support not implemented";
57             }
58              
59             sub remove_statements {
60 0     0 1   throw RDF::Trine::Error::UnimplementedError -text => "LDF remove_statements support not implemented";
61             }
62              
63             sub count_statements {
64 0     0 1   my ($self,$subject,$predicate,$object,$context) = @_;
65              
66 0           my $it = $self->{ldf}->get_statements($subject,$predicate,$object);
67              
68 0           my ($triples,$info) = $it->();
69              
70 0           $info->{hydra_totalItems};
71             }
72              
73             sub size {
74 0     0 1   shift->count_statements;
75             }
76              
77             sub supports {
78 0     0 1   undef;
79             }
80              
81             1;
82              
83             =head1 NAME
84              
85             RDF::Trine::Store::LDF - RDF Store proxy for a Linked Data Fragment endpoint
86              
87             =head1 SYNOPSIS
88              
89             use RDF::Trine::Store::LDF;
90             use RDF::Trine::Store;
91              
92             my $store = RDF::Trine::Store->new_with_config({
93             storetype => 'LDF',
94             url => $url
95             });
96              
97             my $it = $store->get_statements();
98              
99             while (my $st = $it->next) {
100             # $st is a RDF::Trine::Statement
101             print "$st\n";
102             }
103              
104             # Or query the store with SPAQRL
105              
106             use RDF::Query;
107             my $model = RDF::Trine::Model->new($store);
108              
109             my $rdf_query = RDF::Query->new(<<EOF);
110             .
111             .
112             SPARQL
113             .
114             .
115             EOF
116              
117             my $iter = $rdf_query->execute($model);
118              
119             while (my $s = $iter->next) {
120             # $s is a RDF::Trine::VariableBinding
121             print $s->value . "\n";
122             }
123              
124             =head1 DESCRIPTION
125              
126             RDF::Trine::Store::LDF provides a RDF::Trine::Store API to interact with a remote
127             Linked Data Fragment endpoint. For details see: <http://linkeddatafragments.org/>.
128              
129             =head1 METHODS
130              
131             Beyond the methods documented below, this class inherits methods from the L<RDF::Trine::Store> class.
132              
133             =over
134              
135             =item new({ url => url })
136              
137             Returns a new RDF::Trine::Store object that will act as a proxy for the Linked Data Fragment
138             endpoint accessible via the supplied $url.
139              
140             Expertimental: more than one url as an ARRAY reference can be provided for an federated
141             query over many LDF endpoints.
142              
143             =item new_with_config( $hashref )
144              
145             Returns a new RDF::Trine::Store object configured by a hashref with the url as required key.
146              
147             =item get_statements( $subject, $predicate, $object )
148              
149             Returns a stream object of all statements matching the specified subject, predicate and objects.
150             Any of the arguments may be undef to match any value.
151              
152             =item get_pattern( $bgp )
153              
154             Returns an iterator object of all bindings matching the specified graph pattern.
155              
156             =item get_contexts
157              
158             Not supported.
159              
160             =item add_statement ( $statement [, $context] )
161              
162             Not supported.
163              
164             =item remove_statement ( $statement [, $context])
165              
166             Not supported.
167              
168             =item remove_statements ( $subject, $predicate, $object [, $context])
169              
170             Not supported.
171              
172             =item count_statements ( $subject, $predicate, $object )
173              
174             Returns a count of all the statements matching the specified subject, predicate and object.
175             Any of the arguments may be undef to match any value.
176              
177             =item size
178              
179             Returns the number of statements in the store.
180              
181             =item supports ( [ $feature ] )
182              
183             Not supported.
184              
185             =back
186              
187             =head1 AUTHOR
188              
189             Patrick Hochstenbach, C<< patrick.hochstenbach at ugent.be >>
190              
191             =head1 CONTRIBUTORS
192              
193             Gregory Todd Williams, C<< greg@evilfunhouse.com >>
194              
195             =head1 LICENSE
196              
197             This program is free software; you can redistribute it and/or modify it under the terms of either:
198             the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
199              
200             See L<http://dev.perl.org/licenses/> for more information.
201              
202             =encoding utf8
203              
204             =cut