Query/Algebra/Extend.pm

filter: Statementstmt 57.6% 68 / 118 Branchbran 20.8% 5 / 24 Conditioncond 55.5% 5 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 78.2% 18 / 23 Podpod 100% 12 / 12 totaltotal 57.0% 109 / 191 CC 22 SCAR 24.6
CC
22
Cov
52%
_from_sse
42.0
as_sparql
24.1
potentially_bound
12.0
CRAP 11.7
« Query/Federate.pm ↑ Summary Query/Algebra/Table.pm »
1 # RDF::Query::Algebra::Extend
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Extend - Algebra class for extending the variable projection
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Extend version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Extend;
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 Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Scalar::Util qw(reftype blessed);
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 RDF::Trine::Iterator qw(sgrep);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 ######################################################################
28  
29 36 our ($VERSION);
30 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 36 $VERSION = '2.919';
32 }
33  
34 ######################################################################
35  
36 =head1 METHODS
37  
38 Beyond the methods documented below, this class inherits methods from the
39 L<RDF::Query::Algebra> class.
40  
41 =over 4
42  
43 =cut
44  
45 =item C<< new ( $pattern, \@vars_and_exprs ) >>
46  
47 Returns a new Extend structure.
48  
49 =cut
50  
51 25 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod documented
52 25 my $class = shift;
53 25 my $pattern = shift;
54 25 my $vars = shift;
55 25 ▶ unless (reftype($vars) eq 'ARRAY' and not(blessed($vars))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($vars) eq "ARRAY" and not builtin::blessed($vars)) 0 25 25
Condition33%1/3
builtin::reftype($vars) eq "ARRAY" and not builtin::blessed($vars)
!ll&&!rl&&r
0025
MC/DC0%0/2
builtin::reftype($vars) eq "ARRAY" and not builtin::blessed($vars)
builtin::reftype($vars) eq "ARRAY" not builtin::blessed($vars)
Truth table33%1/3
A and not(B)
A= builtin::reftype($vars) eq "ARRAY"B= not builtin::blessed($vars)
ABresult
0X0
100
111
56 0 throw RDF::Query::Error::MethodInvocationError -text => "Variable list in RDF::Query::Algebra::Extend constructor must be an ARRAY reference";
57 }
58 25 my @vars = grep { $_->isa('RDF::Query::Expression::Alias') } @$vars;
59 25 return bless( [ $pattern, \@vars ], $class );
60 }
61  
62 =item C<< construct_args >>
63  
64 Returns a list of arguments that, passed to this class' constructor,
65 will produce a clone of this algebra pattern.
66  
67 =cut
68  
69 130 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
70 130 my $self = shift;
71 130 my $pattern = $self->pattern;
72 130 my $vars = $self->vars;
73 130 return ($pattern, $vars);
74 }
75  
76 =item C<< pattern >>
77  
78 Returns the pattern to be sorted.
79  
80 =cut
81  
82 239 ▶sub pattern {
Subroutine pattern: called CC=2 SCAR=7.6
Pod documented
83 239 my $self = shift;
84 239 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 239 239
85 0 $self->[0] = shift;
86 }
87 239 return $self->[0];
88 }
89  
90 =item C<< vars >>
91  
92 Returns the vars to be extended.
93  
94 =cut
95  
96 213 ▶sub vars {
Subroutine vars: called CC=1 SCAR=0.0
Pod documented
97 213 my $self = shift;
98 213 return $self->[1];
99 }
100  
101 =item C<< sse >>
102  
103 Returns the SSE string for this algebra expression.
104  
105 =cut
106  
107 56 ▶sub sse {
Subroutine sse: called CC=4 SCAR=14.0
Pod documented
108 56 my $self = shift;
109 56 my $context = shift;
110 56 ▶ my $prefix = shift || '';
Condition100%2/2
shift() || ''
l!l
3125
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
111 56 ▶ my $indent = $context->{indent} || ' ';
Condition50%1/2
$context->{'indent'} || ' '
l!l
560
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table50%1/2
A
A= $context->{'indent'}
Aresult
11
00
112
113 my $vars = join(' ',
114 map {
115 64 ▶ ($_->isa('RDF::Query::Node::Variable')) ? '?' . $_->name : $_->sse( $context )
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('RDF::Query::Node::Variable') ? : 0 64 64
116 56 } @{ $self->vars }
117 );
118 56 return sprintf(
119 "(extend (%s)\n${prefix}${indent}%s\n${prefix})",
120 $vars,
121 $self->pattern->sse( $context, "${prefix}${indent}" ),
122 );
123 }
124  
125 0 ▶sub _from_sse {
Subroutine _from_sse: not called CC=6 SCAR=37.4
126 0 my $class = shift;
127 0 my $context = $_[1];
128 0 for ($_[0]) {
129 0 ▶ if (m/^[(]extend\s+[(]\s*/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[(]extend\s+[(]\s*/) { } 0 0 0
130 0 my @nodes;
131 0 s/^[(]extend\s+[(]\s*//;
132 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
/\s*[)]/ or do { do { push @nodes, "RDF::Trine::Node"->from_sse($_[0], $context) } } 0 0 0
133 0 push(@nodes, RDF::Trine::Node->from_sse( $_[0], $context ));
134 } until (m/\s*[)]/);
135 0 ▶ if (m/^\s*[)]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*[)]/) { } 0 0 0
136 0 s/^\s*[)]\s*//;
137 } else {
138 0 throw RDF::Trine::Error -text => "Cannot parse end-of-extend-vars from SSE string: >>$_<<";
139 }
140
141 0 my ($pattern) = RDF::Query::Algebra->from_sse( $context, $_[0] );
142
143 0 ▶ if (m/^\s*[)]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*[)]/) { } 0 0 0
144 0 s/^\s*[)]\s*//;
145 0 return RDF::Query::Algebra::Extend->new( $pattern, \@nodes );
146 } else {
147 0 throw RDF::Trine::Error -text => "Cannot parse end-of-extend from SSE string: >>$_<<";
148 }
149 } else {
150 0 throw RDF::Trine::Error -text => "Cannot parse extend from SSE string: >>$_<<";
151 }
152 }
153 }
154  
155 =item C<< as_sparql >>
156  
157 Returns the SPARQL string for this algebra expression.
158  
159 =cut
160  
161 1 ▶sub as_sparql {
Subroutine as_sparql: called CC=7 SCAR=31.8
Pod documented
162 1 my $self = shift;
163 1 ▶ my $context = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
164 1 my $indent = shift;
165
166 1 ▶ if ($context->{ skip_extend }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"skip_extend"}) 1 0 1
167 1 $context->{ skip_extend }--;
168 1 return $self->pattern->as_sparql( $context, $indent );
169 }
170
171 0 my $pattern = $self->pattern;
172 0 my $vlist = $self->vars;
173 0 my (@vars);
174 0 foreach my $k (@$vlist) {
175 0 ▶ if ($k->isa('RDF::Query::Expression')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k->isa('RDF::Query::Expression')) { } 0 0 0
elsif ($k->isa('RDF::Query::Node::Variable')) { } 0 0 0
176 0 push(@vars, $k->as_sparql({}, ''));
177 } elsif ($k->isa('RDF::Query::Node::Variable')) {
178 0 push(@vars, '?' . $k->name);
179 } else {
180 0 push(@vars, $k);
181 }
182 }
183
184 0 my $ggp = $pattern->as_sparql( $context, $indent );
185 0 my $sparql = $ggp;
186 0 foreach my $v (@vars) {
187 0 $sparql .= "\n${indent}BIND" . $v;
188 }
189 0 return $sparql;
190 }
191  
192 =item C<< as_hash >>
193  
194 Returns the query as a nested set of plain data structures (no objects).
195  
196 =cut
197  
198 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
199 0 my $self = shift;
200 0 my $context = shift;
201 return {
202 type => lc($self->type),
203 pattern => $self->pattern->as_hash,
204 0 vars => [ map { $_->as_hash } @{ $self->vars } ],
205 };
206 }
207  
208 =item C<< type >>
209  
210 Returns the type of this algebra expression.
211  
212 =cut
213  
214 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
215 0 return 'PROJECT';
216 }
217  
218 =item C<< referenced_variables >>
219  
220 Returns a list of the variable names used in this algebra expression.
221  
222 =cut
223  
224 2 ▶sub referenced_variables {
Subroutine referenced_variables: called CC=3 SCAR=11.2
Pod documented
225 2 my $self = shift;
226 2 my @vars = $self->pattern->referenced_variables;
227 2 foreach my $v (@{ $self->vars }) {
228 2 ▶ if ($v->isa('RDF::Query::Node::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->isa('RDF::Query::Node::Variable')) { } 0 2 2
229 0 push(@vars, $v->name);
230 } else {
231 2 push(@vars, $v->referenced_variables);
232 }
233 }
234 2 return RDF::Query::_uniq(@vars);
235 }
236  
237 =item C<< potentially_bound >>
238  
239 Returns a list of the variable names used in this algebra expression that will
240 bind values during execution.
241  
242 =cut
243  
244 0 ▶sub potentially_bound {
Subroutine potentially_bound: not called CC=3 SCAR=24.8
Pod documented
245 0 my $self = shift;
246 0 my @vars;
247 0 push(@vars, $self->pattern->potentially_bound);
248 0 foreach my $v (@{ $self->vars }) {
249 0 ▶ if ($v->isa('RDF::Query::Node::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->isa('RDF::Query::Node::Variable')) { } 0 0 0
250 0 push(@vars, $v->name);
251 } else {
252 0 push(@vars, $v->potentially_bound);
253 }
254 }
255 0 return RDF::Query::_uniq(@vars);
256 }
257  
258 =item C<< definite_variables >>
259  
260 Returns a list of the variable names that will be bound after evaluating this algebra expression.
261  
262 =cut
263  
264 0 ▶sub definite_variables {
Subroutine definite_variables: not called CC=1 SCAR=6.9
Pod documented
265 0 my $self = shift;
266 0 return $self->pattern->definite_variables;
267 }
268  
269 =item C<< is_solution_modifier >>
270  
271 Returns true if this node is a solution modifier.
272  
273 =cut
274  
275 24 ▶sub is_solution_modifier {
Subroutine is_solution_modifier: called CC=1 SCAR=0.0
Pod documented
276 24 return 1;
277 }
278  
279  
280 36 1;
281  
282 __END__
« Query/Federate.pm ↑ Summary Query/Algebra/Table.pm »