Toby Inkster avatar Toby Inkster committed 7b9b39e

slight cleanup, release as v0.271

Comments (0)

Files changed (19)

Changes

-############################################################################
-## Changes #################################################################
-############################################################################
-
-HTML-Embedded-Turtle
-====================
-
-Created:      2010-05-05
-Home page:    <http://search.cpan.org/dist/HTML-Embedded-Turtle/>
-Bug tracker:  <http://rt.cpan.org/Dist/Display.html?Queue=HTML-Embedded-Turtle>
-Maintainer:   Toby Inkster <mailto:tobyink@cpan.org>
-
-0.090 [2010-12-09]
- - use RDF::TriN3
-
-0.01 [2010-05-05] # First release
-

Changes.ttl

-#############################################################
-
-@prefix :        <http://usefulinc.com/ns/doap#> .
-@prefix dcs:     <http://ontologi.es/doap-changeset#> .
-@prefix dc:      <http://purl.org/dc/terms/> .
-@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
-@prefix my:      <http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/> .
-@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
-@prefix toby:    <http://tobyinkster.co.uk/#> .
-@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
-
-#############################################################
-
-<>
-
-	dc:title         "Changes" ;
-	dc:description   "Revision history for Perl extension HTML::Embedded::Turtle."@en ;
-	dc:subject       my:project ;
-	dc:creator       toby:i .
-
-#############################################################
-
-my:v_0-01
-
-	a               :Version ;
-	dc:issued       "2010-05-05"^^xsd:date ;
-	:revision       "0.01"^^xsd:string ;
-	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-Embedded-Turtle-0.01.tar.gz> ;
-	rdfs:label      "First release"@en .
-
-my:v_0-090
-
-	a               :Version ;
-	dc:issued       "2010-12-09"^^xsd:date ;
-	:revision       "0.090"^^xsd:string ;
-	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-Embedded-Turtle-0.090.tar.gz> ;
-	dcs:changeset [
-		dcs:versus my:v_0-01 ;
-		dcs:item   [ rdfs:label "use RDF::TriN3"@en ]
-		] .
-
-#############################################################
-
-my:project
-
-	a               :Project ;
-	:name           "HTML-Embedded-Turtle" ;
-	:shortdesc      "embedding RDF in HTML the crazy way"@en ;
-	:programming-language  "Perl" ;
-	:homepage       <https://metacpan.org/release/HTML-Embedded-Turtle> ;
-	:download-page  <https://metacpan.org/release/HTML-Embedded-Turtle> ;
-	:bug-database   <http://rt.cpan.org/Dist/Display.html?Queue=HTML-Embedded-Turtle> ;
-	:repository     [ a :SVNRepository ; :browse <http://goddamn.co.uk/svn-web/perlmods/browse/HTML-Embedded-Turtle/> ] ;
-	:maintainer     toby:i ;
-	:developer      toby:i ;
-	:documenter     toby:i ;
-	:tester         toby:i ;
-	:created        "2010-05-05"^^xsd:date ;
-	:license        <http://dev.perl.org/licenses/> ;
-	:release        my:v_0-01 , my:v_0-090 .
-
-#############################################################
-
-toby:i
-
-	a               foaf:Person ;
-	foaf:name       "Toby Inkster" ;
-	foaf:homepage   <http://tobyinkster.co.uk/> ;
-	foaf:page       <https://metacpan.org/author/TOBYINK> ;
-	foaf:mbox       <mailto:tobyink@cpan.org> ;
-	<http://www.w3.org/2002/07/owl#sameAs> <http://purl.org/NET/cpan-uri/person/tobyink> .
-
-#############################################################

Changes.xml

-<?xml version="1.0" encoding="utf-8"?>
-<rdf:RDF xmlns:dbug="http://ontologi.es/doap-bugs#" xmlns:dc="http://purl.org/dc/terms/" xmlns:dcs="http://ontologi.es/doap-changeset#" xmlns:doap="http://usefulinc.com/ns/doap#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
-<rdf:Description rdf:nodeID="r37C8C23A03E611E0AA67FAE2354FAF74r0">
-	<dcs:item rdf:nodeID="r37C8C23A03E611E0AA67FAE2354FAF74r1"/>
-	<dcs:versus rdf:resource="http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/v_0-01"/>
-</rdf:Description>
-<rdf:Description rdf:nodeID="r37C8C23A03E611E0AA67FAE2354FAF74r1">
-	<rdfs:label xml:lang="en">use RDF::TriN3</rdfs:label>
-</rdf:Description>
-<rdf:Description rdf:nodeID="r37C8C23A03E611E0AA67FAE2354FAF74r2">
-	<doap:browse rdf:resource="http://goddamn.co.uk/viewvc/perlmods/HTML-Embedded-Turtle/"/>
-	<rdf:type rdf:resource="http://usefulinc.com/ns/doap#SVNRepository"/>
-</rdf:Description>
-<rdf:Description rdf:about="file:///home/tai/src/perlmods/HTML-Embedded-Turtle/Changes.ttl">
-	<dc:creator rdf:resource="http://tobyinkster.co.uk/#i"/>
-	<dc:description xml:lang="en">Revision history for Perl extension HTML::Embedded::Turtle.</dc:description>
-	<dc:subject rdf:resource="http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/project"/>
-	<dc:title>Changes</dc:title>
-</rdf:Description>
-<rdf:Description rdf:about="http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/project">
-	<doap:bug-database rdf:resource="http://rt.cpan.org/Dist/Display.html?Queue=HTML-Embedded-Turtle"/>
-	<doap:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2010-05-05</doap:created>
-	<doap:developer rdf:resource="http://tobyinkster.co.uk/#i"/>
-	<doap:documenter rdf:resource="http://tobyinkster.co.uk/#i"/>
-	<doap:download-page rdf:resource="http://search.cpan.org/dist/HTML-Embedded-Turtle/"/>
-	<doap:homepage rdf:resource="http://search.cpan.org/dist/HTML-Embedded-Turtle/"/>
-	<doap:license rdf:resource="http://dev.perl.org/licenses/"/>
-	<doap:maintainer rdf:resource="http://tobyinkster.co.uk/#i"/>
-	<doap:name>HTML-Embedded-Turtle</doap:name>
-	<doap:programming-language>Perl</doap:programming-language>
-	<doap:release rdf:resource="http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/v_0-01"/>
-	<doap:release rdf:resource="http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/v_0-090"/>
-	<doap:repository rdf:nodeID="r37C8C23A03E611E0AA67FAE2354FAF74r2"/>
-	<doap:shortdesc xml:lang="en">embedding RDF in HTML the crazy way</doap:shortdesc>
-	<doap:tester rdf:resource="http://tobyinkster.co.uk/#i"/>
-	<rdf:type rdf:resource="http://usefulinc.com/ns/doap#Project"/>
-</rdf:Description>
-<rdf:Description rdf:about="http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/v_0-01">
-	<dc:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2010-05-05</dc:issued>
-	<doap:file-release rdf:resource="http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-Embedded-Turtle-0.01.tar.gz"/>
-	<doap:revision rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0.01</doap:revision>
-	<rdf:type rdf:resource="http://usefulinc.com/ns/doap#Version"/>
-	<rdfs:label xml:lang="en">First release</rdfs:label>
-</rdf:Description>
-<rdf:Description rdf:about="http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/v_0-090">
-	<dcs:changeset rdf:nodeID="r37C8C23A03E611E0AA67FAE2354FAF74r0"/>
-	<dc:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2010-12-09</dc:issued>
-	<doap:file-release rdf:resource="http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-Embedded-Turtle-0.090.tar.gz"/>
-	<doap:revision rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0.090</doap:revision>
-	<rdf:type rdf:resource="http://usefulinc.com/ns/doap#Version"/>
-</rdf:Description>
-<rdf:Description xmlns:ns1="http://www.w3.org/2002/07/owl#" rdf:about="http://tobyinkster.co.uk/#i">
-	<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
-	<ns1:sameAs rdf:resource="http://purl.org/NET/cpan-uri/person/tobyink"/>
-	<foaf:homepage rdf:resource="http://tobyinkster.co.uk/"/>
-	<foaf:mbox rdf:resource="mailto:tobyink@cpan.org"/>
-	<foaf:name>Toby Inkster</foaf:name>
-	<foaf:page rdf:resource="http://search.cpan.org/~tobyink/"/>
-</rdf:Description>
-</rdf:RDF>

MANIFEST.SKIP

-^MANIFEST.bak$
-^Makefile.old$
-^Makefile$
-^blib/
-^pm_to_blib
-^blibdirs
-\.svn
-^example.*\.pl$
-^[^/]+\.(tar\.gz|tar\.bz2|tgz|tbz2|tbz|zip|tar)$
-^MYMETA.yml

META.yml

----
-abstract: 'embedding RDF in HTML the crazy way'
-author:
-  - 'Toby Inkster <tobyink@cpan.org>'
-build_requires:
-  ExtUtils::MakeMaker: 6.42
-  Module::Signature: 0.66
-  Test::More: 0.61
-configure_requires:
-  ExtUtils::MakeMaker: 6.42
-distribution_type: module
-generated_by: 'Module::Install version 1.00'
-keywords:
-  - HTML
-  - XHTML
-  - script
-  - RDF
-  - SemWeb
-  - Turtle
-  - Notation3
-  - N-Triples
-license: perl
-meta-spec:
-  url: http://module-build.sourceforge.net/META-spec-v1.4.html
-  version: 1.4
-name: HTML-Embedded-Turtle
-no_index:
-  directory:
-    - inc
-    - t
-requires:
-  Data::UUID: 0
-  RDF::RDFa::Parser: 1.09_04
-  RDF::TriN3: 0
-  RDF::Trine: 0.118
-  RDF::TrineShortcuts: 0.07
-  common::sense: 0
-  perl: 5.8.0
-resources:
-  bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=HTML-Embedded-Turtle
-  homepage: http://search.cpan.org/dist/HTML-Embedded-Turtle/
-  license: http://dev.perl.org/licenses/
-  repository: http://goddamn.co.uk/viewvc/perlmods/HTML-Embedded-Turtle/
-version: 0.090
-use strict;
-use warnings;
-
-use inc::Module::Install;
-
-my $dist = 'HTML-Embedded-Turtle';
-my $fn   = "lib/$dist.pm"; $fn =~ s#-#/#g;
-
-name                $dist;
-perl_version_from   $fn;
-version_from        $fn;
-abstract_from       $fn;
-readme_from         $fn;
-author              'Toby Inkster <tobyink@cpan.org>';
-license             'perl';
-
-requires            'common::sense'       => 0;
-requires            'Data::UUID'          => 0;
-requires            'RDF::RDFa::Parser'   => '1.09_04';
-requires            'RDF::Trine'          => '0.118';
-requires            'RDF::TriN3'          => 0;
-requires            'RDF::TrineShortcuts' => '0.07';
-test_requires       'Test::More'          => '0.61';
-
-resources(
-	'homepage'   => "https://metacpan.org/release/$dist",
-	'repository' => "http://goddamn.co.uk/svn-web/perlmods/browse/$dist/",
-	'bugtracker' => "http://rt.cpan.org/Dist/Display.html?Queue=$dist",
-	);
-	
-keywords(qw(HTML XHTML script RDF SemWeb Turtle Notation3 N-Triples));
-
-write_doap_changes;
-write_doap_changes_xml;
-auto_license;
-auto_manifest;
-
-auto_install;
-WriteAll(
-	'meta' => 1,
-	'sign' => 1,
-	);
+use inc::Module::Package 'RDF:standard';

README

-NAME
-    HTML::Embedded::Turtle - embedding RDF in HTML the crazy way
-
-VERSION
-    0.01
-
-SYNOPSIS
-     use HTML::Embedded::Turtle;
- 
-     my $het = HTML::Embedded::Turtle->new($html, $base_uri);
-     foreach my $graph ($het->endorsements)
-     {
-       my $model = $het->graph($graph);
-   
-       # $model is an RDF::Trine::Model. Do something with it.
-     }
-
-DESCRIPTION
-    RDF can be embedded in (X)HTML using simple <script> tags. This is
-    described at <http://esw.w3.org/N3inHTML>. This gives you a file format
-    that can contain multiple (optionally named) graphs. The document as a
-    whole can "endorse" a graph by including:
-
-     <link rel="meta" href="#foo" />
-
-    Where "#foo" is a fragment identifier pointing to a graph.
-
-     <script type="text/turtle" id="foo"> ... </script>
-
-    The rel="meta" stuff is parsed using an RDFa parser, so equivalent RDFa
-    works too.
-
-    This module parses HTML files containing graphs like these, and allows
-    you to access them each individually; as a union of all graphs on the
-    page; or as a union of just the endorsed graphs.
-
-    Despite the module name, this module supports a variety of <script
-    type>s: text/turtle, application/turtle, application/x-turtle text/plain
-    (N-Triples), application/x-rdf+json (RDF/JSON), application/json
-    (RDF/JSON), application/rdf+xml (RDF/XML). Although it doesn't support
-    full N3, it recognises the following as well, but treats them as Turtle:
-    text/n3, text/rdf+n3.
-
-  Constructor
-    "$het = HTML::Embedded::Turtle->new($markup, $base_uri, \%opts)"
-        Create a new object. $markup is the HTML or XHTML markup to parse;
-        $base_uri is the base URI to use for relative references.
-
-        Options include:
-
-        *   markup
-
-            Choose which parser to use: 'html' or 'xml'. The former chooses
-            HTML::HTML5::Parser, which can handle tag soup; the latter
-            chooses XML::LibXML, which cannot. Defaults to 'html'.
-
-        *   rdfa_options
-
-            A set of options to be parsed to RDF::RDFa::Parser when looking
-            for endorsements. See RDF::RDFa::Parser::Config. The default is
-            probably sensible.
-
-  Public Methods
-    "$het->union_graph"
-        A union graph of all graphs found in the document, as an
-        RDF::Trine::Model. Note that the returned model contains quads.
-
-    "$het->endorsed_union_graph"
-        A union graph of only the endorsed graphs, as an RDF::Trine::Model.
-        Note that the returned model contains quads.
-
-    "$het->graph($name)"
-        A single graph from the page.
-
-    "$het->all_graphs"
-        A hashref where the keys are graph names and the values are
-        RDF::Trine::Models. Some graph names will be URIs, and others may be
-        blank nodes (e.g. "_:foobar").
-
-    "$het->endorsed_graphs"
-        Like "all_graphs", but only returns endorsed graphs. Note that all
-        endorsed graphs will have graph names that are URIs.
-
-    "$het->endorsements"
-        Returns a list of URIs which are the names of endorsed graphs. Note
-        that the presence of a URI $x in this list does not imply that
-        "$het->graph($x)" will be defined.
-
-BUGS
-    Please report any bugs to <http://rt.cpan.org/>.
-
-    Please forgive me in advance for inflicting this module upon you.
-
-SEE ALSO
-    RDF::RDFa::Parser, RDF::Trine.
-
-    <http://www.perlrdf.org/>.
-
-AUTHOR
-    Toby Inkster <tobyink@cpan.org>.
-
-COPYRIGHT AND LICENSE
-    Copyright (C) 2010 by Toby Inkster
-
-    This library is free software; you can redistribute it and/or modify it
-    under the same terms as Perl itself, either Perl version 5.8 or, at your
-    option, any later version of Perl 5 you may have available.
-

TODO

-TODO:
-1. Add some more items to this list.
-2. ...

example1.pl

-use lib "lib";
-use Data::Dumper;
-use HTML::Embedded::Turtle;
-
-my $het = HTML::Embedded::Turtle->new(<<MARKUP, 'http://example.net/');
-<title>Test</title>
-<link rel=meta href="#endorsed">
-
-<script language=Turtle>
-\@prefix foaf: <http://xmlns.com/foaf/0.1/> .
-[] a foaf:Person ; foaf:name "Joe Bloggs" .
-</script>
-
-<script type="text/turtle" id=endorsed>
-\@prefix foaf: <http://xmlns.com/foaf/0.1/> .
-[] a foaf:Person ; foaf:name "Alice Smith" .
-</script>
-
-<script type="TEXT/TURTLE" id=unendorsed>
-\@prefix foaf: <http://xmlns.com/foaf/0.1/> .
-[] a foaf:Person ; foaf:name "Bob Smith" .
-</script>
-
-<p>Hello</p>
-
-MARKUP
-
-my $iter = $het->endorsed_union_graph->get_statements(undef, undef, undef, undef);
-while (my $st = $iter->next)
-{
-	print $st->as_string;
-}

examples/simple-example.pl

+use 5.010;
+use strict;
+
+use HTML::Embedded::Turtle 0.200;
+use Data::Dumper;
+
+my $het = HTML::Embedded::Turtle->new(<<'MARKUP', 'http://example.net/');
+	<title property="http://purl.org/dc/terms/title">Test</title>
+	<link rel=meta href="#endorsed">
+	<script language=Turtle>
+		@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+		[] a foaf:Person ; foaf:name "Joe Bloggs" .
+	</script>
+	<script type="text/turtle" id=endorsed>
+		@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+		[] a foaf:Person ; foaf:name "Alice Smith" .
+	</script>
+	<script type="TEXT/TURTLE" id=unendorsed>
+		@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+		[] a foaf:Person ; foaf:name "Bob Smith" .
+	</script>
+	<p>Hello</p>
+MARKUP
+
+my $iter = $het->union_graph->get_statements(undef, undef, undef, undef);
+while (my $st = $iter->next)
+{
+	say $st->as_string;
+}
+say "############################";
+say Dumper([ $het->endorsements ]);

lib/HTML/Embedded/Turtle.pm

 package HTML::Embedded::Turtle;
 
-use 5.008;
-use common::sense;
+use 5.010;
+use common::sense; # oh, the irony!
 use Data::UUID;
 use RDF::RDFa::Parser '1.093';
 use RDF::TriN3;
-use RDF::TrineShortcuts qw(rdf_query rdf_parse);
+use RDF::Trine qw[iri literal blank statement];
 
-our $VERSION = '0.090';
+sub biri { $_[0] =~ /^_:(.*)$/ ? blank($1) : iri(@_) }
+
+use namespace::clean;
+
+BEGIN {
+  $HTML::Embedded::Turtle::VERSION   = '0.271';
+  $HTML::Embedded::Turtle::AUTHORITY = 'cpan:TOBYINK';
+}
+
+my $xhv = RDF::Trine::Namespace->new('http://www.w3.org/1999/xhtml/vocab#');
 
 sub new
 {
 		options  => $options ,
 		}, $class;
 	
-	$options->{'rdfa_options'} ||= $options->{'markup'} =~ /x(ht)?ml/i ?
-		RDF::RDFa::Parser::Config->new('xhtml', '1.0', dom_parser=>'xml') :
-		RDF::RDFa::Parser::Config->new('html',  '1.0', dom_parser=>'html');
+	$options->{'rdfa_options'} //= $options->{'markup'} =~ /x(ht)?ml/i
+		? RDF::RDFa::Parser::Config->new(RDF::RDFa::Parser::Config->HOST_XHTML, RDF::RDFa::Parser::Config->RDFA_10)
+		: RDF::RDFa::Parser::Config->new(RDF::RDFa::Parser::Config->HOST_HTML5, RDF::RDFa::Parser::Config->RDFA_10);
 	
 	my $rdfa_parser      =
-	$self->{rdfa_parser} = RDF::RDFa::Parser->new($markup, $base_uri, $options->{'rdfa_options'})->consume;
+	$self->{rdfa_parser} = RDF::RDFa::Parser->new($markup, $base_uri, $options->{'rdfa_options'});
 	$self->{dom}         = $rdfa_parser->dom;
 	$self->{base_uri}    = $rdfa_parser->uri;
 
-	$self->_find_endorsed;
-	$self->_extract_graphs;
+	$self->_find_endorsed->_extract_graphs;
 }
 
 sub _find_endorsed
 	my ($self) = @_;
 	my $rdfa_parser = $self->{rdfa_parser};
 
