File Coverage

blib/lib/RDF/Query/Plan/Constant.pm
Criterion Covered Total %
statement 46 63 73.0
branch 7 14 50.0
condition 0 2 0.0
subroutine 13 16 81.2
pod 12 12 100.0
total 78 107 72.9


line stmt bran cond sub pod time code
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.916.
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     35   190 use strict;
  35         84  
  35         898  
24 35     35   188 use warnings;
  35         88  
  35         967  
25 35     35   188 use base qw(RDF::Query::Plan);
  35         70  
  35         3258  
26              
27             ######################################################################
28              
29             our ($VERSION);
30             BEGIN {
31 35     35   22655 $VERSION = '2.916';
32             }
33              
34             ######################################################################
35              
36             =item C<< new ( @variable_bindings ) >>
37              
38             =cut
39              
40             sub new {
41 21     21 1 45 my $class = shift;
42 21         58 my @binds = @_;
43 21         149 my $self = $class->SUPER::new( \@binds );
44 21         47 $self->[0]{referenced_variables} = [ keys %{ $binds[0] } ];
  21         240  
45 21         81 return $self;
46             }
47              
48             =item C<< execute ( $execution_context ) >>
49              
50             =cut
51              
52             sub execute ($) {
53 35     35 1 60 my $self = shift;
54 35         56 my $context = shift;
55 35         110 $self->[0]{delegate} = $context->delegate;
56 35 50       154 if ($self->state == $self->OPEN) {
57 0         0 throw RDF::Query::Error::ExecutionError -text => "CONSTANT plan can't be executed while already open";
58             }
59            
60 35         88 $self->[0]{'index'} = 0;
61 35         141 $self->state( $self->OPEN );
62 35         150 $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             sub bindings {
72 0     0 1 0 my $self = shift;
73 0   0     0 my $binds = $self->[1] || [];
74 0         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             sub is_unit {
84 0     0 1 0 my $self = shift;
85 0         0 my @binds = $self->bindings;
86 0 0       0 return 0 unless scalar(@binds) == 1;
87 0         0 my @keys = keys %{ $binds[0] };
  0         0  
88 0         0 return not(scalar(@keys));
89             }
90              
91             =item C<< next >>
92              
93             =cut
94              
95             sub next {
96 69     69 1 229 my $self = shift;
97 69 50       211 unless ($self->state == $self->OPEN) {
98 0         0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open CONSTANT";
99             }
100 69         158 my $binds = $self->[1];
101 69 100       123 if ($self->[0]{'index'} > $#{ $binds }) {
  69         199  
102 30         114 return;
103             }
104 39         118 my $row = $binds->[ $self->[0]{'index'}++ ];
105 39 50       180 if ($row) {
106 39         134 my $bindings = RDF::Query::VariableBindings->new( $row );
107 39 50       160 if (my $d = $self->delegate) {
108 0         0 $d->log_result( $self, $bindings );
109             }
110 39         149 return $bindings;
111             } else {
112 0         0 return;
113             }
114             }
115              
116             =item C<< close >>
117              
118             =cut
119              
120             sub close {
121 31     31 1 63 my $self = shift;
122 31 50       95 unless ($self->state == $self->OPEN) {
123 0         0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open CONSTANT";
124             }
125 31         73 delete $self->[0]{'index'};
126 31         119 $self->SUPER::close();
127             }
128              
129             =item C<< size >>
130              
131             =cut
132              
133             sub size {
134 0     0 1 0 my $self = shift;
135 0         0 return scalar( @{ $self->[1] } );
  0         0  
136             }
137              
138             =item C<< distinct >>
139              
140             Returns true if the pattern is guaranteed to return distinct results.
141              
142             =cut
143              
144             sub distinct {
145             # XXX could check constant data to determine if it's unique
146 12     12 1 51 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             sub ordered {
156             # XXX could check constant data to determine if it's ordered
157 11     11 1 77 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             sub plan_node_name {
167 6     6 1 21 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             sub plan_prototype {
179 6     6 1 16 my $self = shift;
180 6         25 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             sub plan_node_data {
191 9     9 1 15 my $self = shift;
192 9         18 my $binds = $self->[1];
193 9         28 return @$binds;
194             }
195              
196             1;
197              
198             __END__
199              
200             =back
201              
202             =head1 AUTHOR
203              
204             Gregory Todd Williams <gwilliams@cpan.org>
205              
206             =cut