Query/Plan/BasicGraphPattern.pm

filter: Statementstmt 92.2% 95 / 103 Branchbran 58.8% 20 / 34 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 9 / 9 totaltotal 82.4% 141 / 171 CC 22 SCAR 20.1
CC
22
Cov
82%
next
13.2
execute
11.4
new
3.0
CRAP 7.4
« Query/Algebra/Sequence.pm ↑ Summary Query/Algebra/Clear.pm »
1 # RDF::Query::Plan::BasicGraphPattern
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Plan::BasicGraphPattern - Executable query plan for BasicGraphPatterns.
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Plan::BasicGraphPattern version 2.919.
11  
12 =head1 METHODS
13  
14 Beyond the methods documented below, this class inherits methods from the
15 L<RDF::Query::Plan> class.
16  
17 =over 4
18  
19 =cut
20  
21 package RDF::Query::Plan::BasicGraphPattern;
22  
23 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 35 ▶use base qw(RDF::Query::Plan);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 35 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 35 ▶use RDF::Trine::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 ######################################################################
31  
32 35 our ($VERSION);
33 35 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 35 $VERSION = '2.919';
35 }
36  
37 ######################################################################
38  
39 =item C<< new ( @triples ) >>
40  
41 =cut
42  
43 76 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
44 76 my $class = shift;
45 my @triples = map {
46 76 my @nodes = $_->nodes;
47 206 ▶ $nodes[3] ||= RDF::Trine::Node::Nil->new();
Condition33%1/3
$nodes[3] ||= "RDF::Trine::Node::Nil"->new
l!l&&r!l&&!r
20600
MC/DC0%0/2
$nodes[3] ||= "RDF::Trine::Node::Nil"->new
$nodes[3] "RDF::Trine::Node::Nil"->new
Truth table33%1/3
A ||= B
A= $nodes[3]B= "RDF::Trine::Node::Nil"->new
ABresult
1X1
011
000
48 206 ▶ (scalar(@nodes) == 4)
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodes == 4 ? : 206 0 206
49 ? RDF::Trine::Statement::Quad->new( @nodes )
50 : RDF::Trine::Statement->new( @nodes )
51 } @_;
52 76 my @vars = map { $_->name } grep { $_->isa('RDF::Trine::Node::Variable') } map { $_->nodes } @triples;
53 76 my @uvars = keys %{ { map { $_ => 1 } @vars } };
54 76 my $self = $class->SUPER::new( \@triples );
55 76 $self->[0]{referenced_variables} = \@uvars;
56 76 return $self;
57 }
58  
59 =item C<< execute ( $execution_context ) >>
60  
61 =cut
62  
63 78 ▶sub execute ($) {
Subroutine execute: called CC=11 SCAR=24.3
Pod documented
64 78 my $self = shift;
65 78 my $context = shift;
66 78 $self->[0]{delegate} = $context->delegate;
67 78 ▶ if ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state == $self->OPEN) 0 78 78
68 0 throw RDF::Query::Error::ExecutionError -text => "BGP plan can't be executed twice";
69 }
70
71 78 my $l = Log::Log4perl->get_logger("rdf.query.plan.basicgraphpattern");
72 78 $l->trace( "executing RDF::Query::Plan::BasicGraphPattern" );
73
74 78 my @bound_triples;
75 78 my $bound = $context->bound;
76 78 ▶ if (%$bound) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$bound) { } 5 73 78
77 5 $self->[0]{bound} = $bound;
78 5 my @triples = @{ $self->[1] };
79 5 foreach my $j (0 .. $#triples) {
80 10 my @nodes = $triples[$j]->nodes;
81 10 foreach my $i (0 .. $#nodes) {
82 40 ▶ next unless ($nodes[$i]->isa('RDF::Trine::Node::Variable'));
Branch: 1 branch
BranchTrueFalseTotal
unless $nodes[$i]->isa("RDF::Trine::Node::Variable") 14 26 40
83 26 ▶ next unless (blessed($bound->{ $nodes[$i]->name }));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($$bound{$nodes[$i]->name}) 17 9 26
84 # warn "pre-bound variable found: " . $nodes[$i]->name;
85 9 $nodes[$i] = $bound->{ $nodes[$i]->name };
86 }
87 10 ▶ my $triple = (scalar(@nodes) == 4)
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodes == 4 ? : 10 0 10
88 ? RDF::Trine::Statement::Quad->new( @nodes )
89 : RDF::Trine::Statement->new( @nodes );
90 10 push(@bound_triples, $triple);
91 }
92 } else {
93 73 @bound_triples = @{ $self->[1] };
94 }
95
96 78 ▶ my @tmp = grep { $_->isa('RDF::Trine::Statement::Quad') and $_->context->isa('RDF::Trine::Node::Variable') } @bound_triples;
Condition33%1/3
$_->isa('RDF::Trine::Statement::Quad') && $_->context->isa('RDF::Trine::Node::Variable')
!ll&&!rl&&r
02100
MC/DC0%0/2
$_->isa('RDF::Trine::Statement::Quad') && $_->context->isa('RDF::Trine::Node::Variable')
$_->isa('RDF::Trine::Statement::Quad') $_->context->isa('RDF::Trine::Node::Variable')
Truth table33%1/3
A && B
A= $_->isa('RDF::Trine::Statement::Quad')B= $_->context->isa('RDF::Trine::Node::Variable')
ABresult
0X0
100
111
97 78 ▶ my $quad = scalar(@tmp) ? $tmp[0]->context : undef;
Branch: 1 branch
BranchTrueFalseTotal
scalar @tmp ? : 0 78 78
98
99 78 my $model = $context->model;
100 78 my $pattern = RDF::Trine::Pattern->new( @bound_triples );
101 78 $l->trace( "BGP: " . $pattern->sse );
102 78 my $iter = $model->get_pattern( $pattern );
103
104 78 ▶ if (blessed($iter)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($iter)) { } 78 0 78
105 78 $self->[0]{iter} = $iter;
106 78 $self->[0]{quad} = $quad;
107 78 $self->[0]{nil} = RDF::Trine::Node::Nil->new();
108 78 $self->state( $self->OPEN );
109 } else {
110 0 warn "no iterator in execute()";
111 }
112 78 $self;
113 }
114  
115 =item C<< next >>
116  
117 =cut
118  
119 254 ▶sub next {
Subroutine next: called CC=9 SCAR=25.8
Pod documented
120 254 my $self = shift;
121 254 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 254 254
122 0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open BGP";
123 }
124
125 254 my $q = $self->[0]{quad};
126
127 254 my $iter = $self->[0]{iter};
128 254 ▶ return undef unless ($iter);
Branch: 1 branch
BranchTrueFalseTotal
unless $iter 0 254 254
129 254 ▶ while (ref(my $row = $iter->next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $row = $iter->next)) 192 62 254
130 192 ▶ if (ref(my $bound = $self->[0]{bound})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $bound = $self->[0]{"bound"})) 4 188 192
131 4 @{ $row }{ keys %$bound } = values %$bound;
132 }
133 192 ▶ if (blessed($q)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($q)) 0 192 192
134 # skip results when we were matching over variable named graphs (GRAPH ?g {...})
135 # and where the graph variable is bound to the nil node
136 # (the nil node is used to represent the default graph, which should never match inside a GRAPH block).
137 0 my $node = $row->{ $q->name };
138 0 ▶ if (blessed($node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node)) 0 0 0
139 0 ▶ next if ($node->isa('RDF::Trine::Node::Nil'));
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("RDF::Trine::Node::Nil") 0 0 0
140 }
141 }
142 192 my $result = RDF::Query::VariableBindings->new( $row );
143 192 ▶ if (my $d = $self->delegate) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->delegate) 0 192 192
144 0 $d->log_result( $self, $result );
145 }
146 192 return $result;
147 }
148 62 return;
149 }
150  
151 =item C<< close >>
152  
153 =cut
154  
155 78 ▶sub close {
Subroutine close: called CC=2 SCAR=7.4
Pod documented
156 78 my $self = shift;
157 78 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 78 78
158 0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open BGP";
159 }
160
161 78 delete $self->[0]{iter};
162 78 $self->SUPER::close();
163 }
164  
165 =item C<< distinct >>
166  
167 Returns true if the pattern is guaranteed to return distinct results.
168  
169 =cut
170  
171 59 ▶sub distinct {
Subroutine distinct: called CC=1 SCAR=0.0
Pod documented
172 59 return 0;
173 }
174  
175 =item C<< ordered >>
176  
177 Returns true if the pattern is guaranteed to return ordered results.
178  
179 =cut
180  
181 44 ▶sub ordered {
Subroutine ordered: called CC=1 SCAR=0.0
Pod documented
182 44 return [];
183 }
184  
185 =item C<< plan_node_name >>
186  
187 Returns the string name of this plan node, suitable for use in serialization.
188  
189 =cut
190  
191 25 ▶sub plan_node_name {
Subroutine plan_node_name: called CC=1 SCAR=0.0
Pod documented
192 25 return 'bgp';
193 }
194  
195 =item C<< plan_prototype >>
196  
197 Returns a list of scalar identifiers for the type of the content (children)
198 nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
199 identifiers.
200  
201 =cut
202  
203 25 ▶sub plan_prototype {
Subroutine plan_prototype: called CC=1 SCAR=0.0
Pod documented
204 25 my $self = shift;
205 25 return qw(*T);
206 }
207  
208 =item C<< plan_node_data >>
209  
210 Returns the data for this plan node that corresponds to the values described by
211 the signature returned by C<< plan_prototype >>.
212  
213 =cut
214  
215 26 ▶sub plan_node_data {
Subroutine plan_node_data: called CC=1 SCAR=0.0
Pod documented
216 26 my $self = shift;
217 26 my @triples = @{ $self->[1] };
218 26 return @triples;
219 }
220  
221 35 1;
222  
223 __END__
« Query/Algebra/Sequence.pm ↑ Summary Query/Algebra/Clear.pm »