Commits

Toby Inkster  committed 9dbe088

relative base URI support

  • Participants
  • Parent commits 63626a2

Comments (0)

Files changed (2)

File examples/turtle_tokens.pl

 my $hl   = "Syntax::Highlight::RDF"->highlighter("Turtle");
 
 $hl->tokenize(\$data);
-$hl->_fixup("http://www.example.net/");
+$hl->_fixup("xyzzy/");
 
 for my $tok (@{$hl->_tokens})
 {
 }
 
 __DATA__
-@base <http://www.example.org/> .
 @prefix foo: <http://example.com/foo#> .
 @prefix quux: <quux#>.
 

File lib/Syntax/Highlight/RDF.pm

 ;
 
 {
-	use HTML::HTML5::Entities qw/encode_entities/;	
+	use HTML::HTML5::Entities qw/encode_entities/;
 	no strict 'refs';
 	*{Feature    . "::tok"}        = sub { sprintf "%s~", $_[0]->TYPE };
 	*{Token      . "::tok"}        = sub { sprintf "%s[%s]", $_[0]->TYPE, $_[0]->spelling };
 	my ($relative, $base) = @_;
 	return $relative unless length $base;
 	
-	# XXX - cope with situation where $base exists but is relative
+	require URI;
 	
-	require URI;
+	# Where the base itself is relative
+	if (not URI->new($base)->scheme)
+	{
+		if ($base =~ m{^/})
+		{
+			return "URI"->new_abs(@_)->as_string;
+		}
+		else
+		{
+			return substr("URI"->new_abs(@_)->as_string, 1);
+		}
+	}
+	
 	"URI"->new_abs(@_)->as_string;
 }
 
 	use Moo;
 	extends "Syntax::Highlight::RDF";
 	use constant mode => Syntax::Highlight::RDF::MODE_NTRIPLES
-	                  |  Syntax::Highlight::RDF::MODE_TURTLE;
+		| Syntax::Highlight::RDF::MODE_TURTLE;
 	sub _serializer
 	{
 		eval { require RDF::TrineX::Serializer::MockTurtleSoup }
 	use Moo;
 	extends "Syntax::Highlight::RDF";
 	use constant mode => Syntax::Highlight::RDF::MODE_NTRIPLES
-	                  |  Syntax::Highlight::RDF::MODE_TURTLE
-	                  |  Syntax::Highlight::RDF::MODE_NOTATION_3;
+		| Syntax::Highlight::RDF::MODE_TURTLE
+		| Syntax::Highlight::RDF::MODE_NOTATION_3;
 	sub _serializer
 	{
 		require RDF::Trine::Serializer::Notation3;
 	use Moo;
 	extends "Syntax::Highlight::RDF";
 	use constant mode => Syntax::Highlight::RDF::MODE_NTRIPLES
-	                  |  Syntax::Highlight::RDF::MODE_TURTLE
-	                  |  Syntax::Highlight::RDF::MODE_SPARQL;
+		| Syntax::Highlight::RDF::MODE_TURTLE
+		| Syntax::Highlight::RDF::MODE_SPARQL;
 }
 
 {
 	use Moo;
 	extends "Syntax::Highlight::RDF";
 	use constant mode => Syntax::Highlight::RDF::MODE_NTRIPLES
-	                  |  Syntax::Highlight::RDF::MODE_TURTLE
-	                  |  Syntax::Highlight::RDF::MODE_SPARQL;
+		| Syntax::Highlight::RDF::MODE_TURTLE
+		| Syntax::Highlight::RDF::MODE_SPARQL;
 }
 
 {
 	use Moo;
 	extends "Syntax::Highlight::RDF";
 	use constant mode => Syntax::Highlight::RDF::MODE_NTRIPLES
-	                  |  Syntax::Highlight::RDF::MODE_TURTLE
-	                  |  Syntax::Highlight::RDF::MODE_NOTATION_3
-	                  |  Syntax::Highlight::RDF::MODE_PRETDSL;
+		| Syntax::Highlight::RDF::MODE_TURTLE
+		| Syntax::Highlight::RDF::MODE_NOTATION_3
+		| Syntax::Highlight::RDF::MODE_PRETDSL;
 }
 
 {
 	use Moo;
 	extends "Syntax::Highlight::RDF";
 	use constant mode => Syntax::Highlight::RDF::MODE_NTRIPLES
-	                  |  Syntax::Highlight::RDF::MODE_TURTLE
-	                  |  Syntax::Highlight::RDF::MODE_TRIG;
+		| Syntax::Highlight::RDF::MODE_TURTLE
+		| Syntax::Highlight::RDF::MODE_TRIG;
 }
 
 sub highlighter
 
 =back
 
+=begin private
+
+=item MODE_NTRIPLES       => 0,
+
+=item MODE_TURTLE         => 1,
+
+=item MODE_NOTATION_3     => 2,
+
+=item MODE_SPARQL         => 4,
+
+=item MODE_PRETDSL        => 8,
+
+=item MODE_TRIG           => 16,
+
+=item mode
+
+=end private
+
 =head1 BUGS
 
 Please report any bugs to