Query/Algebra/Filter.pm

filter: Statementstmt 82.5% 71 / 86 Branchbran 56.2% 9 / 16 Conditioncond 52.9% 9 / 17 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 82.6% 19 / 23 Podpod 100% 13 / 13 totaltotal 75.1% 124 / 165 CC 16 SCAR 12.1
CC
16
Cov
75%
referenced_variables
9.3
as_sparql
5.2
new
4.0
CRAP 3.3
« Query/Node/Resource.pm ↑ Summary Query/Functions/Geo.pm »
1 # RDF::Query::Algebra::Filter
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Filter - Algebra class for Filter expressions
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Filter version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Filter;
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 Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Scalar::Util qw(blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 36 ▶use RDF::Query::Error qw(:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 ▶use RDF::Trine::Iterator qw(sgrep smap swatch);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 ######################################################################
29  
30 36 our ($VERSION);
31 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
32 36 $VERSION = '2.919';
33 }
34  
35 ######################################################################
36  
37 # function
38 # operator
39 # unary
40 # binary
41  
42  
43 =head1 METHODS
44  
45 Beyond the methods documented below, this class inherits methods from the
46 L<RDF::Query::Algebra> class.
47  
48 =over 4
49  
50 =cut
51  
52 =item C<new ( $expression, $pattern )>
53  
54 Returns a new Filter structure.
55  
56 =cut
57  
58 48 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
59 48 my $class = shift;
60 48 my $expr = shift;
61 48 my $pattern = shift;
62 48 ▶ Carp::confess "Not an algebra pattern: " . Dumper($pattern) unless ($pattern->isa('RDF::Query::Algebra'));
Branch: 1 branch
BranchTrueFalseTotal
unless $pattern->isa("RDF::Query::Algebra") 0 48 48
63 48 ▶ unless ($pattern->isa('RDF::Query::Algebra::GroupGraphPattern') or $pattern->isa('RDF::Query::Algebra::Filter')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pattern->isa("RDF::Query::Algebra::GroupGraphPattern") or $pattern->isa("RDF::Query::Algebra::Filter")) 3 45 48
Condition100%3/3
$pattern->isa("RDF::Query::Algebra::GroupGraphPattern") or $pattern->isa("RDF::Query::Algebra::Filter")
l!l&&r!l&&!r
4413
MC/DC100%2/2
$pattern->isa("RDF::Query::Algebra::GroupGraphPattern") or $pattern->isa("RDF::Query::Algebra::Filter")
$pattern->isa("RDF::Query::Algebra::GroupGraphPattern") $pattern->isa("RDF::Query::Algebra::Filter")
Truth table100%3/3
A or B
A= $pattern->isa("RDF::Query::Algebra::GroupGraphPattern")B= $pattern->isa("RDF::Query::Algebra::Filter")
ABresult
1X1
011
000
64 # for proper serialization, the pattern needs to be a GGP or another filter
65 3 $pattern = RDF::Query::Algebra::GroupGraphPattern->new( $pattern );
66 }
67 48 return bless( [ 'FILTER', $expr, $pattern ] );
68 }
69  
70 =item C<< construct_args >>
71  
72 Returns a list of arguments that, passed to this class' constructor,
73 will produce a clone of this algebra pattern.
74  
75 =cut
76  
77 158 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
78 158 my $self = shift;
79 158 return ($self->expr, $self->pattern);
80 }
81  
82 =item C<< expr >>
83  
84 Returns the filter expression.
85  
86 =cut
87  
88 319 ▶sub expr {
Subroutine expr: called CC=2 SCAR=7.6
Pod documented
89 319 my $self = shift;
90 319 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 319 319
91 0 $self->[1] = shift;
92 }
93 319 return $self->[1];
94 }
95  
96 =item C<< pattern >>
97  
98 Returns the filter pattern.
99  
100 =cut
101  
102 312 ▶sub pattern {
Subroutine pattern: called CC=2 SCAR=7.6
Pod documented
103 312 my $self = shift;
104 312 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 312 312
105 0 $self->[2] = shift;
106 }
107 312 return $self->[2];
108 }
109  
110 =item C<< sse >>
111  
112 Returns the SSE string for this algebra expression.
113  
114 =cut
115  
116 84 ▶sub sse {
Subroutine sse: called CC=3 SCAR=11.0
Pod documented
117 84 my $self = shift;
118 84 my $context = shift;
119 84 ▶ my $prefix = shift || '';
Condition100%2/2
shift() || ''
l!l
4737
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
120 84 ▶ my $indent = $context->{indent} || ' ';
Condition50%1/2
$context->{'indent'} || ' '
l!l
840
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table50%1/2
A
A= $context->{'indent'}
Aresult
11
00
121
122 84 return sprintf(
123 "(filter %s\n${prefix}${indent}%s)",
124 $self->expr->sse( $context, "${prefix}${indent}" ),
125 $self->pattern->sse( $context, "${prefix}${indent}" ),
126 );
127 }
128  
129 =item C<< as_sparql >>
130  
131 Returns the SPARQL string for this algebra expression.
132  
133 =cut
134  
135 8 ▶sub as_sparql {
Subroutine as_sparql: called CC=5 SCAR=16.4
Pod documented
136 8 my $self = shift;
137 8 ▶ my $context = shift || {};
Condition50%1/2
shift() || {}
l!l
80
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
138 8 ▶ my $indent = shift || '';
Condition50%1/2
shift() || ''
l!l
08
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
139
140 8 ▶ if ($context->{ skip_filter }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"skip_filter"}) 1 7 8
141 1 $context->{ skip_filter }--;
142 1 return $self->pattern->as_sparql( $context, $indent );
143 }
144
145 7 my $expr = $self->expr;
146 7 my $filter_sparql = $expr->as_sparql( $context, $indent );
147 7 my $pattern_sparql = $self->pattern->as_sparql( $context, $indent );
148 7 ▶ if ($pattern_sparql =~ m#}\s*$#) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_sparql =~ /}\s*$/) { } 7 0 7
149 7 $pattern_sparql =~ s#}\s*$#${indent}\tFILTER( ${filter_sparql} ) .\n${indent}}#;
150 } else {
151 0 $pattern_sparql = "${pattern_sparql}\n${indent}FILTER( ${filter_sparql} )";
152 }
153 7 return $pattern_sparql;
154 }
155  
156 =item C<< as_hash >>
157  
158 Returns the query as a nested set of plain data structures (no objects).
159  
160 =cut
161  
162 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
163 0 my $self = shift;
164 0 my $context = shift;
165 return {
166 0 type => lc($self->type),
167 pattern => $self->pattern->as_hash,
168 expression => $self->expr->as_hash,
169 };
170 }
171  
172 =item C<< as_spin ( $model ) >>
173  
174 Adds statements to the given model to represent this algebra object in the
175 SPARQL Inferencing Notation (L<http://www.spinrdf.org/>).
176  
177 =cut
178  
179 0 ▶sub as_spin {
Subroutine as_spin: not called CC=1 SCAR=6.9
Pod documented
180 0 my $self = shift;
181 0 my $model = shift;
182 0 return $self->pattern->as_spin($model);
183 }
184  
185 =item C<< type >>
186  
187 Returns the type of this algebra expression.
188  
189 =cut
190  
191 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
192 0 return 'FILTER';
193 }
194  
195 =item C<< referenced_variables >>
196  
197 Returns a list of the variable names used in this algebra expression.
198  
199 =cut
200  
201 16 ▶sub referenced_variables {
Subroutine referenced_variables: called CC=5 SCAR=22.3
Pod documented
202 16 my $self = shift;
203 16 my $expr = $self->expr;
204 16 my $pattern = $self->pattern;
205 16 my @vars = $pattern->referenced_variables;
206 16 ▶ if (blessed($expr) and $expr->isa('RDF::Query::Algebra')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($expr) and $expr->isa('RDF::Query::Algebra')) { } 16 0 16
elsif (builtin::blessed($expr) and $expr->isa('RDF::Query::Node::Variable')) { } 0 0 0
Condition33%1/3
builtin::blessed($expr) and $expr->isa("RDF::Query::Algebra")
!ll&&!rl&&r
0016
MC/DC0%0/2
builtin::blessed($expr) and $expr->isa("RDF::Query::Algebra")
builtin::blessed($expr) $expr->isa("RDF::Query::Algebra")
Truth table33%1/3
A and B
A= builtin::blessed($expr)B= $expr->isa("RDF::Query::Algebra")
ABresult
0X0
100
111
207 16 return RDF::Query::_uniq(@vars, $self->expr->referenced_variables);
208 ▶ } elsif (blessed($expr) and $expr->isa('RDF::Query::Node::Variable')) {
Condition0%0/3
builtin::blessed($expr) and $expr->isa("RDF::Query::Node::Variable")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($expr) and $expr->isa("RDF::Query::Node::Variable")
builtin::blessed($expr) $expr->isa("RDF::Query::Node::Variable")
Truth table0%0/3
A and B
A= builtin::blessed($expr)B= $expr->isa("RDF::Query::Node::Variable")
ABresult
0X0
100
111
209 0 return RDF::Query::_uniq(@vars, $expr->name);
210 } else {
211 0 return (@vars);
212 }
213 }
214  
215 =item C<< potentially_bound >>
216  
217 Returns a list of the variable names used in this algebra expression that will
218 bind values during execution.
219  
220 =cut
221  
222 8 ▶sub potentially_bound {
Subroutine potentially_bound: called CC=1 SCAR=0.0
Pod documented
223 8 my $self = shift;
224 8 return $self->pattern->potentially_bound;
225 }
226  
227 =item C<< definite_variables >>
228  
229 Returns a list of the variable names that will be bound after evaluating this algebra expression.
230  
231 =cut
232  
233 0 ▶sub definite_variables {
Subroutine definite_variables: not called CC=1 SCAR=6.9
Pod documented
234 0 my $self = shift;
235 0 my $pattern = $self->pattern;
236 0 return $pattern->definite_variables;
237 }
238  
239 =item C<< is_solution_modifier >>
240  
241 Returns true if this node is a solution modifier.
242  
243 =cut
244  
245 37 ▶sub is_solution_modifier {
Subroutine is_solution_modifier: called CC=1 SCAR=0.0
Pod documented
246 37 return 0;
247 }
248  
249  
250 36 1;
251  
252 __END__
« Query/Node/Resource.pm ↑ Summary Query/Functions/Geo.pm »