File Coverage

blib/lib/Attean/API/Store.pm
Criterion Covered Total %
statement 87 91 95.6
branch 1 2 50.0
condition n/a
subroutine 26 28 92.8
pod 0 10 0.0
total 114 131 87.0


line stmt bran cond sub pod time code
1 50     50   680 use v5.14;
  50         160  
2 50     50   275 use warnings;
  50         118  
  50         2167  
3              
4             =head1 NAME
5              
6             Attean::API::Store - Triple/quad store role
7              
8             =head1 VERSION
9              
10             This document describes Attean::Store version 0.032
11              
12             =head1 DESCRIPTION
13              
14             The Attean::Store role is an empty role that more specialized roles conform to:
15              
16             =over 4
17              
18             =item * L<Attean::API::TripleStore>
19              
20             =item * L<Attean::API::MutableTripleStore>
21              
22             =item * L<Attean::API::ETagCacheableTripleStore>
23              
24             =item * L<Attean::API::TimeCacheableTripleStore>
25              
26             =item * L<Attean::API::QuadStore>
27              
28             =item * L<Attean::API::MutableQuadStore>
29              
30             =item * L<Attean::API::ETagCacheableQuadStore>
31              
32             =item * L<Attean::API::TimeCacheableQuadStore>
33              
34             =back
35              
36             =cut
37              
38             use Moo::Role;
39 50     50   264 }
  50         102  
  50         305  
40              
41             use Scalar::Util qw(blessed);
42              
43 50     50   16769 use Moo::Role;
  50         110  
  50         2444  
44              
45 50     50   301 with 'Attean::API::Store';
  50         136  
  50         254  
46              
47             requires 'get_triples';
48              
49             before 'get_triples' => sub {
50             if (scalar(@_) == 2 and blessed($_[1]) and not($_[1]->does('Attean::API::TermOrVariable'))) {
51             my $type = ref($_[0]);
52             die "get_triples called with a single $type argument, but expecting a list of terms/variables";
53             }
54             };
55            
56             my $self = shift;
57             my $iter = $self->get_triples(@_);
58             my $count = 0;
59 25     25 0 1041 while (my $r = $iter->next) {
60 25         541 $count++;
61 25         847 }
62 25         123 return $count;
63 209         425 }
64            
65 25         480 my $self = shift;
66             return $self->count_triples(@_);
67             }
68            
69 1     1 0 242 my $self = shift;
70 1         4 return $self->count_triples();
71             }
72              
73             my $self = shift;
74 10     10 0 782 return ($self->count_triples_estimate(@_) > 0)
75 10         44 }
76              
77             }
78              
79 0     0 0 0 use Moo::Role;
80 0         0 with 'Attean::API::TripleStore';
81            
82             requires 'add_triple';
83             requires 'remove_triple';
84              
85             before 'add_triple' => sub {
86 50     50   29909 my $self = shift;
  50         148  
  50         255  
87             my $quad = shift;
88             unless ($quad->is_ground) {
89             die "Cannot add a non-ground triple (with variables) to a model";
90             }
91             };
92             }
93              
94             use Moo::Role;
95             with 'Attean::API::TripleStore';
96            
97             requires 'etag_value_for_triples';
98             }
99              
100             use Moo::Role;
101             with 'Attean::API::TripleStore';
102 50     50   20363
  50         139  
  50         244  
103             requires 'mtime_for_triples';
104             }
105              
106             use Scalar::Util qw(blessed);
107              
108             use Moo::Role;
109 50     50   16454  
  50         164  
  50         227  
110             with 'Attean::API::Store';
111              
112             requires 'get_quads';
113              
114             before 'get_quads' => sub {
115             if (scalar(@_) == 2 and blessed($_[1]) and not($_[1]->does('Attean::API::TermOrVariable'))) {
116 50     50   17239 my $type = ref($_[0]);
  50         124  
  50         2187  
117             die "get_quads called with a single $type argument, but expecting a list of terms/variables";
118 50     50   293 }
  50         113  
  50         225  
119             };
120            
121             my $self = shift;
122             my $iter = $self->get_quads(@_);
123             my $count = 0;
124             while (my $r = $iter->next) {
125             $count++;
126             }
127             return $count;
128             }
129            
130             my $self = shift;
131             return $self->count_quads(@_);
132 11     11 0 424 }
133 11         215  
134 11         340 my $self = shift;
135 11         34 return ($self->count_quads_estimate(@_) > 0)
136 22         49 }
137              
138 11         124 my $self = shift;
139             my $iter = $self->get_quads(@_);
140             my %graphs;
141             while (my $r = $iter->next) {
142 12     12 0 522 my $g = $r->graph;
143 12         41 $graphs{ $g->as_string }++;
144             }
145             return Attean::ListIterator->new( values => [map { Attean::IRI->new($_) } keys %graphs], item_type => 'Attean::API::Term' );
146             }
147 0     0 0 0
148 0         0 my $self = shift;
149             return $self->count_quads();
150             }
151             }
152 3     3 0 16  
153 3         57 use Role::Tiny ();
154 3         93 use Moo::Role;
155 3         13 use Type::Tiny::Role;
156 7         15 with 'Attean::API::QuadStore';
157 7         18
158             requires 'add_quad';
159 3         26 requires 'remove_quad';
  3         184  
160             requires 'create_graph';
161             requires 'drop_graph';
162             requires 'clear_graph';
163 2     2 0 683  
164 2         7 before 'add_quad' => sub {
165             my $self = shift;
166             my $quad = shift;
167             unless ($quad->is_ground) {
168             die "Cannot add a non-ground quad (with variables) to a store";
169 50     50   32631 }
  50         119  
  50         1025  
170 50     50   260 };
  50         172  
  50         255  
171 50     50   16173  
  50         147  
  50         6260  
172             my $self = shift;
173             my $iter = shift;
174             my $type = $iter->item_type;
175             use Data::Dumper;
176             die "Iterator type $type isn't quads" unless (Role::Tiny::does_role($type, 'Attean::API::Quad'));
177             while (my $q = $iter->next) {
178             $self->add_quad($q);
179             }
180             }
181             }
182              
183             use Moo::Role;
184              
185             with 'Attean::API::QuadStore';
186            
187             requires 'etag_value_for_quads';
188             }
189 29     29 0 4708  
190 29         60 use Moo::Role;
191 29         120  
192 50     50   353 with 'Attean::API::QuadStore';
  50         108  
  50         6815  
193 29 50       82
194 29         576 requires 'mtime_for_quads';
195 93         2011 }
196              
197             use Moo::Role;
198            
199             requires 'begin_bulk_updates';
200             requires 'end_bulk_updates';
201 50     50   354 }
  50         122  
  50         232  
202              
203             use Moo::Role;
204            
205             with 'Attean::API::Store';
206             }
207              
208             1;
209 50     50   18117  
  50         121  
  50         250  
210              
211             =head1 BUGS
212              
213             Please report any bugs or feature requests to through the GitHub web interface
214             at L<https://github.com/kasei/attean/issues>.
215              
216             =head1 SEE ALSO
217 50     50   17094  
  50         125  
  50         231  
218              
219              
220             =head1 AUTHOR
221              
222             Gregory Todd Williams C<< <gwilliams@cpan.org> >>
223              
224 50     50   16620 =head1 COPYRIGHT
  50         119  
  50         236  
225              
226             Copyright (c) 2014--2022 Gregory Todd Williams.
227             This program is free software; you can redistribute it and/or modify it under
228             the same terms as Perl itself.
229              
230             =cut