Attean/API/Store.pm

filter: Statementstmt 93.1% 135 / 145 Branchbran 72.2% 13 / 18 Conditioncond 66.6% 8 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 93.7% 30 / 32 Podpod 0.0% 0 / 10 totaltotal 83.4% 186 / 223 CC 14 SCAR 7.9
CC
14
Cov
89%
__ANON__
5.5
__ANON__
5.5
add_iter
3.0
CRAP 2.2
« Attean/ListIterator.pm ↑ Summary Test/Attean/TripleStore.pm »
1 50 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
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.040
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 50 package Attean::API::Store 0.040 {
39 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 }
41  
42 50 package Attean::API::TripleStore 0.040 {
43 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 50 with 'Attean::API::Store';
48  
49 50 requires 'get_triples';
50  
51 49 ▶ before 'get_triples' => sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
52 49 ▶ if (scalar(@_) == 2 and blessed($_[1]) and not($_[1]->does('Attean::API::TermOrVariable'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 2 and builtin::blessed($_[1]) and not $_[1]->does("Attean::API::TermOrVariable")) 0 49 49
Condition66%4/6
scalar @_ == 2 and builtin::blessed($_[1]) and not $_[1]->does("Attean::API::TermOrVariable")
!ll&&!rl&&r
4360
scalar @_ == 2 and builtin::blessed($_[1])
!ll&&!rl&&r
4306
MC/DC0%0/3
scalar @_ == 2 and builtin::blessed($_[1]) and not $_[1]->does("Attean::API::TermOrVariable")
scalar @_ == 2 builtin::blessed($_[1]) not $_[1]->does("Attean::API::TermOrVariable")
Truth table50%2/4
A and B and not(C)
A= scalar @_ == 2B= builtin::blessed($_[1])C= not $_[1]->does("Attean::API::TermOrVariable")
ABCresult
0XX0
10X0
1100
1111
53 0 my $type = ref($_[0]);
54 0 die "get_triples called with a single $type argument, but expecting a list of terms/variables";
55 }
56 50 };
57
58 25 ▶ sub count_triples {
Subroutine count_triples: called CC=2 SCAR=6.9
Pod undocumented
59 25 my $self = shift;
60 25 my $iter = $self->get_triples(@_);
61 25 my $count = 0;
62 25 ▶ while (my $r = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $iter->next) 209 25 234
63 209 $count++;
64 }
65 25 return $count;
66 }
67
68 1 ▶ sub count_triples_estimate {
Subroutine count_triples_estimate: called CC=1 SCAR=0.0
Pod undocumented
69 1 my $self = shift;
70 1 return $self->count_triples(@_);
71 }
72
73 10 ▶ sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
74 10 my $self = shift;
75 10 return $self->count_triples();
76 }
77  
78 0 ▶ sub holds {
Subroutine holds: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my $self = shift;
80 0 return ($self->count_triples_estimate(@_) > 0)
81 }
82  
83 }
84  
85 50 package Attean::API::MutableTripleStore 0.040 {
86 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 50 with 'Attean::API::TripleStore';
88
89 50 requires 'add_triple';
90 50 requires 'remove_triple';
91  
92 16 ▶ before 'add_triple' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
93 16 my $self = shift;
94 16 my $quad = shift;
95 16 ▶ unless ($quad->is_ground) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($quad->is_ground) 0 16 16
96 0 die "Cannot add a non-ground triple (with variables) to a model";
97 }
98 50 };
99 }
100  
101 50 package Attean::API::ETagCacheableTripleStore 0.040 {
102 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 50 with 'Attean::API::TripleStore';
104
105 50 requires 'etag_value_for_triples';
106 }
107  
108 50 package Attean::API::TimeCacheableTripleStore 0.040 {
109 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 50 with 'Attean::API::TripleStore';
111
112 50 requires 'mtime_for_triples';
113 }
114  
115 50 package Attean::API::QuadStore 0.040 {
116 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 50 with 'Attean::API::Store';
121  
122 50 requires 'get_quads';
123  
124 129 ▶ before 'get_quads' => sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
125 129 ▶ if (scalar(@_) == 2 and blessed($_[1]) and not($_[1]->does('Attean::API::TermOrVariable'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 2 and builtin::blessed($_[1]) and not $_[1]->does("Attean::API::TermOrVariable")) 0 129 129
Condition66%4/6
scalar @_ == 2 and builtin::blessed($_[1]) and not $_[1]->does("Attean::API::TermOrVariable")
!ll&&!rl&&r
117120
scalar @_ == 2 and builtin::blessed($_[1])
!ll&&!rl&&r
117012
MC/DC0%0/3
scalar @_ == 2 and builtin::blessed($_[1]) and not $_[1]->does("Attean::API::TermOrVariable")
scalar @_ == 2 builtin::blessed($_[1]) not $_[1]->does("Attean::API::TermOrVariable")
Truth table50%2/4
A and B and not(C)
A= scalar @_ == 2B= builtin::blessed($_[1])C= not $_[1]->does("Attean::API::TermOrVariable")
ABCresult
0XX0
10X0
1100
1111
126 0 my $type = ref($_[0]);
127 0 die "get_quads called with a single $type argument, but expecting a list of terms/variables";
128 }
129 50 };
130
131 11 ▶ sub count_quads {
Subroutine count_quads: called CC=2 SCAR=6.9
Pod undocumented
132 11 my $self = shift;
133 11 my $iter = $self->get_quads(@_);
134 11 my $count = 0;
135 11 ▶ while (my $r = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $iter->next) 22 11 33
136 22 $count++;
137 }
138 11 return $count;
139 }
140
141 12 ▶ sub count_quads_estimate {
Subroutine count_quads_estimate: called CC=1 SCAR=0.0
Pod undocumented
142 12 my $self = shift;
143 12 return $self->count_quads(@_);
144 }
145  
146 0 ▶ sub holds {
Subroutine holds: not called CC=1 SCAR=6.9
Pod undocumented
147 0 my $self = shift;
148 0 return ($self->count_quads_estimate(@_) > 0)
149 }
150  
151 3 ▶ sub get_graphs {
Subroutine get_graphs: called CC=2 SCAR=6.9
Pod undocumented
152 3 my $self = shift;
153 3 my $iter = $self->get_quads(@_);
154 3 my %graphs;
155 3 ▶ while (my $r = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $iter->next) 7 3 10
156 7 my $g = $r->graph;
157 7 $graphs{ $g->as_string }++;
158 }
159 3 return Attean::ListIterator->new( values => [map { Attean::IRI->new($_) } keys %graphs], item_type => 'Attean::API::Term' );
160 }
161
162 2 ▶ sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
163 2 my $self = shift;
164 2 return $self->count_quads();
165 }
166 }
167  
168 50 package Attean::API::MutableQuadStore 0.040 {
169 50 ▶ use Role::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
170 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
171 50 ▶ use Type::Tiny::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
172 50 with 'Attean::API::QuadStore';
173
174 50 requires 'add_quad';
175 50 requires 'remove_quad';
176 50 requires 'create_graph';
177 50 requires 'drop_graph';
178 50 requires 'clear_graph';
179  
180 140 ▶ before 'add_quad' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
181 140 my $self = shift;
182 140 my $quad = shift;
183 140 ▶ unless ($quad->is_ground) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($quad->is_ground) 0 140 140
184 0 die "Cannot add a non-ground quad (with variables) to a store";
185 }
186 50 };
187  
188 29 ▶ sub add_iter {
Subroutine add_iter: called CC=3 SCAR=11.0
Pod undocumented
189 29 my $self = shift;
190 29 my $iter = shift;
191 29 my $type = $iter->item_type;
192 50 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 29 ▶ die "Iterator type $type isn't quads" unless (Role::Tiny::does_role($type, 'Attean::API::Quad'));
Branch: 1 branch
BranchTrueFalseTotal
unless Role::Tiny::does_role($type, "Attean::API::Quad") 0 29 29
194 29 ▶ while (my $q = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $q = $iter->next) 93 29 122
195 93 $self->add_quad($q);
196 }
197 }
198 }
199  
200 50 package Attean::API::ETagCacheableQuadStore 0.040 {
201 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
202  
203 50 with 'Attean::API::QuadStore';
204
205 50 requires 'etag_value_for_quads';
206 }
207  
208 50 package Attean::API::TimeCacheableQuadStore 0.040 {
209 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
210  
211 50 with 'Attean::API::QuadStore';
212
213 50 requires 'mtime_for_quads';
214 }
215  
216 50 package Attean::API::BulkUpdatableStore 0.040 {
217 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
218
219 50 requires 'begin_bulk_updates';
220 50 requires 'end_bulk_updates';
221 }
222  
223 50 package Attean::API::RDFStarStore 0.040 {
224 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
225
226 50 with 'Attean::API::Store';
227 }
228  
229 50 1;
230  
231 __END__
« Attean/ListIterator.pm ↑ Summary Test/Attean/TripleStore.pm »