RDF::Trine::Node::Blank - RDF Node class for blank nodes


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

Index


Code Index:

NAME

Top

RDF::Trine::Node::Blank - RDF Node class for blank nodes

VERSION

Top

This document describes RDF::Trine::Node::Blank 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 Blank structure.

blank_identifier

Returns the identifier of the blank node.

value

Returns the blank identifier.

sse

Returns the SSE string for this blank node.

as_ntriples

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

as_string

Returns a string representation of the node.

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::Blank
# -----------------------------------------------------------------------------

package RDF::Trine::Node::Blank;

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 },
			;

my $COUNTER	= 0;
sub new {
	my $class	= shift;
	my $name	= shift;
	unless (defined($name)) {
		$name	= 'r' . time() . 'r' . $COUNTER++;
	}
	if ($name =~ m/[^A-Za-z0-9]/) {
		throw RDF::Trine::Error::SerializationError -text => "Only alphanumerics are allowed in N-Triples bnode labels";
	}
	return $class->_new( $name );
}

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

sub blank_identifier {
	my $self	= shift;
	return $self->[1];
}

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

sub sse {
	my $self	= shift;
	my $id		= $self->blank_identifier;
	return qq(_:${id});
}

sub as_ntriples {
	my $self	= shift;
	my $id		= $self->blank_identifier;
	return qq(_:${id});
}

sub as_string {
	my $self	= shift;
	return	'(' . $self->blank_identifier . ')';
}

sub type {
	return 'BLANK';
}

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

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

1;

__END__