Query/Algebra/Update.pm

filter: Statementstmt 60.3% 76 / 126 Branchbran 22.5% 9 / 40 Conditioncond 18.1% 4 / 22 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 79.1% 19 / 24 Podpod 100% 12 / 12 totaltotal 51.2% 121 / 236 CC 33 SCAR 50.4
CC
33
Cov
47%
as_sparql
420.0
check_duplicate_blanks
20.0
sse
11.8
CRAP 154.2
« Query/Node/Literal.pm ↑ Summary Query/ServiceDescription.pm »
1 # RDF::Query::Algebra::Update
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Update - Algebra class for UPDATE operations
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Update version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Update;
15  
16 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 36 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 36 ▶use base qw(RDF::Query::Algebra);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 36 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 36 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 36 ▶use Scalar::Util qw(blessed reftype refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 36 ▶use RDF::Trine::Iterator qw(smap sgrep swatch);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 ######################################################################
30  
31 36 our ($VERSION);
32 36 my %TRIPLE_LABELS;
33 36 my @node_methods = qw(subject predicate object);
34 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
35 36 $VERSION = '2.919';
36 }
37  
38 ######################################################################
39  
40 =head1 METHODS
41  
42 Beyond the methods documented below, this class inherits methods from the
43 L<RDF::Query::Algebra> class.
44  
45 =over 4
46  
47 =cut
48  
49 =item C<new ( $delete_template, $insert_template, $pattern, \%dataset, $data_only_flag )>
50  
51 Returns a new UPDATE structure.
52  
53 =cut
54  
55 10 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
56 10 my $class = shift;
57 10 my $delete = shift;
58 10 my $insert = shift;
59 10 my $pat = shift;
60 10 my $dataset = shift;
61 10 my $data = shift;
62 10 return bless([$delete, $insert, $pat, $dataset, $data], $class);
63 }
64  
65 =item C<< construct_args >>
66  
67 Returns a list of arguments that, passed to this class' constructor,
68 will produce a clone of this algebra pattern.
69  
70 =cut
71  
72 38 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
73 38 my $self = shift;
74 38 return ($self->delete_template, $self->insert_template, $self->pattern);
75 }
76  
77 =item C<< sse >>
78  
79 Returns the SSE string for this algebra expression.
80  
81 =cut
82  
83 8 ▶sub sse {
Subroutine sse: called CC=11 SCAR=24.7
Pod documented
84 8 my $self = shift;
85 8 my $context = shift;
86 8 my $indent = shift;
87
88 8 my $string;
89 8 my $delete = $self->delete_template;
90 8 my $insert = $self->insert_template;
91 8 my $dataset = $self->dataset;
92 8 ▶ my @ds_keys = keys %{ $dataset || {} };
Condition100%2/2
$dataset || {}
l!l
26
MC/DC100%1/1
$dataset || {}
$dataset
Truth table100%2/2
A
A= $dataset
Aresult
11
00
93 8 ▶ if (@ds_keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ds_keys) { } 1 7 8
94 1 ▶ my @defaults = sort map { $_->sse } @{ $dataset->{default} || [] };
Condition50%1/2
$dataset->{'default'} || []
l!l
10
MC/DC0%0/1
$dataset->{'default'} || []
$dataset->{'default'}
Truth table50%1/2
A
A= $dataset->{'default'}
Aresult
11
00
95 0 ▶ my @named = sort map { $_->sse } values %{ $dataset->{named} || {} };
Condition50%1/2
$dataset->{'named'} || {}
l!l
01
MC/DC0%0/1
$dataset->{'named'} || {}
$dataset->{'named'}
Truth table50%1/2
A
A= $dataset->{'named'}
Aresult
11
00
96 1 my @strings;
97 1 ▶ push(@strings, (@defaults) ? '(defaults ' . join(' ', @defaults) . ')' : ());
Branch: 1 branch
BranchTrueFalseTotal
@defaults ? : 1 0 1
98 1 ▶ push(@strings, (@named) ? '(named ' . join(' ', @named) . ')' : ());
Branch: 1 branch
BranchTrueFalseTotal
@named ? : 0 1 1
99
100 1 my $ds_string = '(dataset ' . join(' ', @strings) . ')';
101 1 ▶ return sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$delete ? : 1 0 1
$insert ? : 1 0 1
102 "(update (delete %s) (insert %s) (where %s) %s)",
103 ($delete ? $delete->sse( $context, $indent ) : ''),
104 ($insert ? $insert->sse( $context, $indent ) : ''),
105 $self->pattern->sse( $context, $indent ),
106 $ds_string,
107 );
108 } else {
109 7 ▶ return sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$delete ? : 1 6 7
$insert ? : 7 0 7
110 "(update (delete %s) (insert %s) (where %s))",
111 ($delete ? $delete->sse( $context, $indent ) : ''),
112 ($insert ? $insert->sse( $context, $indent ) : ''),
113 $self->pattern->sse( $context, $indent ),
114 );
115 }
116 }
117  
118 =item C<< as_sparql >>
119  
120 Returns the SPARQL string for this algebra expression.
121  
122 =cut
123  
124 0 ▶sub as_sparql {
Subroutine as_sparql: not called CC=20 SCAR=60.4
Pod documented
125 0 my $self = shift;
126 0 ▶ my $context = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
127 0 ▶ my $indent = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
128 0 my $delete = $self->delete_template;
129 0 my $insert = $self->insert_template;
130 0 my $ggp = $self->pattern;
131
132 0 my $dataset = $self->dataset;
133 0 ▶ my @ds_keys = keys %{ $dataset || {} };
Condition0%0/2
$dataset || {}
l!l
00
MC/DC0%0/1
$dataset || {}
$dataset
Truth table0%0/2
A
A= $dataset
Aresult
11
00
134 0 my $ds_string = '';
135 0 ▶ if (@ds_keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ds_keys) 0 0 0
136 0 ▶ my @defaults = @{ $dataset->{default} || [] };
Condition0%0/2
$dataset->{'default'} || []
l!l
00
MC/DC0%0/1
$dataset->{'default'} || []
$dataset->{'default'}
Truth table0%0/2
A
A= $dataset->{'default'}
Aresult
11
00
137 0 ▶ my %named = %{ $dataset->{named} || {} };
Condition0%0/2
$dataset->{'named'} || {}
l!l
00
MC/DC0%0/1
$dataset->{'named'} || {}
$dataset->{'named'}
Truth table0%0/2
A
A= $dataset->{'named'}
Aresult
11
00
138 0 my @strings;
139 0 push(@strings, sprintf("USING <%s>", $_->uri_value)) foreach (@defaults);
140 0 push(@strings, sprintf("USING NAMED <%s>", $named{$_}->uri_value)) foreach (keys %named);
141 0 $ds_string = join("\n${indent}", @strings);
142 }
143
144 0 ▶ if ($insert or $delete) {
Branch: 1 branch
BranchTrueFalseTotal
if ($insert or $delete) { } 0 0 0
Condition0%0/3
$insert or $delete
l!l&&r!l&&!r
000
MC/DC0%0/2
$insert or $delete
$insert $delete
Truth table0%0/3
A or B
A= $insertB= $delete
ABresult
1X1
011
000
145 # TODO: $(delete|insert)->as_sparql here isn't properly serializing GRAPH blocks, because even though they contain Quad objects inside of BGPs, there's no containing NamedGraph object...
146 0 ▶ if ($ds_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ds_string) 0 0 0
147 0 $ds_string = "\n${indent}$ds_string";
148 }
149
150 0 ▶ if ($insert and $delete) {
Branch: 2 branches
BranchTrueFalseTotal
if ($insert and $delete) { } 0 0 0
elsif ($insert) { } 0 0 0
Condition0%0/3
$insert and $delete
!ll&&!rl&&r
000
MC/DC0%0/2
$insert and $delete
$insert $delete
Truth table0%0/3
A and B
A= $insertB= $delete
ABresult
0X0
100
111
151 0 return sprintf(
152 "DELETE {\n${indent} %s\n${indent}}\n${indent}INSERT {\n${indent} %s\n${indent}}\n${indent}%s\n${indent}WHERE %s",
153 $delete->as_sparql( $context, "${indent} " ),
154 $insert->as_sparql( $context, "${indent} " ),
155 $ds_string,
156 $ggp->as_sparql( { %$context, force_ggp_braces => 1 }, ${indent} ),
157 );
158 } elsif ($insert) {
159 0 return sprintf(
160 "INSERT {\n${indent} %s\n${indent}}\n${indent}%s\n${indent}WHERE %s",
161 $insert->as_sparql( $context, "${indent} " ),
162 $ds_string,
163 $ggp->as_sparql( { %$context, force_ggp_braces => 1 }, ${indent} ),
164 );
165 } else {
166 0 return sprintf(
167 "DELETE {\n${indent} %s\n${indent}}\n${indent}%s\n${indent}WHERE %s",
168 $delete->as_sparql( $context, "${indent} " ),
169 $ds_string,
170 $ggp->as_sparql( { %$context, force_ggp_braces => 1 }, ${indent} ),
171 );
172 }
173 } else {
174 0 my @pats = $ggp->patterns;
175 0 ▶ my $op = ($delete) ? 'DELETE' : 'INSERT';
Branch: 1 branch
BranchTrueFalseTotal
$delete ? : 0 0 0
176 0 ▶ my $temp = ($delete) ? $delete : $insert;
Branch: 1 branch
BranchTrueFalseTotal
$delete ? : 0 0 0
177 0 ▶ my $temps = ($temp->isa('RDF::Query::Algebra::GroupGraphPattern'))
Branch: 1 branch
BranchTrueFalseTotal
$temp->isa('RDF::Query::Algebra::GroupGraphPattern') ? : 0 0 0
178 ? $temp->as_sparql( $context, "${indent} " )
179 : "{\n${indent} " . $temp->as_sparql( $context, "${indent} " ) . "\n${indent}}";
180 0 ▶ if (scalar(@pats) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @pats == 0) { } 0 0 0
181 0 return sprintf(
182 "${op} DATA %s",
183 $temps
184 );
185 } else {
186 0 ▶ if ($ds_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ds_string) { } 0 0 0
187 0 $ds_string = "\n${indent}$ds_string\n${indent}";
188 } else {
189 0 $ds_string = ' ';
190 }
191 0 return sprintf(
192 "${op} %s%sWHERE %s",
193 $temps,
194 $ds_string,
195 $ggp->as_sparql( { %$context, force_ggp_braces => 1 }, "${indent}" ),
196 );
197 }
198 }
199 }
200  
201 =item C<< referenced_blanks >>
202  
203 Returns a list of the blank node names used in this algebra expression.
204  
205 =cut
206  
207 0 ▶sub referenced_blanks {
Subroutine referenced_blanks: not called CC=1 SCAR=6.9
Pod documented
208 0 my $self = shift;
209 0 return;
210 }
211  
212 =item C<< referenced_variables >>
213  
214 =cut
215  
216 0 ▶sub referenced_variables {
Subroutine referenced_variables: not called CC=1 SCAR=6.9
Pod documented
217 0 my $self = shift;
218 0 return;
219 }
220  
221 =item C<< delete_template >>
222  
223 =cut
224  
225 54 ▶sub delete_template {
Subroutine delete_template: called CC=1 SCAR=0.0
Pod documented
226 54 my $self = shift;
227 54 return $self->[0];
228 }
229  
230 =item C<< insert_template >>
231  
232 =cut
233  
234 54 ▶sub insert_template {
Subroutine insert_template: called CC=1 SCAR=0.0
Pod documented
235 54 my $self = shift;
236 54 return $self->[1];
237 }
238  
239 =item C<< pattern >>
240  
241 =cut
242  
243 54 ▶sub pattern {
Subroutine pattern: called CC=1 SCAR=0.0
Pod documented
244 54 my $self = shift;
245 54 return $self->[2];
246 }
247  
248 =item C<< dataset >>
249  
250 =cut
251  
252 16 ▶sub dataset {
Subroutine dataset: called CC=1 SCAR=0.0
Pod documented
253 16 my $self = shift;
254 16 return $self->[3];
255 }
256  
257 =item C<< data_only >>
258  
259 =cut
260  
261 0 ▶sub data_only {
Subroutine data_only: not called CC=1 SCAR=6.9
Pod documented
262 0 my $self = shift;
263 0 return $self->[4];
264 }
265  
266 =item C<< check_duplicate_blanks >>
267  
268 Returns true if blank nodes respect the SPARQL rule of no blank-label re-use
269 across BGPs, otherwise throws a RDF::Query::Error::QueryPatternError exception.
270  
271 =cut
272  
273 0 ▶sub check_duplicate_blanks {
Subroutine check_duplicate_blanks: not called CC=4 SCAR=30.0
Pod documented
274 0 my $self = shift;
275 0 ▶ unless ($self->data_only) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->data_only) 0 0 0
276 # if self isn't an INSERT/DELETE DATA operation, then we need to check the template patterns, too
277 0 ▶ if ($self->delete_template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->delete_template) 0 0 0
278 0 $self->delete_template->check_duplicate_blanks;
279 }
280
281 0 ▶ if ($self->insert_tempalte) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->insert_tempalte) 0 0 0
282 0 $self->insert_tempalte->check_duplicate_blanks;
283 }
284 }
285 0 return $self->pattern->check_duplicate_blanks;
286 }
287  
288 36 1;
289  
290 __END__
« Query/Node/Literal.pm ↑ Summary Query/ServiceDescription.pm »