RDF::Query::Plan::Sequence - Executable query plan for a sequence of operations.


RDF-Query documentation Contained in the RDF-Query distribution.

Index


Code Index:

NAME

Top

RDF::Query::Plan::Sequence - Executable query plan for a sequence of operations.

VERSION

Top

This document describes RDF::Query::Plan::Sequence version 2.907.

METHODS

Top

Beyond the methods documented below, this class inherits methods from the RDF::Query::Plan class.

new ( @plans )
execute ( $execution_context )
next
close
distinct

Returns true if the pattern is guaranteed to return distinct results.

ordered

Returns true if the pattern is guaranteed to return ordered results.

plan_node_name

Returns the string name of this plan node, suitable for use in serialization.

plan_prototype

Returns a list of scalar identifiers for the type of the content (children) nodes of this plan node. See RDF::Query::Plan for a list of the allowable identifiers.

plan_node_data

Returns the data for this plan node that corresponds to the values described by the signature returned by plan_prototype.

AUTHOR

Top

 Gregory Todd Williams <gwilliams@cpan.org>


RDF-Query documentation Contained in the RDF-Query distribution.
# RDF::Query::Plan::Sequence
# -----------------------------------------------------------------------------

package RDF::Query::Plan::Sequence;

use strict;
use warnings;
use base qw(RDF::Query::Plan);

use Scalar::Util qw(blessed);
use RDF::Trine::Statement;

######################################################################

our ($VERSION);
BEGIN {
	$VERSION	= '2.907';
}

######################################################################

sub new {
	my $class	= shift;
	my @plans	= @_;
	my $self	= $class->SUPER::new( \@plans );
	return $self;
}

sub execute ($) {
	my $self	= shift;
	my $context	= shift;
	if ($self->state == $self->OPEN) {
		throw RDF::Query::Error::ExecutionError -text => "SEQUENCE plan can't be executed twice";
	}
	
	my $l		= Log::Log4perl->get_logger("rdf.query.plan.sequence");
	$l->trace( "executing RDF::Query::Plan::Sequence" );
	
	my @plans	= @{ $self->[1] };
	while (scalar(@plans) > 1) {
		my $p	= shift(@plans);
		$p->execute( $context );
		1 while ($p->next);
	}
	my $iter	= $plans[0]->execute( $context );
	
	if (blessed($iter)) {
		$self->[0]{iter}	= $iter;
		$self->state( $self->OPEN );
	} else {
		warn "no iterator in execute()";
	}
	$self;
}

sub next {
	my $self	= shift;
	unless ($self->state == $self->OPEN) {
		throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open SEQUENCE";
	}
	
	my $iter	= $self->[0]{iter};
	my $row		= $iter->next;
	return $row;
}

sub close {
	my $self	= shift;
	unless ($self->state == $self->OPEN) {
		throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open SEQUENCE";
	}
	
	delete $self->[0]{iter};
	$self->SUPER::close();
}

sub distinct {
	my $self	= shift;
	my @plans	= @{ $self->[1] };
	return $plans[ $#plans ]->distinct;
}

sub ordered {
	my $self	= shift;
	my @plans	= @{ $self->[1] };
	return $plans[ $#plans ]->ordered;
}

sub plan_node_name {
	return 'sequence';
}

sub plan_prototype {
	my $self	= shift;
	return qw(*P);
}

sub plan_node_data {
	my $self	= shift;
	my @triples	= @{ $self->[1] };
	return @triples;
}

1;

__END__