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


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

Index


Code Index:

NAME

Top

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

VERSION

Top

This document describes RDF::Trine::Node::Variable version 0.135

METHODS

Top

Beyond the methods documented below, this class inherits methods from the RDF::Trine::Node class.

new ( $name )

Returns a new Variable structure.

name

Returns the name of the variable.

sse

Returns the SSE string for this variable.

as_string

Returns a string representation of the node.

value

Returns the variable name.

as_ntriples

Returns the node in a string form suitable for NTriples serialization.

type

Returns the type string of this node.

equal ( $node )

Returns true if the two nodes are equal, false otherwise.

AUTHOR

Top

Gregory Todd Williams <gwilliams@cpan.org>

COPYRIGHT

Top


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

package RDF::Trine::Node::Variable;

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

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

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

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

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

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

sub new {
	my $class	= shift;
	my $name	= shift;
	return bless( [ $name ], $class );
}

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

sub sse {
	my $self	= shift;
	my $name	= $self->name;
	return qq(?${name});
}

sub as_string {
	my $self	= shift;
	return '?' . $self->name;
}

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

sub as_ntriples {
	my $self	= shift;
	throw RDF::Trine::Error::UnimplementedError -text => "Variable nodes aren't allowed in NTriples";
}

sub type {
	return 'VAR';
}

sub equal {
	my $self	= shift;
	my $node	= shift;
	return 0 unless (blessed($node) and $node->isa('RDF::Trine::Node'));
	return 0 unless ($self->type eq $node->type);
	return ($self->name eq $node->name);
}

# called to compare two nodes of the same type
sub _compare {
	my $a	= shift;
	my $b	= shift;
	return ($a->name cmp $b->name);
}

1;

__END__