Query/Plan/SubSelect.pm

filter: Statementstmt 85.1% 86 / 101 Branchbran 55.5% 10 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 82.6% 19 / 23 Podpod 100% 12 / 12 totaltotal 80.5% 128 / 159 CC 11 SCAR 8.5
CC
11
Cov
80%
next
5.3
new
3.2
close
3.1
CRAP 2.3
« Query/Algebra/TimeGraph.pm ↑ Summary Query/Plan/Limit.pm »
1 # RDF::Query::Plan::SubSelect
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Plan::SubSelect - Executable query plan for sub-select queries.
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Plan::SubSelect 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::SubSelect;
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 Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 35 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 35 ▶use Storable qw(store_fd fd_retrieve);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 35 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 35 ▶use RDF::Query::Error qw(:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 35 ▶use RDF::Query::ExecutionContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 35 ▶use RDF::Query::VariableBindings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 ######################################################################
37  
38 35 our ($VERSION);
39 35 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
40 35 $VERSION = '2.919';
41 }
42  
43 ######################################################################
44  
45 =item C<< new ( $query, [ \%logging_keys ] ) >>
46  
47 Returns a new SubSelect query plan object. C<<$query>> is a RDF:Query object
48 representing a SELECT query.
49  
50 =cut
51  
52 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.5
Pod documented
53 1 my $class = shift;
54 1 my $query = shift;
55 1 my $plan = shift;
56 1 ▶ unless (blessed($plan) and $plan->isa('RDF::Query::Plan')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($plan) and $plan->isa("RDF::Query::Plan")) 0 1 1
Condition33%1/3
builtin::blessed($plan) and $plan->isa("RDF::Query::Plan")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($plan) and $plan->isa("RDF::Query::Plan")
builtin::blessed($plan) $plan->isa("RDF::Query::Plan")
Truth table33%1/3
A and B
A= builtin::blessed($plan)B= $plan->isa("RDF::Query::Plan")
ABresult
0X0
100
111
57 0 Carp::confess;
58 }
59 1 my $keys = {};
60 1 my $self = $class->SUPER::new( $query, $plan );
61 1 $self->[0]{referenced_variables} = [ $query->variables ];
62 1 $self->[0]{logging_keys} = $keys;
63 1 return $self;
64 }
65  
66 =item C<< execute ( $execution_context ) >>
67  
68 =cut
69  
70 1 ▶sub execute ($) {
Subroutine execute: called CC=3 SCAR=11.2
Pod documented
71 1 my $self = shift;
72 1 my $context = shift;
73 1 $self->[0]{delegate} = $context->delegate;
74 1 ▶ if ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state == $self->OPEN) 0 1 1
75 0 throw RDF::Query::Error::ExecutionError -text => "SUBSELECT plan can't be executed while already open";
76 }
77 1 my $l = Log::Log4perl->get_logger("rdf.query.plan.subselect");
78 1 $l->trace("executing subselect");
79 1 my $plan = $self->plan;
80 1 $l->trace("subselect plan: " . $plan->sse);
81 1 my $iter = $plan->execute( $context );
82 1 ▶ if ($iter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iter) { } 1 0 1
83 1 $self->[0]{iter} = $iter;
84 1 $self->[0]{'open'} = 1;
85 1 $self->[0]{'count'} = 0;
86 1 $self->[0]{logger} = $context->logger;
87 1 $self->state( $self->OPEN );
88 } else {
89 0 warn "no iterator in execute()";
90 }
91 1 $self;
92 }
93  
94 =item C<< next >>
95  
96 =cut
97  
98 2 ▶sub next {
Subroutine next: called CC=5 SCAR=16.7
Pod documented
99 2 my $self = shift;
100 2 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 2 2
101 0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open SERVICE";
102 }
103 2 my $l = Log::Log4perl->get_logger("rdf.query.plan.subselect");
104 2 ▶ return undef unless ($self->[0]{'open'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[0]{"open"} 0 2 2
105 2 my $iter = $self->[0]{iter};
106 2 my $result = $iter->next;
107
108 2 ▶ return undef unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 1 1 2
109 1 $l->trace("- got subselect result $result");
110 1 $self->[0]{'count'}++;
111 1 my $row = RDF::Query::VariableBindings->new( $result );
112 1 ▶ if (my $d = $self->delegate) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->delegate) 0 1 1
113 0 $d->log_result( $self, $row );
114 }
115 1 return $row;
116 };
117  
118 =item C<< close >>
119  
120 =cut
121  
122 1 ▶sub close {
Subroutine close: called CC=3 SCAR=11.3
Pod documented
123 1 my $self = shift;
124 1 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 1 1
125 0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open SERVICE";
126 }
127 1 my $plan = $self->plan;
128 1 ▶ if (defined($plan)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plan) 1 0 1
129 1 $plan->close();
130 }
131 1 delete $self->[0]{iter};
132 1 delete $self->[0]{args};
133 1 delete $self->[0]{count};
134 1 $self->SUPER::close();
135 }
136  
137 =item C<< query >>
138  
139 Returns the sub-select query object.
140  
141 =cut
142  
143 0 ▶sub query {
Subroutine query: not called CC=1 SCAR=6.9
Pod documented
144 0 my $self = shift;
145 0 return $self->[1];
146 }
147  
148 =item C<< plan >>
149  
150 Returns the sub-select query plan object.
151  
152 =cut
153  
154 4 ▶sub plan {
Subroutine plan: called CC=1 SCAR=0.0
Pod documented
155 4 my $self = shift;
156 4 return $self->[2];
157 }
158  
159 =item C<< distinct >>
160  
161 Returns true if the pattern is guaranteed to return distinct results.
162  
163 =cut
164  
165 0 ▶sub distinct {
Subroutine distinct: not called CC=1 SCAR=6.9
Pod documented
166 0 my $self = shift;
167 # XXX this could be set at construction time, if we want to trust the remote
168 # XXX endpoint to return DISTINCT results (when appropriate).
169 0 return 0;
170 }
171  
172 =item C<< ordered >>
173  
174 Returns true if the pattern is guaranteed to return ordered results.
175  
176 =cut
177  
178 0 ▶sub ordered {
Subroutine ordered: not called CC=1 SCAR=6.9
Pod documented
179 0 my $self = shift;
180 # XXX this could be set at construction time, if we want to trust the remote
181 # XXX endpoint to return ORDERED results (when appropriate).
182 0 return 0;
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 1 ▶sub plan_node_name {
Subroutine plan_node_name: called CC=1 SCAR=0.0
Pod documented
192 1 return 'subselect';
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 1 ▶sub plan_prototype {
Subroutine plan_prototype: called CC=1 SCAR=0.0
Pod documented
204 1 my $self = shift;
205 1 return qw(P);
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 2 ▶sub plan_node_data {
Subroutine plan_node_data: called CC=1 SCAR=0.0
Pod documented
216 2 my $self = shift;
217 2 return ($self->plan);
218 }
219  
220 =item C<< graph ( $g ) >>
221  
222 =cut
223  
224 0 ▶sub graph {
Subroutine graph: not called CC=1 SCAR=6.9
Pod documented
225 0 my $self = shift;
226 0 my $g = shift;
227 0 die "graph is unimplemented for sub-selects";
228 }
229  
230  
231 35 1;
232  
233 __END__
« Query/Algebra/TimeGraph.pm ↑ Summary Query/Plan/Limit.pm »