| 1 | # RDF::Query::Plan::NamedGraph | ||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||
| 3 | |||||||||||||
| 4 | =head1 NAME | ||||||||||||
| 5 | |||||||||||||
| 6 | RDF::Query::Plan::NamedGraph - Executable query plan for named graphs. | ||||||||||||
| 7 | |||||||||||||
| 8 | =head1 VERSION | ||||||||||||
| 9 | |||||||||||||
| 10 | This document describes RDF::Query::Plan::NamedGraph 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::NamedGraph; | ||||||||||||
| 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 Scalar::Util qw(blessed); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 35 | ▶ | use base qw(RDF::Query::Plan); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | |||||||||||||
| 28 | ###################################################################### | ||||||||||||
| 29 | |||||||||||||
| 30 | 35 | our ($VERSION); | |||||||||||
| 31 | 35 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 35 | $VERSION = '2.919'; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | ###################################################################### | ||||||||||||
| 36 | |||||||||||||
| 37 | |||||||||||||
| 38 | =item C<< new ( $graph, $plan ) >> | ||||||||||||
| 39 | |||||||||||||
| 40 | =cut | ||||||||||||
| 41 | |||||||||||||
| 42 | 10 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 43 | 10 | my $class = shift; | |||||||||||
| 44 | 10 | my $graph = shift; | |||||||||||
| 45 | 10 | my $plan = shift; | |||||||||||
| 46 | 10 | my $self = $class->SUPER::new( $graph, $plan ); | |||||||||||
| 47 | 10 | $self->[0]{referenced_variables} = [ $plan->referenced_variables ]; | |||||||||||
| 48 | |||||||||||||
| 49 | 10 | my $l = Log::Log4perl->get_logger("rdf.query.plan.namedgraph"); | |||||||||||
| 50 | 10 | $l->trace('constructing named graph plan...'); | |||||||||||
| 51 | 10 | return $self; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | =item C<< execute ( $execution_context ) >> | ||||||||||||
| 55 | |||||||||||||
| 56 | =cut | ||||||||||||
| 57 | |||||||||||||
| 58 | 11 | ▶ | sub execute ($) { | ||||||||||
|
Subroutine
execute: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||
| 59 | 11 | my $self = shift; | |||||||||||
| 60 | 11 | my $context = shift; | |||||||||||
| 61 | 11 | $self->[0]{delegate} = $context->delegate; | |||||||||||
| 62 | 11 | ▶ | if ($self->state == $self->OPEN) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | 0 | throw RDF::Query::Error::ExecutionError -text => "NamedGraph plan can't be executed while already open"; | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 11 | my $l = Log::Log4perl->get_logger("rdf.query.plan.namedgraph"); | |||||||||||
| 67 | 11 | $l->trace('executing named graph plan'); | |||||||||||
| 68 | 11 | my $model = $context->model; | |||||||||||
| 69 | 11 | my $graphs = $model->get_graphs; | |||||||||||
| 70 | 11 | $self->[0]{graphs} = $graphs; | |||||||||||
| 71 | 11 | ▶ | $self->[0]{bound} = $context->bound || {}; | ||||||||||
|
Condition50%1/2
$context->bound || {}
MC/DC0%0/1
$context->bound || {}
$context->bound
Truth table50%1/2
A
A= $context->bound
| |||||||||||||
| 72 | 11 | $self->[0]{context} = $context; | |||||||||||
| 73 | |||||||||||||
| 74 | 11 | ▶ | if (my $g = $self->[0]{graphs}->next) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | 11 | my %bound = %{ $self->[0]{bound} }; | |||||||||||
| 76 | 11 | $bound{ $self->graph->name } = $g; | |||||||||||
| 77 | 11 | my $ctx = $context->copy( bound => \%bound ); | |||||||||||
| 78 | 11 | my $plan = $self->pattern; | |||||||||||
| 79 | 11 | $l->trace("Executing named graph pattern with graph " . $g->as_string . ": " . $plan->sse); | |||||||||||
| 80 | 11 | $plan->execute( $ctx ); | |||||||||||
| 81 | 11 | $self->[0]{current_graph} = $g; | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | 11 | $self->state( $self->OPEN ); | |||||||||||
| 85 | 11 | $self; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | =item C<< next >> | ||||||||||||
| 89 | |||||||||||||
| 90 | =cut | ||||||||||||
| 91 | |||||||||||||
| 92 | 30 | ▶ | sub next { | ||||||||||
|
Subroutine
next: called CC=9 SCAR=22.6
Pod
documented
| |||||||||||||
| 93 | 30 | my $self = shift; | |||||||||||
| 94 | 30 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 0 | throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open NAMED GRAPH"; | |||||||||||
| 96 | } | ||||||||||||
| 97 | 30 | my $context = $self->[0]{context}; | |||||||||||
| 98 | |||||||||||||
| 99 | 30 | my $l = Log::Log4perl->get_logger("rdf.query.plan.namedgraph"); | |||||||||||
| 100 | 30 | while (1) { | |||||||||||
| 101 | 37 | ▶ | unless ($self->[0]{current_graph}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 102 | 0 | return; | |||||||||||
| 103 | } | ||||||||||||
| 104 | 37 | my $row = $self->pattern->next; | |||||||||||
| 105 | 37 | ▶ | if ($row) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 20 | my $g = $self->[0]{current_graph}; | |||||||||||
| 107 | 20 | ▶ | if (my $rg = $row->{ $self->graph->name }) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | 18 | ▶ | unless ($rg->equal( $g )) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | 0 | next; | |||||||||||
| 110 | } | ||||||||||||
| 111 | } | ||||||||||||
| 112 | 20 | $row->{ $self->graph->name } = $g; | |||||||||||
| 113 | 20 | ▶ | if (my $d = $self->delegate) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | 0 | $d->log_result( $self, $row ); | |||||||||||
| 115 | } | ||||||||||||
| 116 | 20 | return $row; | |||||||||||
| 117 | } else { | ||||||||||||
| 118 | 17 | my $g = $self->[0]{graphs}->next; | |||||||||||
| 119 | 17 | ▶ | unless (blessed($g)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 120 | 10 | return; | |||||||||||
| 121 | } | ||||||||||||
| 122 | 7 | my %bound = %{ $self->[0]{bound} }; | |||||||||||
| 123 | 7 | $bound{ $self->graph->name } = $g; | |||||||||||
| 124 | 7 | my $ctx = $self->[0]{context}->copy( bound => \%bound ); | |||||||||||
| 125 | 7 | my $plan = $self->pattern; | |||||||||||
| 126 | 7 | ▶ | if ($plan->state == $plan->OPEN) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 127 | 7 | $plan->close(); | |||||||||||
| 128 | } | ||||||||||||
| 129 | 7 | $l->trace("Executing named graph pattern with graph " . $g->as_string); | |||||||||||
| 130 | 7 | $plan->execute( $ctx ); | |||||||||||
| 131 | 7 | $self->[0]{current_graph} = $g; | |||||||||||
| 132 | } | ||||||||||||
| 133 | } | ||||||||||||
| 134 | } | ||||||||||||
| 135 | |||||||||||||
| 136 | =item C<< close >> | ||||||||||||
| 137 | |||||||||||||
| 138 | =cut | ||||||||||||
| 139 | |||||||||||||
| 140 | 11 | ▶ | sub close { | ||||||||||
|
Subroutine
close: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 141 | 11 | my $self = shift; | |||||||||||
| 142 | 11 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 143 | 0 | throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open NAMED GRAPH"; | |||||||||||
| 144 | } | ||||||||||||
| 145 | 11 | delete $self->[0]{current_graph}; | |||||||||||
| 146 | 11 | my $plan = $self->pattern; | |||||||||||
| 147 | 11 | ▶ | if ($plan->state == $plan->OPEN) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 148 | 11 | $plan->close(); | |||||||||||
| 149 | } | ||||||||||||
| 150 | 11 | $self->SUPER::close(); | |||||||||||
| 151 | } | ||||||||||||
| 152 | |||||||||||||
| 153 | =item C<< graph >> | ||||||||||||
| 154 | |||||||||||||
| 155 | Returns the graph variable. | ||||||||||||
| 156 | |||||||||||||
| 157 | =cut | ||||||||||||
| 158 | |||||||||||||
| 159 | 62 | ▶ | sub graph { | ||||||||||
|
Subroutine
graph: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 160 | 62 | my $self = shift; | |||||||||||
| 161 | 62 | return $self->[1]; | |||||||||||
| 162 | } | ||||||||||||
| 163 | |||||||||||||
| 164 | =item C<< pattern >> | ||||||||||||
| 165 | |||||||||||||
| 166 | Returns the query plan that will be used with each named graph in the model. | ||||||||||||
| 167 | |||||||||||||
| 168 | =cut | ||||||||||||
| 169 | |||||||||||||
| 170 | 77 | ▶ | sub pattern { | ||||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 171 | 77 | my $self = shift; | |||||||||||
| 172 | 77 | return $self->[2]; | |||||||||||
| 173 | } | ||||||||||||
| 174 | |||||||||||||
| 175 | =item C<< distinct >> | ||||||||||||
| 176 | |||||||||||||
| 177 | Returns true if the pattern is guaranteed to return distinct results. | ||||||||||||
| 178 | |||||||||||||
| 179 | =cut | ||||||||||||
| 180 | |||||||||||||
| 181 | 7 | ▶ | sub distinct { | ||||||||||
|
Subroutine
distinct: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 182 | 7 | my $self = shift; | |||||||||||
| 183 | 7 | return $self->pattern->distinct; | |||||||||||
| 184 | } | ||||||||||||
| 185 | |||||||||||||
| 186 | =item C<< ordered >> | ||||||||||||
| 187 | |||||||||||||
| 188 | Returns true if the pattern is guaranteed to return ordered results. | ||||||||||||
| 189 | |||||||||||||
| 190 | =cut | ||||||||||||
| 191 | |||||||||||||
| 192 | 8 | ▶ | sub ordered { | ||||||||||
|
Subroutine
ordered: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 193 | 8 | my $self = shift; | |||||||||||
| 194 | 8 | return []; | |||||||||||
| 195 | } | ||||||||||||
| 196 | |||||||||||||
| 197 | =item C<< plan_node_name >> | ||||||||||||
| 198 | |||||||||||||
| 199 | Returns the string name of this plan node, suitable for use in serialization. | ||||||||||||
| 200 | |||||||||||||
| 201 | =cut | ||||||||||||
| 202 | |||||||||||||
| 203 | 2 | ▶ | sub plan_node_name { | ||||||||||
|
Subroutine
plan_node_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 204 | 2 | return 'named-graph'; | |||||||||||
| 205 | } | ||||||||||||
| 206 | |||||||||||||
| 207 | =item C<< plan_prototype >> | ||||||||||||
| 208 | |||||||||||||
| 209 | Returns a list of scalar identifiers for the type of the content (children) | ||||||||||||
| 210 | nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable | ||||||||||||
| 211 | identifiers. | ||||||||||||
| 212 | |||||||||||||
| 213 | =cut | ||||||||||||
| 214 | |||||||||||||
| 215 | 2 | ▶ | sub plan_prototype { | ||||||||||
|
Subroutine
plan_prototype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 216 | 2 | my $self = shift; | |||||||||||
| 217 | 2 | return qw(N P); | |||||||||||
| 218 | } | ||||||||||||
| 219 | |||||||||||||
| 220 | =item C<< plan_node_data >> | ||||||||||||
| 221 | |||||||||||||
| 222 | Returns the data for this plan node that corresponds to the values described by | ||||||||||||
| 223 | the signature returned by C<< plan_prototype >>. | ||||||||||||
| 224 | |||||||||||||
| 225 | =cut | ||||||||||||
| 226 | |||||||||||||
| 227 | 4 | ▶ | sub plan_node_data { | ||||||||||
|
Subroutine
plan_node_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 228 | 4 | my $self = shift; | |||||||||||
| 229 | 4 | return ($self->graph, $self->pattern); | |||||||||||
| 230 | } | ||||||||||||
| 231 | |||||||||||||
| 232 | |||||||||||||
| 233 | 35 | 1; | |||||||||||
| 234 | |||||||||||||
| 235 | __END__ | ||||||||||||