Commits

Toby Inkster committed 921e888

slurp from file handle (would be nicer to stream - ho hum)

Comments (0)

Files changed (2)

examples/to_html.pl

 
 use Syntax::Highlight::RDF;
 
-my $data = do { local $/ = <DATA> };
-my $hl   = "Syntax::Highlight::RDF"->new;
+my $hl = "Syntax::Highlight::RDF"->new;
 
-for my $tok (@{ $hl->tokenize(\$data) })
+for my $tok (@{ $hl->tokenize(\*DATA) })
 {
 	print $tok->TO_HTML;
 }

lib/Syntax/Highlight/RDF.pm

 
 use Moo;
 
+use IO::Detect qw( as_filehandle );
+
 use constant {
 	MODE_NTRIPLES       => 0,
 	MODE_TURTLE         => 1,
 {
 	my $self = shift;
 	my ($text_ref, $base) = @_;
-	$self->_remaining($text_ref);
+	$self->_remaining(
+		ref($text_ref) eq 'SCALAR'
+			? $text_ref
+			: do { local $/; my $h = as_filehandle($text_ref); \(my $t = <$h>) }
+	);
 	$self->_tokens([]);
 	$self->_base($base // "http://www.example.net/");