Query/Plan/Offset.pm

filter: Statementstmt 73.6% 53 / 72 Branchbran 61.1% 11 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 12 / 16 Podpod 100% 12 / 12 totaltotal 74.5% 88 / 118 CC 10 SCAR 11.2
CC
10
Cov
71%
next
5.6
execute
5.5
close
2.1
CRAP 3.1
« Query/Functions/Geo.pm ↑ Summary Query/Algebra/Minus.pm »
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.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::Offset;
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 ( $plan, $offset ) >>
37  
38 =cut
39  
40 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
41 3 my $class = shift;
42 3 my $offset = shift;
43 3 my $plan = shift;
44 3 my $self = $class->SUPER::new( $offset, $plan );
45 3 $self->[0]{referenced_variables} = [ $plan->referenced_variables ];
46 3 return $self;
47 }
48  
49 =item C<< execute ( $execution_context ) >>
50  
51 =cut
52  
53 3 ▶sub execute ($) {
Subroutine execute: called CC=5 SCAR=17.1
Pod documented
54 3 my $self = shift;
55 3 my $context = shift;
56 3 $self->[0]{delegate} = $context->delegate;
57 3 ▶ if ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state == $self->OPEN) 0 3 3
58 0 throw RDF::Query::Error::ExecutionError -text => "OFFSET plan can't be executed while already open";
59 }
60 3 my $plan = $self->[2];
61 3 $self->[0]{exhausted} = 0;
62 3 $plan->execute( $context );
63  
64 3 ▶ if ($plan->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->state == $self->OPEN) { } 3 0 3
65 3 $self->state( $self->OPEN );
66 3 ▶ for (my $i = 0; $i < $self->offset; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->offset) 4 3 7
67 4 my $row = $plan->next;
68 4 ▶ if(not(defined($row))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $row) 0 4 4
69 0 $self->[0]{exhausted} = 1;
70 0 last;
71 }
72 }
73 } else {
74 0 warn "could not execute plan in OFFSET";
75 }
76 3 $self;
77 }
78  
79 =item C<< next >>
80  
81 =cut
82  
83 6 ▶sub next {
Subroutine next: called CC=5 SCAR=17.2
Pod documented
84 6 my $self = shift;
85 6 ▶ if ($self->[0]{exhausted}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[0]{"exhausted"}) 0 6 6
86 0 return undef;
87 }
88 6 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 6 6
89 0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open OFFSET";
90 }
91 6 my $plan = $self->[2];
92 6 my $row = $plan->next;
93 6 ▶ unless ($row) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($row) 3 3 6
94 3 $self->[0]{exhausted} = 1;
95 3 return undef;
96 }
97 3 ▶ if (my $d = $self->delegate) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->delegate) 0 3 3
98 0 $d->log_result( $self, $row );
99 }
100 3 return $row;
101 }
102  
103 =item C<< close >>
104  
105 =cut
106  
107 3 ▶sub close {
Subroutine close: called CC=2 SCAR=7.4
Pod documented
108 3 my $self = shift;
109 3 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 3 3
110 0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open OFFSET";
111 }
112 3 $self->[2]->close();
113 3 $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 6 ▶sub pattern {
Subroutine pattern: called CC=1 SCAR=0.0
Pod documented
123 6 my $self = shift;
124 6 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 7 ▶sub offset {
Subroutine offset: called CC=1 SCAR=0.0
Pod documented
134 7 my $self = shift;
135 7 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 3 ▶sub distinct {
Subroutine distinct: called CC=1 SCAR=0.0
Pod documented
145 3 my $self = shift;
146 3 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 3 ▶sub ordered {
Subroutine ordered: called CC=1 SCAR=0.0
Pod documented
156 3 my $self = shift;
157 3 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 0 ▶sub plan_node_name {
Subroutine plan_node_name: not called CC=1 SCAR=6.9
Pod documented
167 0 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 0 ▶sub plan_prototype {
Subroutine plan_prototype: not called CC=1 SCAR=6.9
Pod documented
179 0 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 0 ▶sub plan_node_data {
Subroutine plan_node_data: not called CC=1 SCAR=6.9
Pod documented
191 0 my $self = shift;
192 0 return ($self->offset, $self->pattern);
193 }
194  
195 =item C<< graph ( $g ) >>
196  
197 =cut
198  
199 0 ▶sub graph {
Subroutine graph: not called CC=1 SCAR=6.9
Pod documented
200 0 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 35 1;
210  
211 __END__
« Query/Functions/Geo.pm ↑ Summary Query/Algebra/Minus.pm »