File Coverage

blib/lib/RDF/Query/Plan/Iterator.pm
Criterion Covered Total %
statement 13 51 25.4
branch 0 12 0.0
condition 0 6 0.0
subroutine 5 14 35.7
pod 9 9 100.0
total 27 92 29.3


line stmt bran cond sub pod time code
1             # RDF::Query::Plan::Iterator
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::Plan::Iterator - Executable query plan for result-generating iterators.
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::Plan::Iterator version 2.918.
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::Iterator;
22              
23 35     35   129 use strict;
  35         54  
  35         824  
24 35     35   125 use warnings;
  35         46  
  35         838  
25 35     35   118 use base qw(RDF::Query::Plan);
  35         44  
  35         2023  
26              
27 35     35   156 use Scalar::Util qw(blessed reftype);
  35         59  
  35         1951  
28              
29             ######################################################################
30              
31             our ($VERSION);
32             BEGIN {
33 35     35   12107 $VERSION = '2.918';
34             }
35              
36             ######################################################################
37              
38             =item C<< new ( $iter, \&execute_cb ) >>
39              
40             =item C<< new ( \&create_iterator_cb ) >>
41              
42             =cut
43              
44             sub new {
45 0     0 1   my $class = shift;
46 0           my $iter = shift;
47 0           my $cb = shift;
48 0           my $self = $class->SUPER::new( $iter, $cb );
49 0           $self->[0]{referenced_variables} = [];
50 0           return $self;
51             }
52              
53             =item C<< execute ( $execution_context ) >>
54              
55             =cut
56              
57             sub execute ($) {
58 0     0 1   my $self = shift;
59 0           my $context = shift;
60 0           $self->[0]{delegate} = $context->delegate;
61 0 0         if ($self->state == $self->OPEN) {
62 0           throw RDF::Query::Error::ExecutionError -text => "ITERATOR plan can't be executed while already open";
63             }
64            
65 0 0         if (ref($self->[2])) {
66 0           $self->[2]->( $context );
67             }
68            
69             # if we don't have an actual iterator, but only a promise of one, construct it now
70 0 0 0       if (reftype($self->[1]) eq 'CODE' and not(blessed($self->[1]) and $self->[1]->isa('RDF::Trine::Iterator'))) {
      0        
71 0           $self->[1] = $self->[1]->( $context );
72             }
73            
74 0           $self->state( $self->OPEN );
75 0           $self;
76             }
77              
78             =item C<< next >>
79              
80             =cut
81              
82             sub next {
83 0     0 1   my $self = shift;
84 0 0         unless ($self->state == $self->OPEN) {
85 0           throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open ITERATOR";
86             }
87 0           my $iter = $self->[1];
88 0           my $bindings = $iter->next;
89 0 0         if (my $d = $self->delegate) {
90 0           $d->log_result( $self, $bindings );
91             }
92 0           return $bindings;
93             }
94              
95             =item C<< close >>
96              
97             =cut
98              
99             sub close {
100 0     0 1   my $self = shift;
101 0 0         unless ($self->state == $self->OPEN) {
102 0           throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open ITERATOR";
103             }
104 0           my $iter = $self->[1];
105 0           $iter->close;
106 0           $self->SUPER::close();
107             }
108              
109             =item C<< distinct >>
110              
111             Returns true if the pattern is guaranteed to return distinct results.
112              
113             =cut
114              
115             sub distinct {
116 0     0 1   return 0;
117             }
118              
119             =item C<< ordered >>
120              
121             Returns true if the pattern is guaranteed to return ordered results.
122              
123             =cut
124              
125             sub ordered {
126 0     0 1   return [];
127             }
128              
129             =item C<< plan_node_name >>
130              
131             Returns the string name of this plan node, suitable for use in serialization.
132              
133             =cut
134              
135             sub plan_node_name {
136 0     0 1   return 'optimized-iterator';
137             }
138              
139             =item C<< plan_prototype >>
140              
141             Returns a list of scalar identifiers for the type of the content (children)
142             nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
143             identifiers.
144              
145             =cut
146              
147             sub plan_prototype {
148 0     0 1   my $self = shift;
149 0           return qw();
150             }
151              
152             =item C<< plan_node_data >>
153              
154             Returns the data for this plan node that corresponds to the values described by
155             the signature returned by C<< plan_prototype >>.
156              
157             =cut
158              
159             sub plan_node_data {
160 0     0 1   my $self = shift;
161 0           return;
162             }
163              
164             1;
165              
166             __END__
167              
168             =back
169              
170             =head1 AUTHOR
171              
172             Gregory Todd Williams <gwilliams@cpan.org>
173              
174             =cut