-	my $results = rdf_query(
-		sprintf('SELECT ?endorsed WHERE { <%s> <http://www.w3.org/1999/xhtml/vocab#meta> ?endorsed . }', $self->{base_uri}),
-		$rdfa_parser->graph);
-	while (my $row = $results->next)
+	foreach my $o ($rdfa_parser->graph->objects(iri($self->{base_uri}), $xhv->meta))
 	{
 		# Endorsements must be URIs.
-		next unless UNIVERSAL::isa($row->{endorsed}, 'RDF::Trine::Node::Resource');
+		next unless $o->is_resource;
 		
 		# Endorsements must be fragments within this document.
-		next unless substr($row->{endorsed}->uri, 0 , 1+length $self->{base_uri})
-			eq $self->{base_uri}.'#';
+		my $must_start_with    = $self->{base_uri} . '#';
+		my $must_start_with_re = qr/^\Q$must_start_with\E/;
+		next unless $o->uri =~ $must_start_with_re;
 			
-		push @{ $self->{endorsements} }, $row->{endorsed}->uri;
+		push @{ $self->{endorsements} }, $o->uri;
 	}
 	
 	return $self;
 	my @scripts = $self->{'dom'}->getElementsByTagName('script');
 	foreach my $script (@scripts)
 	{
-		my $parser = $self->_choose_parser_by_type($script->getAttribute('type'));
-		$parser ||=  $self->_choose_parser_by_language($script->getAttribute('language'));
-		
+		my $parser = $self->_choose_parser_by_type($script->getAttribute('type'))
+			// $self->_choose_parser_by_language($script->getAttribute('language'));
 		next unless $parser;
 		
 		my $data  = $script->textContent;
 		my $model = RDF::Trine::Model->temporary_model;
 		$parser->parse_into_model($self->{base_uri}, $data, $model);
 		
-		my $graphname;
-		if (length $script->getAttribute('id'))
-		{
-			$graphname = $self->{base_uri} . '#' . $script->getAttribute('id');
-		}
-		else
-		{
-			$graphname = '_:bn'.(substr $uuid->create_hex, 2);
-		}
+		my $graphname = $script->hasAttribute('id')
+			? join('#', $self->{base_uri}, $script->getAttribute('id'))
+			: sprintf('_:bn%s', substr $uuid->create_hex, 2);
 		
 		$self->{'graphs'}->{$graphname} = $model;
 	}
 sub _choose_parser_by_type
 {
 	my ($self, $type) = @_;
+
+	given ($type)
+	{
+		when(m'^\s*(application|text)/(x-)?turtle\b'i)
+			{ return RDF::Trine::Parser::Turtle->new; }
+		when (m'^\s*text/plain\b'i)
+			{ return RDF::Trine::Parser::NTriples->new; }
+		when (m'^\s*(application|text)/(x-)?(rdf\+)?n3\b'i)
+			{ return RDF::Trine::Parser::Notation3->new; }
+		when (m'^\s*(application/rdf\+xml)|(text/rdf)\b'i)
+			{ return RDF::Trine::Parser::RDFXML->new; }
+		when (m'^\s*application/(x-)?(rdf\+)?json\b'i)
+			{ return RDF::Trine::Parser::RDFJSON->new; }
+	}
 	
-	if ($type =~ m'^\s*(application|text)/(x-)?turtle\b'i)
-	{
-		return RDF::Trine::Parser::Turtle->new;
-	}
-	elsif ($type =~ m'^\s*text/plain\b'i)
-	{
-		return RDF::Trine::Parser::NTriples->new;
-	}
-	elsif ($type =~ m'^\s*(application|text)/(x-)?(rdf\+)?n3\b'i)
-	{
-		return RDF::Trine::Parser::Notation3->new;
-	}
-	elsif ($type =~ m'^\s*(application/rdf\+xml)|(text/rdf)\b'i)
-	{
-		return RDF::Trine::Parser::RDFXML->new;
-	}
-	elsif ($type =~ m'^\s*application/(x-)?(rdf\+)?json\b'i)
-	{
-		return RDF::Trine::Parser::RDFJSON->new;
-	}
+	return undef;
 }
 
 sub _choose_parser_by_language
 {
 	my ($self, $language) = @_;
 	my $parser;
-	eval { $parser = RDF::Trine::Parser->new($language); };
+	eval { $parser = RDF::Trine::Parser->new($language) };
 	return $parser;
 }
 
 		my $model = RDF::Trine::Model->temporary_model;
 		while (my ($graph, $graph_model) = each %{ $self->{graphs} })
 		{
-			rdf_parse($graph_model, context=>$graph, model=>$model);
+			$graph_model->as_stream->each(sub {
+				my ($s, $p, $o) = $_[0]->nodes;
+				$model->add_statement(statement($s, $p, $o), biri($graph));
+			});
 		}
 		return $model;
 	}
 	elsif ($graph eq '::ENDORSED')
 	{
 		my $model = RDF::Trine::Model->temporary_model;
-		foreach my $graph (@{ $self->{endorsements} })
+		while (my ($graph, $graph_model) = each %{ $self->{graphs} })
 		{
-			if (defined $self->{graphs}->{$graph})
-			{
-				rdf_parse($self->{graphs}->{$graph}, context=>$graph, model=>$model);
-			}
+			next unless grep { $_ eq $graph } @{$self->{endorsements}};
+			$graph_model->as_stream->each(sub {
+				my ($s, $p, $o) = $_[0]->nodes;
+				$model->add_statement(statement($s, $p, $o), biri($graph));
+			});
 		}
 		return $model;
 	}
 
 HTML::Embedded::Turtle - embedding RDF in HTML the crazy way
 
