| 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.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::Limit; | ||||||||||
| 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, $limit ) >> | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | |||||||||||
| 40 | 8 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | 8 | my $class = shift; | |||||||||
| 42 | 8 | my $limit = shift; | |||||||||
| 43 | 8 | my $plan = shift; | |||||||||
| 44 | 8 | my $self = $class->SUPER::new( $limit, $plan ); | |||||||||
| 45 | 8 | $self->[0]{referenced_variables} = [ $plan->referenced_variables ]; | |||||||||
| 46 | 8 | return $self; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | =item C<< execute ( $execution_context ) >> | ||||||||||
| 50 | |||||||||||
| 51 | =cut | ||||||||||
| 52 | |||||||||||
| 53 | 8 | ▶ | sub execute ($) { | ||||||||
|
Subroutine
execute: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 54 | 8 | my $self = shift; | |||||||||
| 55 | 8 | my $context = shift; | |||||||||
| 56 | 8 | $self->[0]{delegate} = $context->delegate; | |||||||||
| 57 | 8 | ▶ | if ($self->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | throw RDF::Query::Error::ExecutionError -text => "LIMIT plan can't be executed while already open"; | |||||||||
| 59 | } | ||||||||||
| 60 | 8 | my $plan = $self->[2]; | |||||||||
| 61 | 8 | $plan->execute( $context ); | |||||||||
| 62 | |||||||||||
| 63 | 8 | ▶ | if ($plan->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 8 | $self->state( $self->OPEN ); | |||||||||
| 65 | 8 | $self->[0]{count} = 0; | |||||||||
| 66 | } else { | ||||||||||
| 67 | 0 | warn "could not execute plan in LIMIT"; | |||||||||
| 68 | } | ||||||||||
| 69 | 8 | $self; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | =item C<< next >> | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | 19 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||
| 77 | 19 | my $self = shift; | |||||||||
| 78 | 19 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open LIMIT"; | |||||||||
| 80 | } | ||||||||||
| 81 | 19 | ▶ | return undef if ($self->[0]{count} >= $self->limit); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 12 | my $plan = $self->[2]; | |||||||||
| 83 | 12 | my $row = $plan->next; | |||||||||
| 84 | 12 | ▶ | return undef unless ($row); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 11 | $self->[0]{count}++; | |||||||||
| 86 | 11 | ▶ | if (my $d = $self->delegate) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | $d->log_result( $self, $row ); | |||||||||
| 88 | } | ||||||||||
| 89 | 11 | return $row; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | =item C<< close >> | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | 8 | ▶ | sub close { | ||||||||
|
Subroutine
close: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 97 | 8 | my $self = shift; | |||||||||
| 98 | 8 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | 0 | throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open LIMIT"; | |||||||||
| 100 | } | ||||||||||
| 101 | 8 | delete $self->[0]{count}; | |||||||||
| 102 | 8 | $self->[2]->close(); | |||||||||
| 103 | 8 | $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 | 17 | ▶ | sub pattern { | ||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 113 | 17 | my $self = shift; | |||||||||
| 114 | 17 | return $self->[2]; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | =item C<< limit >> | ||||||||||
| 118 | |||||||||||
| 119 | Returns the limit size. | ||||||||||
| 120 | |||||||||||
| 121 | =cut | ||||||||||
| 122 | |||||||||||
| 123 | 22 | ▶ | sub limit { | ||||||||
|
Subroutine
limit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 124 | 22 | my $self = shift; | |||||||||
| 125 | 22 | 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 | 7 | ▶ | sub distinct { | ||||||||
|
Subroutine
distinct: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 135 | 7 | my $self = shift; | |||||||||
| 136 | 7 | 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 | 7 | ▶ | sub ordered { | ||||||||
|
Subroutine
ordered: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 146 | 7 | my $self = shift; | |||||||||
| 147 | 7 | 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 | 2 | ▶ | sub plan_node_name { | ||||||||
|
Subroutine
plan_node_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 157 | 2 | 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 | 2 | ▶ | sub plan_prototype { | ||||||||
|
Subroutine
plan_prototype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 169 | 2 | my $self = shift; | |||||||||
| 170 | 2 | 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 | 3 | ▶ | sub plan_node_data { | ||||||||
|
Subroutine
plan_node_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 181 | 3 | my $self = shift; | |||||||||
| 182 | 3 | return ($self->limit, $self->pattern); | |||||||||
| 183 | } | ||||||||||
| 184 | |||||||||||
| 185 | =item C<< graph ( $g ) >> | ||||||||||
| 186 | |||||||||||
| 187 | =cut | ||||||||||
| 188 | |||||||||||
| 189 | 0 | ▶ | sub graph { | ||||||||
|
Subroutine
graph: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 190 | 0 | 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 | 35 | 1; | |||||||||
| 201 | |||||||||||
| 202 | __END__ | ||||||||||