Source

p5-rdf-rdfa-api / lib / RDF / RDFa / API / TypedLiteral.pm

Full commit
package RDF::RDFa::API::TypedLiteral;

use 5.010;
use Moose;
use namespace::clean -except => 'meta';
use common::sense;

extends 'RDF::RDFa::API::RDFNode';

has trineNode => (is => 'ro', isa => 'RDF::Trine::Node::Literal');

sub construct
{
	my ($class, $value, $dt, %args) = @_;
	
	if ($dt && $args{dataContext})
	{
		$dt = $args{dataContext}->resolveCurieToString($dt);
	}
	
	return $class->new(
		%args,
		trineNode => RDF::Trine::Node::Literal->new("$value", undef, $dt),
		);
}

sub type
{
	my ($self) = @_;
	
	return undef
		unless $self->trineNode->has_datatype;
		
	return RDF::RDFa::API::IRI->construct($self->trineNode->literal_datatype);
}

sub valueOf
{
	my ($self) = @_;
	
	if ($self->dataContext)
	{
		return $self->dataContext->convertType($self->value, $self->type);
	}
	
	return $self->value;
}

1;

__END__

=head1 NAME

RDF::RDFa::API::TypedLiteral - A TypedLiteral has a string value and a datatype specified as an IRI Reference.

=head1 WEBIDL

	[NoInterfaceObject]
	interface TypedLiteral : RDFNode {
		 readonly attribute stringifier DOMString value;
		 readonly attribute IRI                   type;
		 any valueOf ();
	};

=head1 SEE ALSO

L<RDF::RDFa::API>.

=head1 BUGS

Please report any bugs to L<http://rt.cpan.org/>.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT

Copyright 2010 Toby Inkster

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.