[libhtml-embedded-turtle-perl] 11/28: slight cleanup, release as v0.271

Jonas Smedegaard js at alioth.debian.org
Fri Aug 9 16:24:31 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libhtml-embedded-turtle-perl.

commit f06c7a5a99f4d7dcaa183af72d763572466196e9
Author: Toby Inkster <mail at tobyinkster.co.uk>
Date:   Thu Nov 3 22:34:29 2011 +0000

    slight cleanup, release as v0.271
    
    --HG--
    branch : HTML-Embedded-Turtle
    rename : example1.pl => examples/simple-example.pl
    rename : Changes.ttl => meta/changes.ttl
    extra : convert_revision : svn%3A3fe8e991-6959-4966-b76d-b07eca2b6e37/HTML-Embedded-Turtle%401034
---
 Changes                      |   17 -----
 Changes.xml                  |   60 ---------------
 MANIFEST.SKIP                |   10 ---
 META.yml                     |   44 -----------
 Makefile.PL                  |   43 +----------
 README                       |  108 ---------------------------
 TODO                         |    3 -
 example1.pl                  |   32 --------
 examples/simple-example.pl   |   31 ++++++++
 lib/HTML/Embedded/Turtle.pm  |  167 +++++++++++++++++++++++-------------------
 meta/changes.ttl             |   43 +++++++++++
 Changes.ttl => meta/doap.ttl |   52 +++----------
 meta/makefile.ttl            |   13 ++++
 t/02data.t                   |   59 +++++++++++++++
 xt/01pod.t                   |    5 ++
 xt/02pod_coverage.t          |    8 ++
 xt/03meta_uptodate.t         |    4 +
 xt/04eol.t                   |    2 +
 18 files changed, 268 insertions(+), 433 deletions(-)

diff --git a/Changes b/Changes
deleted file mode 100644
index faa3800..0000000
--- a/Changes
+++ /dev/null
@@ -1,17 +0,0 @@
-############################################################################
-## 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 at cpan.org>
-
-0.090 [2010-12-09]
- - use RDF::TriN3
-
-0.01 [2010-05-05] # First release
-
diff --git a/Changes.xml b/Changes.xml
deleted file mode 100644
index b0778bf..0000000
--- a/Changes.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-<?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 at cpan.org"/>
-	<foaf:name>Toby Inkster</foaf:name>
-	<foaf:page rdf:resource="http://search.cpan.org/~tobyink/"/>
-</rdf:Description>
-</rdf:RDF>
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
deleted file mode 100644
index 6341a6d..0000000
--- a/MANIFEST.SKIP
+++ /dev/null
@@ -1,10 +0,0 @@
-^MANIFEST.bak$
-^Makefile.old$
-^Makefile$
-^blib/
-^pm_to_blib
-^blibdirs
-\.svn
-^example.*\.pl$
-^[^/]+\.(tar\.gz|tar\.bz2|tgz|tbz2|tbz|zip|tar)$
-^MYMETA.yml
\ No newline at end of file
diff --git a/META.yml b/META.yml
deleted file mode 100644
index 8752c48..0000000
--- a/META.yml
+++ /dev/null
@@ -1,44 +0,0 @@
----
-abstract: 'embedding RDF in HTML the crazy way'
-author:
-  - 'Toby Inkster <tobyink at 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
diff --git a/Makefile.PL b/Makefile.PL
index 52da358..01e5b33 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,42 +1 @@
-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 at 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';
diff --git a/README b/README
deleted file mode 100644
index 9684c66..0000000
--- a/README
+++ /dev/null
@@ -1,108 +0,0 @@
-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 at 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.
-
diff --git a/TODO b/TODO
deleted file mode 100644
index 54443fd..0000000
--- a/TODO
+++ /dev/null
@@ -1,3 +0,0 @@
-TODO:
-1. Add some more items to this list.
-2. ...
diff --git a/example1.pl b/example1.pl
deleted file mode 100644
index cb3e0d3..0000000
--- a/example1.pl
+++ /dev/null
@@ -1,32 +0,0 @@
-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;
-}
\ No newline at end of file
diff --git a/examples/simple-example.pl b/examples/simple-example.pl
new file mode 100644
index 0000000..d506d63
--- /dev/null
+++ b/examples/simple-example.pl
@@ -0,0 +1,31 @@
+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 ]);
diff --git a/lib/HTML/Embedded/Turtle.pm b/lib/HTML/Embedded/Turtle.pm
index 4230386..52e3637 100644
--- a/lib/HTML/Embedded/Turtle.pm
+++ b/lib/HTML/Embedded/Turtle.pm
@@ -1,13 +1,22 @@
 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
 {
@@ -17,17 +26,16 @@ 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
@@ -35,19 +43,17 @@ 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;
@@ -61,24 +67,17 @@ sub _extract_graphs
 	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;
 	}
