File Coverage

blib/lib/RDF/Query/Plan/Limit.pm
Criterion Covered Total %
statement 53 65 81.5
branch 9 14 64.2
condition n/a
subroutine 15 16 93.7
pod 12 12 100.0
total 89 107 83.1


line stmt bran cond sub pod time code
1             # RDF::Query::Plan::Limit
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::Plan::Limit - Executable query plan for Limits.
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::Plan::Limit 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::Limit;
22              
23 35     35   124 use strict;
  35         45  
  35         811  
24 35     35   108 use warnings;
  35         39  
  35         750  
25 35     35   111 use base qw(RDF::Query::Plan);
  35         43  
  35         2460  
26              
27             ######################################################################
28              
29             our ($VERSION);
30             BEGIN {
31 35     35   16416 $VERSION = '2.918';
32             }
33              
34             ######################################################################
35              
36             =item C<< new ( $plan, $limit ) >>
37              
38             =cut
39              
40             sub new {
41 8     8 1 12 my $class = shift;
42 8         15 my $limit = shift;
43 8         12 my $plan = shift;
44 8         42 my $self = $class->SUPER::new( $limit, $plan );
45 8         33 $self->[0]{referenced_variables} = [ $plan->referenced_variables ];
46 8         30 return $self;
47             }
48              
49             =item C<< execute ( $execution_context ) >>
50              
51             =cut
52              
53             sub execute ($) {
54 8     8 1 11 my $self = shift;
55 8         14 my $context = shift;
56 8         36 $self->[0]{delegate} = $context->delegate;
57 8 50       50 if ($self->state == $self->OPEN) {
58 0         0 throw RDF::Query::Error::ExecutionError -text => "LIMIT plan can't be executed while already open";
59             }
60 8         24 my $plan = $self->[2];
61 8         38 $plan->execute( $context );
62              
63 8 50       22 if ($plan->state == $self->OPEN) {
64 8         32 $self->state( $self->OPEN );
65 8         17 $self->[0]{count} = 0;
66             } else {
67 0         0 warn "could not execute plan in LIMIT";
68             }
69 8         23 $self;
70             }
71              
72             =item C<< next >>
73              
74             =cut
75              
76             sub next {
77 19     19 1 29 my $self = shift;
78 19 50       48 unless ($self->state == $self->OPEN) {
79 0         0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open LIMIT";
80             }
81 19 100       56 return undef if ($self->[0]{count} >= $self->limit);
82 12         21 my $plan = $self->[2];
83 12         44 my $row = $plan->next;
84 12 100       75 return undef unless ($row);
85 11         21 $self->[0]{count}++;
86 11 50       45 if (my $d = $self->delegate) {
87 0         0 $d->log_result( $self, $row );
88             }
89 11         32 return $row;
90             }
91              
92             =item C<< close >>
93              
94             =cut
95              
96             sub close {
97 8     8 1 15 my $self = shift;
98 8 50       25 unless ($self->state == $self->OPEN) {
99 0         0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open LIMIT";
100             }
101 8         15 delete $self->[0]{count};
102 8         39 $self->[2]->close();
103 8         36 $self->SUPER::close();
104             }
105              
106             =item C<< pattern >>
107              
108             Returns the query plan that will be used to produce the data to be filtered.
109              
110             =cut
111              
112             sub pattern {
113 17     17 1 22 my $self = shift;
114 17         66 return $self->[2];
115             }
116              
117             =item C<< limit >>
118              
119             Returns the limit size.
120              
121             =cut
122              
123             sub limit {
124 22     22 1 21 my $self = shift;
125 22         88 return $self->[1];
126             }
127              
128             =item C<< distinct >>
129              
130             Returns true if the pattern is guaranteed to return distinct results.
131              
132             =cut
133              
134             sub distinct {
135 7     7 1 13 my $self = shift;
136 7         24 return $self->pattern->distinct;
137             }
138              
139             =item C<< ordered >>
140              
141             Returns true if the pattern is guaranteed to return ordered results.
142              
143             =cut
144              
145             sub ordered {
146 7     7 1 12 my $self = shift;
147 7         15 return $self->pattern->ordered;
148             }
149              
150             =item C<< plan_node_name >>
151              
152             Returns the string name of this plan node, suitable for use in serialization.
153              
154             =cut
155              
156             sub plan_node_name {
157 2     2 1 4 return 'limit';
158             }
159              
160             =item C<< plan_prototype >>
161              
162             Returns a list of scalar identifiers for the type of the content (children)
163             nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
164             identifiers.
165              
166             =cut
167              
168             sub plan_prototype {
169 2     2 1 3 my $self = shift;
170 2         6 return qw(i P);
171             }
172              
173             =item C<< plan_node_data >>
174              
175             Returns the data for this plan node that corresponds to the values described by
176             the signature returned by C<< plan_prototype >>.
177              
178             =cut
179              
180             sub plan_node_data {
181 3     3 1 3 my $self = shift;
182 3         11 return ($self->limit, $self->pattern);
183             }
184              
185             =item C<< graph ( $g ) >>
186              
187             =cut
188              
189             sub graph {
190 0     0 1   my $self = shift;
191 0           my $g = shift;
192 0           my $c = $self->pattern->graph( $g );
193 0           my $limit = $self->limit;
194 0           $g->add_node( "$self", label => "Limit ($limit)" . $self->graph_labels );
195 0           $g->add_edge( "$self", $c );
196 0           return "$self";
197             }
198              
199              
200             1;
201              
202             __END__
203              
204             =back
205              
206             =head1 AUTHOR
207              
208             Gregory Todd Williams <gwilliams@cpan.org>
209              
210             =cut