RDF::Query::Node::Variable - RDF Node class for variables


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

Index


Code Index:

NAME

Top

RDF::Query::Node::Variable - RDF Node class for variables

VERSION

Top

This document describes RDF::Query::Node::Variable version 2.907.

METHODS

Top

METHODS

Top

Beyond the methods documented below, this class inherits methods from the RDF::Query::Node and RDF::Trine::Node::Variable classes.

new ( $name )

Returns a new variable object.

as_sparql

Returns the SPARQL string for this node.

as_hash

Returns the query as a nested set of plain data structures (no objects).

AUTHOR

Top

 Gregory Todd Williams <gwilliams@cpan.org>


RDF-Query documentation Contained in the RDF-Query distribution.
# RDF::Query::Node::Variable
# -----------------------------------------------------------------------------

package RDF::Query::Node::Variable;

use strict;
use warnings;
no warnings 'redefine';
use base qw(RDF::Query::Node RDF::Trine::Node::Variable);

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

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

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

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

use overload	'""'	=> sub { $_[0]->sse };

my $COUNTER	= 0;
sub new {
	my $class	= shift;
	my $name	= shift;
	unless (defined($name)) {
		$name	= 'v' . time() . 'r' . $COUNTER++;
	}
	return $class->SUPER::new( $name );
}

sub as_sparql {
	my $self	= shift;
	return $self->sse;
}

sub as_hash {
	my $self	= shift;
	my $context	= shift;
	return {
		type 		=> 'node',
		variable	=> $self->name,
	};
}

package RDF::Query::Node::Variable::ExpressionProxy;

use strict;
use warnings;
use base qw(RDF::Query::Node::Variable);
use Scalar::Util qw(blessed refaddr);

{my %vars;
sub new {
	my $class	= shift;
	my $name	= shift;
	my @vars	= @_;
	my $self	= $class->SUPER::new( $name );
	if (@vars) {
		$vars{ refaddr($self) }	= [map {blessed($_) ? $_ : RDF::Query::Node::Variable->new($_)} @vars];
	}
	return $self;
}

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

sub referenced_variables {
	my $self	= shift;
	my @vars	= map { blessed($_) ? $_->name : $_ } @{ $vars{ refaddr($self) } || [] };
	return RDF::Query::_uniq(@vars);
}

sub DESTROY {
	my $self	= shift;
	delete $vars{ refaddr($self) };
}
}

1;

__END__