Query/Plan/Constant.pm

filter: Statementstmt 73.8% 48 / 65 Branchbran 50.0% 7 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 81.2% 13 / 16 Podpod 100% 12 / 12 totaltotal 72.7% 80 / 110 CC 9 SCAR 11.0
CC
9
Cov
68%
bindings
6.0
is_unit
6.0
next
5.5
CRAP 3.0
« Query/Algebra/Minus.pm ↑ Summary Query/VariableBindings.pm »
1 # RDF::Query::Plan::Constant
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Plan::Constant - Executable query plan for Constants.
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Plan::Constant 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::Constant;
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 ######################################################################
28  
29 35 our ($VERSION);
30 35 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 35 $VERSION = '2.919';
32 }
33  
34 ######################################################################
35  
36 =item C<< new ( @variable_bindings ) >>
37  
38 =cut
39  
40 21 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
41 21 my $class = shift;
42 21 my @binds = @_;
43 21 my $self = $class->SUPER::new( \@binds );
44 21 $self->[0]{referenced_variables} = [ keys %{ $binds[0] } ];
45 21 return $self;
46 }
47  
48 =item C<< execute ( $execution_context ) >>
49  
50 =cut
51  
52 35 ▶sub execute ($) {
Subroutine execute: called CC=2 SCAR=7.1
Pod documented
53 35 my $self = shift;
54 35 my $context = shift;
55 35 $self->[0]{delegate} = $context->delegate;
56 35 ▶ if ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state == $self->OPEN) 0 35 35
57 0 throw RDF::Query::Error::ExecutionError -text => "CONSTANT plan can't be executed while already open";
58 }
59
60 35 $self->[0]{'index'} = 0;
61 35 $self->state( $self->OPEN );
62 35 $self;
63 }
64  
65 =item C<< bindings >>
66  
67 Returns a list of the variable bindings for this constant result set.
68  
69 =cut
70  
71 0 ▶sub bindings {
Subroutine bindings: not called CC=2 SCAR=17.9
Pod documented
72 0 my $self = shift;
73 0 ▶ my $binds = $self->[1] || [];
Condition0%0/2
$self->[1] || []
l!l
00
MC/DC0%0/1
$self->[1] || []
$self->[1]
Truth table0%0/2
A
A= $self->[1]
Aresult
11
00
74 0 return @$binds;
75 }
76  
77 =item C<< is_unit >>
78  
79 Returns true if this constant result set is comprised of a single, empty variable binding.
80  
81 =cut
82  
83 0 ▶sub is_unit {
Subroutine is_unit: not called CC=2 SCAR=17.9
Pod documented
84 0 my $self = shift;
85 0 my @binds = $self->bindings;
86 0 ▶ return 0 unless scalar(@binds) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @binds == 1 0 0 0
87 0 my @keys = keys %{ $binds[0] };
88 0 return not(scalar(@keys));
89 }
90  
91 =item C<< next >>
92  
93 =cut
94  
95 69 ▶sub next {
Subroutine next: called CC=5 SCAR=17.1
Pod documented
96 69 my $self = shift;
97 69 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 69 69
98 0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open CONSTANT";
99 }
100 69 my $binds = $self->[1];
101 69 ▶ if ($self->[0]{'index'} > $#{ $binds }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[0]{"index"} > $#{$binds;}) 30 39 69
102 30 return;
103 }
104 39 my $row = $binds->[ $self->[0]{'index'}++ ];
105 39 ▶ if ($row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row) { } 39 0 39
106 39 my $bindings = RDF::Query::VariableBindings->new( $row );
107 39 ▶ if (my $d = $self->delegate) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->delegate) 0 39 39
108 0 $d->log_result( $self, $bindings );
109 }
110 39 return $bindings;
111 } else {
112 0 return;
113 }
114 }
115  
116 =item C<< close >>
117  
118 =cut
119  
120 31 ▶sub close {
Subroutine close: called CC=2 SCAR=7.4
Pod documented
121 31 my $self = shift;
122 31 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 31 31
123 0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open CONSTANT";
124 }
125 31 delete $self->[0]{'index'};
126 31 $self->SUPER::close();
127 }
128  
129 =item C<< size >>
130  
131 =cut
132  
133 0 ▶sub size {
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
134 0 my $self = shift;
135 0 return scalar( @{ $self->[1] } );
136 }
137  
138 =item C<< distinct >>
139  
140 Returns true if the pattern is guaranteed to return distinct results.
141  
142 =cut
143  
144 12 ▶sub distinct {
Subroutine distinct: called CC=1 SCAR=0.0
Pod documented
145 # XXX could check constant data to determine if it's unique
146 12 return 0;
147 }
148  
149 =item C<< ordered >>
150  
151 Returns true if the pattern is guaranteed to return ordered results.
152  
153 =cut
154  
155 11 ▶sub ordered {
Subroutine ordered: called CC=1 SCAR=0.0
Pod documented
156 # XXX could check constant data to determine if it's ordered
157 11 return [];
158 }
159  
160 =item C<< plan_node_name >>
161  
162 Returns the string name of this plan node, suitable for use in serialization.
163  
164 =cut
165  
166 6 ▶sub plan_node_name {
Subroutine plan_node_name: called CC=1 SCAR=0.0
Pod documented
167 6 return 'table';
168 }
169  
170 =item C<< plan_prototype >>
171  
172 Returns a list of scalar identifiers for the type of the content (children)
173 nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
174 identifiers.
175  
176 =cut
177  
178 6 ▶sub plan_prototype {
Subroutine plan_prototype: called CC=1 SCAR=0.0
Pod documented
179 6 my $self = shift;
180 6 return qw(*V);
181 }
182  
183 =item C<< plan_node_data >>
184  
185 Returns the data for this plan node that corresponds to the values described by
186 the signature returned by C<< plan_prototype >>.
187  
188 =cut
189  
190 9 ▶sub plan_node_data {
Subroutine plan_node_data: called CC=1 SCAR=0.0
Pod documented
191 9 my $self = shift;
192 9 my $binds = $self->[1];
193 9 return @$binds;
194 }
195  
196 35 1;
197  
198 __END__
« Query/Algebra/Minus.pm ↑ Summary Query/VariableBindings.pm »