RDF::Query::Expression - Class for Expr expressions


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

Index


Code Index:

NAME

Top

RDF::Query::Expression - Class for Expr expressions

VERSION

Top

This document describes RDF::Query::Expression version 2.907.

METHODS

Top

new ( $op, @operands )

Returns a new Expr structure.

construct_args

Returns a list of arguments that, passed to this class' constructor, will produce a clone of this algebra pattern.

op

Returns the operator of the expression.

operands

Returns a list of the operands of the expression.

sse

Returns the SSE string for this algebra expression.

explain

Returns a string serialization of the expression appropriate for display on the command line. This method is primarily used by the explain method of the subclasses of RDF::Query::Plan.

type

Returns the type of this algebra expression.

referenced_variables

Returns a list of the variable names used in this algebra expression.

AUTHOR

Top

 Gregory Todd Williams <gwilliams@cpan.org>


RDF-Query documentation Contained in the RDF-Query distribution.
# RDF::Query::Expression
# -----------------------------------------------------------------------------

package RDF::Query::Expression;

use strict;
use warnings;
no warnings 'redefine';
use base qw(RDF::Query::Algebra);

use Data::Dumper;
use Scalar::Util qw(blessed);
use Carp qw(carp croak confess);

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

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

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

sub new {
	my $class	= shift;
	my $op		= shift;
	my @operands	= @_;
	return bless( [ $op, @operands ], $class );
}

sub construct_args {
	my $self	= shift;
	return ($self->op, $self->operands);
}

sub op {
	my $self	= shift;
	return $self->[0];
}

sub operands {
	my $self	= shift;
	return @{ $self }[ 1 .. $#{ $self } ];
}

sub sse {
	my $self	= shift;
	my $context	= shift;
	
	return sprintf(
		'(%s %s)',
		$self->op,
		join(' ', map { $_->sse( $context ) } $self->operands),
	);
}

sub explain {
	my $self	= shift;
	my $s		= shift;
	my $count	= shift;
	my $indent	= $s x $count;
	my $type	= $self->op;
	my $string	= "${indent}${type}\n";
	foreach my $p ($self->operands) {
		$string	.= $p->explain( $s, $count+1 );
	}
	return $string;
}

sub type {
	return 'EXPR';
}

sub referenced_variables {
	my $self	= shift;
	my @ops		= $self->operands;
	my @vars;
	foreach my $o (@ops) {
		if ($o->isa('RDF::Query::Node::Variable')) {
			push(@vars, $o->name);
		} elsif ($o->isa('RDF::Query::Expression')) {
			push(@vars, $o->referenced_variables);
		}
	}
	return RDF::Query::_uniq(@vars);
}

1;

__END__