| 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.915_01. | 
| 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 |  | 177 | use strict; | 
|  | 35 |  |  |  |  | 66 |  | 
|  | 35 |  |  |  |  | 885 |  | 
| 24 | 35 |  |  | 35 |  | 178 | use warnings; | 
|  | 35 |  |  |  |  | 64 |  | 
|  | 35 |  |  |  |  | 922 |  | 
| 25 | 35 |  |  | 35 |  | 169 | use base qw(RDF::Query::Plan); | 
|  | 35 |  |  |  |  | 62 |  | 
|  | 35 |  |  |  |  | 2976 |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | ###################################################################### | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | our ($VERSION); | 
| 30 |  |  |  |  |  |  | BEGIN { | 
| 31 | 35 |  |  | 35 |  | 24171 | $VERSION	= '2.915_01'; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | ###################################################################### | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =item C<< new ( $plan, $limit ) >> | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =cut | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub new { | 
| 41 | 8 |  |  | 8 | 1 | 17 | my $class	= shift; | 
| 42 | 8 |  |  |  |  | 20 | my $limit	= shift; | 
| 43 | 8 |  |  |  |  | 18 | my $plan	= shift; | 
| 44 | 8 |  |  |  |  | 52 | my $self	= $class->SUPER::new( $limit, $plan ); | 
| 45 | 8 |  |  |  |  | 48 | $self->[0]{referenced_variables}	= [ $plan->referenced_variables ]; | 
| 46 | 8 |  |  |  |  | 40 | return $self; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =item C<< execute ( $execution_context ) >> | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =cut | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub execute ($) { | 
| 54 | 8 |  |  | 8 | 1 | 36 | my $self	= shift; | 
| 55 | 8 |  |  |  |  | 14 | my $context	= shift; | 
| 56 | 8 |  |  |  |  | 44 | $self->[0]{delegate}	= $context->delegate; | 
| 57 | 8 | 50 |  |  |  | 62 | 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 |  |  |  |  | 22 | my $plan	= $self->[2]; | 
| 61 | 8 |  |  |  |  | 40 | $plan->execute( $context ); | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 8 | 50 |  |  |  | 31 | if ($plan->state == $self->OPEN) { | 
| 64 | 8 |  |  |  |  | 41 | $self->state( $self->OPEN ); | 
| 65 | 8 |  |  |  |  | 20 | $self->[0]{count}	= 0; | 
| 66 |  |  |  |  |  |  | } else { | 
| 67 | 0 |  |  |  |  | 0 | warn "could not execute plan in LIMIT"; | 
| 68 |  |  |  |  |  |  | } | 
| 69 | 8 |  |  |  |  | 35 | $self; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =item C<< next >> | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =cut | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub next { | 
| 77 | 19 |  |  | 19 | 1 | 69 | my $self	= shift; | 
| 78 | 19 | 50 |  |  |  | 62 | 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 |  |  |  | 63 | return undef if ($self->[0]{count} >= $self->limit); | 
| 82 | 12 |  |  |  |  | 31 | my $plan	= $self->[2]; | 
| 83 | 12 |  |  |  |  | 55 | my $row		= $plan->next; | 
| 84 | 12 | 100 |  |  |  | 93 | return undef unless ($row); | 
| 85 | 11 |  |  |  |  | 33 | $self->[0]{count}++; | 
| 86 | 11 | 50 |  |  |  | 57 | if (my $d = $self->delegate) { | 
| 87 | 0 |  |  |  |  | 0 | $d->log_result( $self, $row ); | 
| 88 |  |  |  |  |  |  | } | 
| 89 | 11 |  |  |  |  | 36 | return $row; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =item C<< close >> | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =cut | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub close { | 
| 97 | 8 |  |  | 8 | 1 | 17 | my $self	= shift; | 
| 98 | 8 | 50 |  |  |  | 31 | 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 |  |  |  |  | 22 | delete $self->[0]{count}; | 
| 102 | 8 |  |  |  |  | 43 | $self->[2]->close(); | 
| 103 | 8 |  |  |  |  | 35 | $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 | 26 | my $self	= shift; | 
| 114 | 17 |  |  |  |  | 72 | 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 | 60 | my $self	= shift; | 
| 125 | 22 |  |  |  |  | 117 | 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 | 15 | my $self	= shift; | 
| 136 | 7 |  |  |  |  | 32 | 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 | 13 | my $self	= shift; | 
| 147 | 7 |  |  |  |  | 20 | 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 | 6 | 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 |  |  |  |  | 11 | 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 | 4 | my $self	= shift; | 
| 182 | 3 |  |  |  |  | 6 | 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 |