RDF::Query::Expression::Alias - Class for aliasing expressions with variable names


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

Index


Code Index:

NAME

Top

RDF::Query::Expression::Alias - Class for aliasing expressions with variable names

VERSION

Top

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

METHODS

Top

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

name

Returns the variable name of the aliased expression.

alias

Returns the variable object of the aliased expression.

expression

Returns the expression object of the aliased expression.

sse

Returns the SSE string for this algebra expression.

as_sparql

Returns the SPARQL string for this algebra expression.

evaluate ( $query, \%bound, $context )

Evaluates the expression using the supplied bound variables. Will return a RDF::Query::Node object.

AUTHOR

Top

 Gregory Todd Williams <gwilliams@cpan.org>


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

package RDF::Query::Expression::Alias;

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

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

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

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

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

sub name {
	my $self	= shift;
	return $self->alias->name;
}

sub alias {
	my $self	= shift;
	my ($alias)	= $self->operands;
	return $alias;
}

sub expression {
	my $self	= shift;
	return ($self->operands)[1];
}

sub sse {
	my $self	= shift;
	my $context	= shift;
	
	return sprintf(
		'(alias ?%s %s)',
		$self->name,
		$self->expression->sse( $context ),
	);
}

sub as_sparql {
	my $self	= shift;
	my $context	= shift;
	my $indent	= shift;
	my $alias	= $self->alias;
	my $expr	= $self->expression;
	return sprintf("(%s AS %s)", $expr->as_sparql, $alias->as_sparql);
}

sub evaluate {
	my $self	= shift;
	my $query	= shift;
	my $bound	= shift;
	my $ctx		= shift;
	my $expr	= $self->expression;
	my $value	= $query->var_or_expr_value( $bound, $expr, $ctx );
	return $value;
}


1;

__END__