-=head1 VERSION
-
-0.01
-
 =head1 SYNOPSIS
 
  use HTML::Embedded::Turtle;
 
 Despite the module name, this module supports a variety of
 E<lt>script typeE<gt>s: text/turtle, application/turtle, application/x-turtle
-text/plain (N-Triples), application/x-rdf+json (RDF/JSON), application/json (RDF/JSON),
-application/rdf+xml (RDF/XML). Although it doesn't support full N3,
-it recognises the following as well, but treats them as Turtle:
-text/n3, text/rdf+n3.
+text/plain (N-Triples), text/n3 (Notation 3), application/x-rdf+json (RDF/JSON),
+application/json (RDF/JSON), and application/rdf+xml (RDF/XML).
+
+The deprecated attribute "language" is also supported:
+
+ <script language="Turtle" id="foo"> ... </script>
+
+Languages supported are (case insensitive): "Turtle", "NTriples", "RDFJSON",
+"RDFXML" and "Notation3".
 
 =head2 Constructor
 
 =over 4
 
-=item C<< $het = HTML::Embedded::Turtle->new($markup, $base_uri, \%opts) >>
+=item C<< HTML::Embedded::Turtle->new($markup, $base_uri, \%opts) >>
 
 Create a new object. $markup is the HTML or XHTML markup to parse;
 $base_uri is the base URI to use for relative references.
 
 =over 4
 
