File Coverage

blib/lib/RDF/Trine/Model/Union.pm
Criterion Covered Total %
statement 55 55 100.0
branch n/a
condition n/a
subroutine 16 16 100.0
pod 6 6 100.0
total 77 77 100.0


line stmt bran cond sub pod time code
1             # RDF::Trine::Model::Union
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Trine::Model::Union - Union models for joining multiple stores together
7              
8             =head1 VERSION
9              
10             This document describes RDF::Trine::Model::Union version 1.018
11              
12             =head1 METHODS
13              
14             Beyond the methods documented below, this class inherits methods from the
15             L<RDF::Trine::Model> class.
16              
17             =over 4
18              
19             =cut
20              
21             package RDF::Trine::Model::Union;
22              
23 1     1   389 use strict;
  1         2  
  1         24  
24 1     1   5 use warnings;
  1         2  
  1         23  
25 1     1   5 no warnings 'redefine';
  1         2  
  1         32  
26 1     1   6 use base qw(RDF::Trine::Model);
  1         2  
  1         59  
27 1     1   6 use Scalar::Util qw(blessed);
  1         2  
  1         43  
28              
29 1     1   5 use RDF::Trine::Node;
  1         3  
  1         30  
30 1     1   5 use RDF::Trine::Store;
  1         2  
  1         33  
31              
32             our ($VERSION);
33             BEGIN {
34 1     1   309 $VERSION = '1.018';
35             }
36              
37             ################################################################################
38              
39             =item C<< new ( @stores ) >>
40              
41             Returns a new union-model over the list of supplied rdf stores.
42              
43             =cut
44              
45             sub new {
46 1     1 1 11 my $class = shift;
47 1         3 my @stores = @_;
48 1         4 my $self = bless({ stores => \@stores }, $class);
49             }
50              
51             =item C<< add_statement ( $statement [, $context] ) >>
52              
53             Adds the specified C<$statement> to the first rdf store.
54              
55             =cut
56              
57             sub add_statement {
58 1     1 1 7 my $self = shift;
59 1         2 my @iterators;
60 1         4 my ($store) = $self->_stores;
61 1         4 $store->add_statement( @_ );
62             }
63              
64             =item C<< remove_statement ( $statement [, $context]) >>
65              
66             Removes the specified C<$statement> from all of the rdf stores.
67              
68             =cut
69              
70             sub remove_statement {
71 1     1 1 7 my $self = shift;
72 1         4 foreach my $store ($self->_stores) {
73 2         9 $store->remove_statement( @_ );
74             }
75             }
76              
77             =item C<< remove_statements ( $subject, $predicate, $object [, $context]) >>
78              
79             Removes all statements matching the supplied C<$statement> pattern from all of the rdf stores.
80              
81             =cut
82              
83             sub remove_statements {
84 1     1 1 7 my $self = shift;
85 1         3 foreach my $store ($self->_stores) {
86 2         8 $store->remove_statements( @_ );
87             }
88             }
89              
90             =item C<< count_statements ($subject, $predicate, $object) >>
91              
92             Returns a count of all the statements matching the specified subject,
93             predicate and objects. Any of the arguments may be undef to match any value.
94              
95             =cut
96              
97             sub count_statements {
98 1     1 1 2 my $self = shift;
99 1         2 my $count = 0;
100 1         4 foreach my $store ($self->_stores) {
101 2         7 $count += $store->count_statements( @_ );
102             }
103 1         5 return $count;
104             }
105              
106             =item C<< get_statements ($subject, $predicate, $object [, $context] ) >>
107              
108             Returns a stream object of all statements matching the specified subject,
109             predicate and objects from all of the rdf stores. Any of the arguments may be
110             undef to match any value.
111              
112             =cut
113              
114             sub get_statements {
115 5     5 1 9 my $self = shift;
116 5         8 my @iterators;
117 5         12 foreach my $store ($self->_stores) {
118 10         32 my $i = $store->get_statements( @_ );
119 10         24 push(@iterators, $i);
120             # my @data;
121             # while (my $d = $i->next) {
122             # warn '++++++++++++++++++ ' . $d->as_string;
123             #
124             # }
125             #
126             # my $m = $i->materialize;
127             # push(@iterators, $m);
128             }
129 5         14 while (@iterators > 1) {
130 5         9 my $i = shift(@iterators);
131 5         9 my $j = shift(@iterators);
132 5         19 unshift(@iterators, $i->concat( $j ));
133             }
134 5         16 return $iterators[0]->unique;
135             }
136              
137             # =item C<< get_pattern ( $bgp [, $context] ) >>
138             #
139             # Returns a stream object of all bindings matching the specified graph pattern.
140             #
141             # =cut
142             #
143             # sub get_pattern {
144             # my $self = shift;
145             # my @iterators;
146             # foreach my $store ($self->_stores) {
147             # push(@iterators, $store->get_pattern( @_ ));
148             # }
149             # while (@iterators > 1) {
150             # my $i = shift(@iterators);
151             # my $j = shift(@iterators);
152             # unshift(@iterators, $i->concat( $j ));
153             # }
154             # return $iterators[0];
155             # }
156              
157             sub _stores {
158 9     9   15 my $self = shift;
159 9         13 return @{ $self->{stores} };
  9         27  
160             }
161              
162             sub _store {
163 7     7   11 my $self = shift;
164 7         15 return;
165             }
166              
167             1;
168              
169             __END__
170              
171             =back
172              
173             =head1 BUGS
174              
175             Please report any bugs or feature requests to through the GitHub web interface
176             at L<https://github.com/kasei/perlrdf/issues>.
177              
178             =head1 AUTHOR
179              
180             Gregory Todd Williams C<< <gwilliams@cpan.org> >>
181              
182             =head1 COPYRIGHT
183              
184             Copyright (c) 2006-2012 Gregory Todd Williams. This
185             program is free software; you can redistribute it and/or modify it under
186             the same terms as Perl itself.
187              
188             =cut