Query/Algebra/Sequence.pm

filter: Statementstmt 55.3% 57 / 103 Branchbran 0.0% 0 / 6 Conditioncond 26.6% 4 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 65.3% 17 / 26 Podpod 100% 13 / 13 totaltotal 53.2% 91 / 171 CC 15 SCAR 20.5
CC
15
Cov
49%
as_sparql
20.0
_referenced_blanks
20.0
check_duplicate_blanks
16.1
CRAP 7.8
« Query/Plan/Construct.pm ↑ Summary Query/Plan/BasicGraphPattern.pm »
1 # RDF::Query::Algebra::Sequence
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Sequence - Algebra class for a sequence of algebra operations
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Sequence version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Sequence;
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 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 Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 ▶use RDF::Trine::Iterator qw(smap swatch);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 ######################################################################
29  
30 36 our ($VERSION);
31 36 my %AS_SPARQL;
32 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
33 36 $VERSION = '2.919';
34 }
35  
36 ######################################################################
37  
38 =head1 METHODS
39  
40 Beyond the methods documented below, this class inherits methods from the
41 L<RDF::Query::Algebra> class.
42  
43 =over 4
44  
45 =cut
46  
47 =item C<new ( @patterns )>
48  
49 Returns a new Sequence structure.
50  
51 =cut
52  
53 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
54 1 my $class = shift;
55 1 my @patterns = @_;
56 1 return bless( [ @patterns ] );
57 }
58  
59 =item C<< construct_args >>
60  
61 Returns a list of arguments that, passed to this class' constructor,
62 will produce a clone of this algebra pattern.
63  
64 =cut
65  
66 1 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
67 1 my $self = shift;
68 1 return ($self->patterns);
69 }
70  
71 =item C<< patterns >>
72  
73 Returns a list of patterns belonging to this sequence.
74  
75 =cut
76  
77 2 ▶sub patterns {
Subroutine patterns: called CC=1 SCAR=0.0
Pod documented
78 2 my $self = shift;
79 2 return @$self;
80 }
81  
82 =item C<< sse >>
83  
84 Returns the SSE string for this algebra expression.
85  
86 =cut
87  
88 1 ▶sub sse {
Subroutine sse: called CC=3 SCAR=11.2
Pod documented
89 1 my $self = shift;
90 1 my $context = shift;
91 1 ▶ my $prefix = shift || '';
Condition50%1/2
shift() || ''
l!l
01
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
92 1 ▶ my $indent = $context->{indent} || ' ';
Condition50%1/2
$context->{'indent'} || ' '
l!l
10
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table50%1/2
A
A= $context->{'indent'}
Aresult
11
00
93
94 1 my @patterns = map { $_->sse( $context ) } $self->patterns;
95 1 return sprintf(
96 "(sequence\n${prefix}${indent}%s\n${prefix})",
97 join("\n${prefix}${indent}", @patterns)
98 );
99 }
100  
101 =item C<< as_sparql >>
102  
103 Returns the SPARQL string for this algebra expression.
104  
105 =cut
106  
107 0 ▶sub as_sparql {
Subroutine as_sparql: not called CC=4 SCAR=30.0
Pod documented
108 0 my $self = shift;
109 0 ▶ if (exists $AS_SPARQL{ refaddr( $self ) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $AS_SPARQL{builtin::refaddr($self)}) { } 0 0 0
110 0 return $AS_SPARQL{ refaddr( $self ) };
111 } else {
112 0 my $context = shift;
113 # if (ref($context)) {
114 # $context = { %$context };
115 # }
116 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
117 0 my @patterns;
118 0 foreach my $t ($self->patterns) {
119 0 push(@patterns, $t->as_sparql( $context, $indent ));
120 }
121 0 my $string = join(" ;\n${indent}", @patterns);
122 0 $AS_SPARQL{ refaddr( $self ) } = $string;
123 0 return $string;
124 }
125 }
126  
127 =item C<< as_hash >>
128  
129 Returns the query as a nested set of plain data structures (no objects).
130  
131 =cut
132  
133 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
134 0 my $self = shift;
135 0 my $context = shift;
136 return {
137 type => lc($self->type),
138 0 patterns => [ map { $_->as_hash } $self->patterns ],
139 };
140 }
141  
142 =item C<< type >>
143  
144 Returns the type of this algebra expression.
145  
146 =cut
147  
148 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
149 0 return 'SEQUENCE';
150 }
151  
152 =item C<< referenced_variables >>
153  
154 Returns a list of the variable names used in this algebra expression.
155  
156 =cut
157  
158 0 ▶sub referenced_variables {
Subroutine referenced_variables: not called CC=1 SCAR=6.9
Pod documented
159 0 my $self = shift;
160 0 return RDF::Query::_uniq(map { $_->referenced_variables } $self->patterns);
161 }
162  
163 =item C<< potentially_bound >>
164  
165 Returns a list of the variable names used in this algebra expression that will
166 bind values during execution.
167  
168 =cut
169  
170 0 ▶sub potentially_bound {
Subroutine potentially_bound: not called CC=1 SCAR=6.9
Pod documented
171 0 my $self = shift;
172 0 my @patterns = $self->patterns;
173 0 return $patterns[ $#patterns ]->potentially_bound;
174 }
175  
176 =item C<< definite_variables >>
177  
178 Returns a list of the variable names that will be bound after evaluating this algebra expression.
179  
180 =cut
181  
182 0 ▶sub definite_variables {
Subroutine definite_variables: not called CC=1 SCAR=6.9
Pod documented
183 0 my $self = shift;
184 0 my @patterns = $self->patterns;
185 0 return $patterns[ $#patterns ]->potentially_bound;
186 }
187  
188 =item C<< clone >>
189  
190 =cut
191  
192 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
193 0 my $self = shift;
194 0 my $class = ref($self);
195 0 return $class->new( map { $_->clone } $self->patterns );
196 }
197  
198 =item C<< bind_variables ( \%bound ) >>
199  
200 Returns a new algebra pattern with variables named in %bound replaced by their corresponding bound values.
201  
202 =cut
203  
204 0 ▶sub bind_variables {
Subroutine bind_variables: not called CC=1 SCAR=6.9
Pod documented
205 0 my $self = shift;
206 0 my $class = ref($self);
207 0 my $bound = shift;
208 0 return $class->new( map { $_->bind_variables( $bound ) } $self->patterns );
209 }
210  
211 =item C<< check_duplicate_blanks >>
212  
213 Returns true if blank nodes respect the SPARQL rule of no blank-label re-use
214 across BGPs, otherwise throws a RDF::Query::Error::QueryPatternError exception.
215  
216 =cut
217  
218 1 ▶sub check_duplicate_blanks {
Subroutine check_duplicate_blanks: called CC=7 SCAR=27.8
Pod documented
219 1 my $self = shift;
220 1 my @data;
221 1 ▶ foreach my $arg (grep { blessed($_) and $_->isa('RDF::Query::Algebra::Update') and $_->data_only } $self->construct_args) {
Condition33%2/6
builtin::blessed($_) && $_->isa('RDF::Query::Algebra::Update') && $_->data_only
!ll&&!rl&&r
200
builtin::blessed($_) and $_->isa("RDF::Query::Algebra::Update")
!ll&&!rl&&r
020
MC/DC0%0/3
builtin::blessed($_) && $_->isa('RDF::Query::Algebra::Update') && $_->data_only
builtin::blessed($_) $_->isa("RDF::Query::Algebra::Update") $_->data_only
Truth table25%1/4
A and B && C
A= builtin::blessed($_)B= $_->isa("RDF::Query::Algebra::Update")C= $_->data_only
ABCresult
0XX0
10X0
1100
1111
222 0 push(@data, [$arg, $arg->_referenced_blanks()]);
223 }
224
225 1 my %seen;
226 1 foreach my $d (@data) {
227 0 my ($pat, $data) = @$d;
228 0 foreach my $b (@$data) {
229 0 ▶ if ($seen{ $b }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen{$b}) 0 0 0
230 0 throw RDF::Query::Error::QueryPatternError -text => "Same blank node identifier ($b) used in more than one BasicGraphPattern.";
231 }
232 0 $seen{ $b } = $pat;
233 }
234 }
235
236 1 return 1;
237 }
238  
239 0 ▶sub _referenced_blanks {
Subroutine _referenced_blanks: not called CC=4 SCAR=30.0
240 0 my $self = shift;
241 0 my @data;
242 0 foreach my $arg ($self->pattern) {
243 0 ▶ if (blessed($arg) and $arg->isa('RDF::Query::Algebra')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->isa("RDF::Query::Algebra")) 0 0 0
Condition0%0/3
builtin::blessed($arg) and $arg->isa("RDF::Query::Algebra")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($arg) and $arg->isa("RDF::Query::Algebra")
builtin::blessed($arg) $arg->isa("RDF::Query::Algebra")
Truth table0%0/3
A and B
A= builtin::blessed($arg)B= $arg->isa("RDF::Query::Algebra")
ABresult
0X0
100
111
244 0 push( @data, $arg->_referenced_blanks );
245 }
246 }
247 0 return @data;
248 }
249  
250 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
251 1 my $self = shift;
252 1 delete $AS_SPARQL{ refaddr( $self ) };
253 }
254  
255 36 1;
256  
257 __END__
« Query/Plan/Construct.pm ↑ Summary Query/Plan/BasicGraphPattern.pm »