-=item C<< $het->union_graph >>
+=item C<< union_graph >>
 
 A union graph of all graphs found in the document, as an RDF::Trine::Model.
 Note that the returned model contains quads.
 
-=item C<< $het->endorsed_union_graph >>
+=item C<< endorsed_union_graph >>
 
 A union graph of only the endorsed graphs, as an RDF::Trine::Model.
 Note that the returned model contains quads.
 
-=item C<< $het->graph($name) >>
+=item C<< graph($name) >>
 
 A single graph from the page.
 
-=item C<< $het->all_graphs >>
+=item C<< graphs >>
+
+=item C<< all_graphs >>
 
 A hashref where the keys are graph names and the values are
 RDF::Trine::Models. Some graph names will be URIs, and others
 may be blank nodes (e.g. "_:foobar").
 
-=item C<< $het->endorsed_graphs >>
+C<graphs> and C<all_graphs> are aliases for each other.
+
+=item C<< endorsed_graphs >>
 
 Like C<all_graphs>, but only returns endorsed graphs. Note that
 all endorsed graphs will have graph names that are URIs.
 
-=item C<< $het->endorsements >>
+=item C<< endorsements >>
 
 Returns a list of URIs which are the names of endorsed graphs. Note that
 the presence of a URI C<$x> in this list does not imply that
 C<< $het->graph($x) >> will be defined.
 