@@ -89,34 +88,29 @@ sub _extract_graphs
 sub _choose_parser_by_type
 {
 	my ($self, $type) = @_;
-	
-	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)
+
+	given ($type)
 	{
-		return RDF::Trine::Parser::RDFJSON->new;
+		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; }
 	}
+	
+	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;
 }
 
@@ -129,19 +123,23 @@ sub graph
 		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;
 	}
@@ -230,10 +228,6 @@ __END__
 
 HTML::Embedded::Turtle - embedding RDF in HTML the crazy way
 
-=head1 VERSION
-
-0.01
-
 =head1 SYNOPSIS
 
  use HTML::Embedded::Turtle;
@@ -268,16 +262,21 @@ or as a union of just the endorsed graphs.
 
 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.
@@ -306,37 +305,49 @@ probably sensible.
 
 =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
@@ -347,7 +358,7 @@ Please forgive me in advance for inflicting this module upon you.
 
 =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/>.
 
@@ -357,11 +368,15 @@ Toby Inkster E<lt>tobyink at cpan.orgE<gt>.
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2010 by Toby Inkster
+Copyright (C) 2010-2011 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
 
-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.
+=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
diff --git a/meta/changes.ttl b/meta/changes.ttl
new file mode 100644
index 0000000..62633f1
--- /dev/null
+++ b/meta/changes.ttl
@@ -0,0 +1,43 @@
+ at prefix :        <http://usefulinc.com/ns/doap#> .
+ at prefix dcs:     <http://ontologi.es/doap-changeset#> .
+ at prefix dc:      <http://purl.org/dc/terms/> .
+ at prefix foaf:    <http://xmlns.com/foaf/0.1/> .
+ at prefix my:      <http://purl.org/NET/cpan-uri/dist/HTML-Embedded-Turtle/> .
+ at prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+ at prefix toby:    <http://tobyinkster.co.uk/#> .
+ at 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 ]
+		] .
+
diff --git a/Changes.ttl b/meta/doap.ttl
similarity index 55%
rename from Changes.ttl
rename to meta/doap.ttl
index 9a9971b..bb6995f 100644
--- a/Changes.ttl
+++ b/meta/doap.ttl
@@ -1,5 +1,3 @@
-#############################################################
-
 @prefix :        <http://usefulinc.com/ns/doap#> .
 @prefix dcs:     <http://ontologi.es/doap-changeset#> .
 @prefix dc:      <http://purl.org/dc/terms/> .
@@ -9,40 +7,7 @@
 @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 ;
@@ -57,17 +22,22 @@ my:project
 	:tester         toby:i ;
 	:created        "2010-05-05"^^xsd:date ;
 	:license        <http://dev.perl.org/licenses/> ;
-	:release        my:v_0-01 , my:v_0-090 .
-
-#############################################################
+	: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 at cpan.org> ;
 	<http://www.w3.org/2002/07/owl#sameAs> <http://purl.org/NET/cpan-uri/person/tobyink> .
-
-#############################################################
diff --git a/meta/makefile.ttl b/meta/makefile.ttl
new file mode 100644
index 0000000..1e12a45
--- /dev/null
+++ b/meta/makefile.ttl
@@ -0,0 +1,13 @@
+# This file provides instructions for packaging.
+
+ at 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" .
diff --git a/t/02data.t b/t/02data.t
new file mode 100644
index 0000000..46a0387
--- /dev/null
+++ b/t/02data.t
@@ -0,0 +1,59 @@
+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');
\ No newline at end of file
diff --git a/xt/01pod.t b/xt/01pod.t
new file mode 100644
index 0000000..92ba3f6
--- /dev/null
+++ b/xt/01pod.t
@@ -0,0 +1,5 @@
+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();
+
diff --git a/xt/02pod_coverage.t b/xt/02pod_coverage.t
new file mode 100644
index 0000000..89ed60a
--- /dev/null
+++ b/xt/02pod_coverage.t
@@ -0,0 +1,8 @@
+use Test::More;
+use Test::Pod::Coverage;
+
+my @modules = qw(HTML::Embedded::Turtle);
+pod_coverage_ok($_, "$_ is covered")
+	foreach @modules;
+done_testing(scalar @modules);
+
diff --git a/xt/03meta_uptodate.t b/xt/03meta_uptodate.t
new file mode 100644
index 0000000..e43e7b0
--- /dev/null
+++ b/xt/03meta_uptodate.t
@@ -0,0 +1,4 @@
+use Test::More tests => 1;
+use Test::RDF::DOAP::Version;
+doap_version_ok('HTML-Embedded-Turtle', 'HTML::Embedded::Turtle');
+
diff --git a/xt/04eol.t b/xt/04eol.t
new file mode 100644
index 0000000..3877ffa
--- /dev/null
+++ b/xt/04eol.t
@@ -0,0 +1,2 @@
+use Test::EOL;
+all_perl_files_ok();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libhtml-embedded-turtle-perl.git



More information about the Pkg-perl-cvs-commits mailing list