File Coverage

blib/lib/RDF/Query/Plan/Offset.pm
Criterion Covered Total %
statement 51 70 72.8
branch 9 16 56.2
condition n/a
subroutine 12 16 75.0
pod 12 12 100.0
total 84 114 73.6


line stmt bran cond sub pod time code
1             # RDF::Query::Plan::Offset
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::Plan::Offset - Executable query plan for Offsets.
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::Plan::Offset 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::Offset;
22              
23 35     35   125 use strict;
  35         43  
  35         879  
24 35     35   113 use warnings;
  35         44  
  35         800  
25 35     35   114 use base qw(RDF::Query::Plan);
  35         42  
  35         2466  
26              
27             ######################################################################
28              
29             our ($VERSION);
30             BEGIN {
31 35     35   17572 $VERSION = '2.918';
32             }
33              
34             ######################################################################
35              
36             =item C<< new ( $plan, $offset ) >>
37              
38             =cut
39              
40             sub new {
41 3     3 1 4 my $class = shift;
42 3         5 my $offset = shift;
43 3         4 my $plan = shift;
44 3         13 my $self = $class->SUPER::new( $offset, $plan );
45 3         10 $self->[0]{referenced_variables} = [ $plan->referenced_variables ];
46 3         10 return $self;
47             }
48              
49             =item C<< execute ( $execution_context ) >>
50              
51             =cut
52              
53             sub execute ($) {
54 3     3 1 4 my $self = shift;
55 3         5 my $context = shift;
56 3         11 $self->[0]{delegate} = $context->delegate;
57 3 50       14 if ($self->state == $self->OPEN) {
58 0         0 throw RDF::Query::Error::ExecutionError -text => "OFFSET plan can't be executed while already open";
59             }
60 3         7 my $plan = $self->[2];
61 3         6 $self->[0]{exhausted} = 0;
62 3         11 $plan->execute( $context );
63              
64 3 50       11 if ($plan->state == $self->OPEN) {
65 3         13 $self->state( $self->OPEN );
66 3         12 for (my $i = 0; $i < $self->offset; $i++) {
67 4         14 my $row = $plan->next;
68 4 50       15 if(not(defined($row))) {
69 0         0 $self->[0]{exhausted} = 1;
70 0         0 last;
71             }
72             }
73             } else {
74 0         0 warn "could not execute plan in OFFSET";
75             }
76 3         8 $self;
77             }
78              
79             =item C<< next >>
80              
81             =cut
82              
83             sub next {
84 6     6 1 8 my $self = shift;
85 6 50       15 if ($self->[0]{exhausted}) {
86 0         0 return undef;
87             }
88 6 50       17 unless ($self->state == $self->OPEN) {
89 0         0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open OFFSET";
90             }
91 6         10 my $plan = $self->[2];
92 6         17 my $row = $plan->next;
93 6 100       12 unless ($row) {
94 3         5 $self->[0]{exhausted} = 1;
95 3         8 return undef;
96             }
97 3 50       15 if (my $d = $self->delegate) {
98 0         0 $d->log_result( $self, $row );
99             }
100 3         9 return $row;
101             }
102              
103             =item C<< close >>
104              
105             =cut
106              
107             sub close {
108 3     3 1 4 my $self = shift;
109 3 50       7 unless ($self->state == $self->OPEN) {
110 0         0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open OFFSET";
111             }
112 3         15 $self->[2]->close();
113 3         12 $self->SUPER::close();
114             }
115              
116             =item C<< pattern >>
117              
118             Returns the query plan that will be used to produce the data to be offset.
119              
120             =cut
121              
122             sub pattern {
123 6     6 1 6 my $self = shift;
124 6         19 return $self->[2];
125             }
126              
127             =item C<< offset >>
128              
129             Returns the number of results that are discarded as offset.
130              
131             =cut
132              
133             sub offset {
134 7     7 1 14 my $self = shift;
135 7         27 return $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             sub distinct {
145 3     3 1 3 my $self = shift;
146 3         9 return $self->pattern->distinct;
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 3     3 1 4 my $self = shift;
157 3         6 return $self->pattern->ordered;
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 0     0 1   return 'offset';
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 0     0 1   my $self = shift;
180 0           return qw(i P);
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 0     0 1   my $self = shift;
192 0           return ($self->offset, $self->pattern);
193             }
194              
195             =item C<< graph ( $g ) >>
196              
197             =cut
198              
199             sub graph {
200 0     0 1   my $self = shift;
201 0           my $g = shift;
202 0           my $c = $self->pattern->graph( $g );
203 0           $g->add_node( "$self", label => "Offset ($self->[1])" . $self->graph_labels );
204 0           $g->add_edge( "$self", $c );
205 0           return "$self";
206             }
207              
208              
209             1;
210              
211             __END__
212              
213             =back
214              
215             =head1 AUTHOR
216              
217             Gregory Todd Williams <gwilliams@cpan.org>
218              
219             =cut