+=item C<< dom >>
+
+Returns the page DOM.
+
+=item C<< uri >>
+
+Returns the page URI.
+
 =back
 
 =head1 BUGS
 
 =head1 SEE ALSO
 
-L<RDF::RDFa::Parser>, L<RDF::Trine>.
+L<RDF::RDFa::Parser>, L<RDF::Trine>, L<RDF::TriN3>.
 
 L<http://www.perlrdf.org/>.
 
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2010 by Toby Inkster
+Copyright (C) 2010-2011 by Toby Inkster.
 
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself, either Perl version 5.8 or,
-at your option, any later version of Perl 5 you may have available.
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
 
+=head1 DISCLAIMER OF WARRANTIES
+
+THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
 =cut
+@prefix :        <http://usefulinc.com/ns/doap#> .
+@prefix dcs:     <http://ontologi.es/doap-changeset#> .
+@prefix dc:      <http://purl.org/dc/terms/> .
+@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
+@prefix my:      <http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix toby:    <http://tobyinkster.co.uk/#> .
+@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
+
+my:project :release my:v_0-01 .
+my:v_0-01
+	a               :Version ;
+	dc:issued       "2010-05-05"^^xsd:date ;
+	:revision       "0.01"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-Embedded-Turtle-0.01.tar.gz> ;
+	rdfs:label      "First release"@en .
+
+my:project :release my:v_0-090 .
+my:v_0-090
+	a               :Version ;
+	dc:issued       "2010-12-09"^^xsd:date ;
+	:revision       "0.090"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-Embedded-Turtle-0.090.tar.gz> ;
+	dcs:changeset [
+		dcs:versus my:v_0-01 ;
+		dcs:item   [ rdfs:label "use RDF::TriN3"@en ]
+		] .
+
+my:project :release my:v_0-271 .
+my:v_0-271
+	a               :Version ;
+	dc:issued       "2010-12-09"^^xsd:date ;
+	:revision       "0.271"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-Embedded-Turtle-0.271.tar.gz> ;
+	dcs:changeset [
+		dcs:versus my:v_0-090 ;
+		dcs:item   [ rdfs:label "drop dependency on RDF::TrineShortcuts"@en ] ;
+		dcs:item   [ rdfs:label "improved test cases"@en ; rdfs:comment "introduces a dependency on Test::RDF"@en ; a dcs:Packaging ] ;
+		dcs:item   [ rdfs:label "various cleanups"@en ] ;
+		dcs:item   [ rdfs:label "Module::Package::RDF"@en ; a dcs:Packaging ] ;
+		dcs:item   [ rdfs:label "use 5.010"@en ; a dcs:Update ]
+		] .
+
+@prefix :        <http://usefulinc.com/ns/doap#> .
+@prefix dcs:     <http://ontologi.es/doap-changeset#> .
+@prefix dc:      <http://purl.org/dc/terms/> .
+@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
+@prefix my:      <http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix toby:    <http://tobyinkster.co.uk/#> .
+@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
+
+my:project
+	a               :Project ;
+	:name           "HTML-Embedded-Turtle" ;
+	:shortdesc      "embedding RDF in HTML the crazy way"@en ;
+	:programming-language  "Perl" ;
+	:homepage       <https://metacpan.org/release/HTML-Embedded-Turtle> ;
+	:download-page  <https://metacpan.org/release/HTML-Embedded-Turtle> ;
+	:bug-database   <http://rt.cpan.org/Dist/Display.html?Queue=HTML-Embedded-Turtle> ;
+	:repository     [ a :SVNRepository ; :browse <http://goddamn.co.uk/svn-web/perlmods/browse/HTML-Embedded-Turtle/> ] ;
+	:maintainer     toby:i ;
+	:developer      toby:i ;
+	:documenter     toby:i ;
+	:tester         toby:i ;
+	:created        "2010-05-05"^^xsd:date ;
+	:license        <http://dev.perl.org/licenses/> ;
+	:category
+		[ rdfs:label "HTML"@en ] ,
+		[ rdfs:label "XHTML"@en ] ,
+		[ rdfs:label "script"@en ] ,
+		[ rdfs:label "RDF"@en ] ,
+		[ rdfs:label "Semantic Web"@en ] ,
+		[ rdfs:label "Turtle"@en ] ,
+		[ rdfs:label "Notation 3"@en ] ,
+		[ rdfs:label "N-Triples"@en ] ,
+		[ rdfs:label "RDF/XML"@en ] ,
+		[ rdfs:label "RDF/JSON"@en ] .
+
+toby:i
+	a               foaf:Person ;
+	foaf:name       "Toby Inkster" ;
+	foaf:homepage   <http://tobyinkster.co.uk/> ;
+	foaf:page       <https://metacpan.org/author/TOBYINK> ;
+	foaf:mbox       <mailto:tobyink@cpan.org> ;
+	<http://www.w3.org/2002/07/owl#sameAs> <http://purl.org/NET/cpan-uri/person/tobyink> .

meta/makefile.ttl

+# This file provides instructions for packaging.
+
+@prefix : <http://purl.org/NET/cpan-uri/terms#> .
+
+<http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/project>
+	:perl_version_from _:main ;
+	:version_from _:main ;
+	:readme_from _:main ;
+	:test_requires "Test::More 0.61" , "Test::RDF 0.23" ;
+	:requires "Data::UUID", "RDF::RDFa::Parser 1.093", "common::sense" ,
+		"RDF::Trine 0.135" , "RDF::TriN3" .
+
+_:main <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName> "lib/HTML/Embedded/Turtle.pm" .
+use Test::More tests => 10;
+use Test::RDF 0.23;
+use HTML::Embedded::Turtle;
+use RDF::Trine qw[statement iri literal blank variable];
+use RDF::Trine::Namespace 'rdf';
+my $foaf = RDF::Trine::Namespace->new('http://xmlns.com/foaf/0.1/');
+
+my $het = HTML::Embedded::Turtle->new(<<'MARKUP', 'http://example.net/');
+	<title property="http://purl.org/dc/terms/title">Test</title>
+	<link rel=meta href="#endorsed">
+	<script language=Turtle>
+		@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+		[] a foaf:Person ; foaf:name "Joe Bloggs" .
+	</script>
+	<script type="text/turtle" id=endorsed>
+		@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+		[] a foaf:Person ; foaf:name "Alice Smith" .
+	</script>
+	<script type="TEXT/TURTLE" id=unendorsed>
+		@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+		[] a foaf:Person ; foaf:name "Bob Smith" .
+	</script>
+	<p>Hello</p>
+MARKUP
+
+pattern_target($het->union_graph);
+
+pattern_ok(
+	statement(variable('x'), $rdf->type, $foaf->Person),
+	statement(variable('x'), $foaf->name, literal('Joe Bloggs')),
+	);
+
+pattern_ok(
+	statement(variable('x'), $rdf->type, $foaf->Person),
+	statement(variable('x'), $foaf->name, literal('Alice Smith')),
+	);
+
+pattern_ok(
+	statement(variable('x'), $rdf->type, $foaf->Person),
+	statement(variable('x'), $foaf->name, literal('Bob Smith')),
+	);
+
+is_deeply([ $het->endorsements ], ['http://example.net/#endorsed'], 'endorsed graph list is sensible');
+
+pattern_target($het->endorsed_union_graph);
+
+pattern_ok(
+	statement(variable('x'), $rdf->type, $foaf->Person),
+	statement(variable('x'), $foaf->name, literal('Alice Smith')),
+	'second graph is endorsed'
+	);
+
+is($het->endorsed_union_graph->count_statements(undef, undef, literal('Joe Bloggs')),
+	0, 'first graph is not endorsed');
+
+is($het->endorsed_union_graph->count_statements(undef, undef, literal('Bob Smith')),
+	0, 'third graph is not endorsed');
+
+isa_ok($het->dom, 'XML::LibXML::Document');
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
+

xt/02pod_coverage.t

+use Test::More;
+use Test::Pod::Coverage;
+
+my @modules = qw(HTML::Embedded::Turtle);
+pod_coverage_ok($_, "$_ is covered")
+	foreach @modules;
+done_testing(scalar @modules);
+

xt/03meta_uptodate.t

+use Test::More tests => 1;
+use Test::RDF::DOAP::Version;
+doap_version_ok('HTML-Embedded-Turtle', 'HTML::Embedded::Turtle');
+
+use Test::EOL;
+all_perl_files_ok();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.