[SCM] librdf-ns-perl Debian packaging branch, master, updated. debian/20130208-1-22-g47de138

Jakob Voss voss at gbv.de
Fri Apr 19 13:28:44 UTC 2013


The following commit has been merged in the master branch:
commit 977ba1d2b064122d3852d3d00a9d8f9ebe4fe4bf
Author: Jakob Voss <voss at gbv.de>
Date:   Wed Sep 5 09:32:41 2012 +0200

    found yet another namespace module (URI::NamespaceMap)

diff --git a/lib/RDF/NS.pm b/lib/RDF/NS.pm
index da114de..d3e1c22 100644
--- a/lib/RDF/NS.pm
+++ b/lib/RDF/NS.pm
@@ -154,7 +154,9 @@ sub GET {
 sub BLANK {
 }
 
-sub URI {
+*URI = *uri;
+
+sub uri {
     my $self = shift;
 	return $1 if $_[0] =~ /^<([a-zA-Z][a-zA-Z+.-]*:.+)>$/;
 	return $self->BLANK($_[0]) if $_[0] =~ /^_(:.*)?$/;
@@ -225,7 +227,7 @@ sub UPDATE {
   $ns->foaf;               # http://xmlns.com/foaf/0.1/
   $ns->foaf_Person;        # http://xmlns.com/foaf/0.1/Person
   $ns->foaf('Person');     # http://xmlns.com/foaf/0.1/Person
-  $ns->URI('foaf:Person'); # http://xmlns.com/foaf/0.1/Person
+  $ns->uri('foaf:Person'); # http://xmlns.com/foaf/0.1/Person
 
   use RDF::NS;             # get rid if typing '$' by defining a constant
   use constant NS => RDF::NS->new('20111208');
@@ -235,11 +237,6 @@ sub UPDATE {
   $ns->TTL('foaf');        # @prefix foaf: <http://xmlns.com/foaf/0.1/> .
   $ns->XMLNS('foaf');      # xmlns:foaf="http://xmlns.com/foaf/0.1/"
 
-  # get RDF::Trine::Node::Resource instead of strings
-  use RDF::NS::Trine;      # requires RDF::Trine
-  $ns = RDF::NS::Trine->new('20120829');
-  $ns->foaf_Person;        # iri('http://xmlns.com/foaf/0.1/Person')
-
   # load your own mapping from a file
   $ns = RDF::NS->new("mapping.txt");
 
@@ -277,7 +274,11 @@ The code repository of this module also contains an
 L<update script|https://github.com/nichtich/RDF-NS/blob/master/update.pl>
 to download the current prefix-namespace mappings from L<http://prefix.cc>.
 
-=method new ( $file_or_date [, %options ] )
+=head1 GENERAL METHODS
+
+In most cases you only need the following lowercase methods.
+
+=head2 new ( $file_or_date [, %options ] )
 
 Create a new namespace mapping from a selected file or date. The special string
 C<"any"> can be used to get the newest mapping, but you should better select a
@@ -285,72 +286,86 @@ specific version, as mappings can change, violating backwards compatibility.
 Supported options include C<warn> to enable warnings and C<at> to specify a
 date. 
 
-=method LOAD ( $file_or_date [, %options ] )
+=head2 E<prefix>
+
+Returns the namespace for E<prefix> if namespace prefix is defined. For
+instance C<< $ns->foaf >> returns C<http://xmlns.com/foaf/0.1/>.
 
-=method URI ( $short | "<$URI>" )
+=head2 E<prefix_name>
+
+Returns the namespace plus local name, if namespace prefix is defined. For
+instance C<< $ns->foaf_Person >> returns C<http://xmlns.com/foaf/0.1/Person>.
+
+=head2 uri ( $short | "<$URI>" )
 
 Expand a prefixed URI, such as C<foaf:Person> or C<foaf_Person>. Alternatively 
 you can expand prefixed URIs with method calls, such as C<$ns-E<gt>foaf_Person>.
 If you pass an URI wrapped in C<E<lt>> and C<E<gt>>, it will not be expanded
 but returned as given.
 
-=method TTL ( prefix[es] )
+=head1 SERIALIZATION METHODS
+
+=head2 TTL ( prefix[es] )
 
 Returns a Turtle/Notation3 C<@prefix> definition or a list of such definitions
 in list context. Prefixes can be passed as single arguments or separated by
 commas, vertical bars, and spaces.
 
-=method SPARQL ( prefix[es] )
+=head2 SPARQL ( prefix[es] )
 
 Returns a SPARQL PREFIX definition or a list of such definitions in list
 context. Prefixes can be passed as single arguments or separated by commas,
 vertical bars, and spaces.
 
-=method XMLNS ( prefix[es] )
+=head2 XMLNS ( prefix[es] )
 
 Returns an XML namespace declaration or a list of such declarations in list
 context. Prefixes can be passed as single arguments or separated by commas,
 vertical bars, and spaces.
 
-=method TXT ( prefix[es] )
+=head2 TXT ( prefix[es] )
 
 Returns a list of tabular-separated prefix-namespace-mappings.
 
-=method BEACON ( prefix[es] )
+=head2 BEACON ( prefix[es] )
 
 Returns a list of BEACON format prefix definitions (not including prefixes).
 
-=method PREFIX ( $uri )
+=head1 LOOKUP METHODS
+
+=head2 PREFIX ( $uri )
 
 Get a prefix of a namespace URI, if it is defined. This method does a reverse
 lookup which is less performant than the other direction. If multiple prefixes
 are defined, it is not determinstic which one is returned. If you need to call
 this method frequently, better create a reverse hash (method REVERSE).
 
-=method PREFIXES ( $uri )
+=head2 PREFIXES ( $uri )
 
 Get all known prefixes of a namespace URI.
 
-=method REVERSE
+=head2 REVERSE
 
 Create a lookup hash from namespace URIs to prefixes. If multiple prefixes
 exist, the shortes will be used.
 
-=method SELECT ( prefix[es] )
+=head2 SELECT ( prefix[es] )
 
 In list context, returns a sorted list of prefix-namespace pairs, which
 can be used to assign to a hash. In scalar context, returns the namespace
 of the first prefix that was found. Prefixes can be passed as single arguments
 or separated by commas, vertical bars, and spaces.
 
-=method MAP ( $code [, prefix[es] ] )
+=head1 INTERNAL METHODS
+
+=head2 MAP ( $code [, prefix[es] ] )
 
 Internally used to map particular or all prefixes. Prefixes can be selected as
 single arguments or separated by commas, vertical bars, and spaces. In scalar
 context, C<$_> is set to the first existing prefix (if found) and C<$code> is
 called. In list context, found prefixes are sorted at mapped with C<$code>.
 
-=method GET ( $uri )
+=head2 GET ( $uri )
 
 This method is used internally to create URIs as return value of the URI
 method and all lowercase shortcut methods, such as C<foaf_Person>. By default
@@ -359,8 +374,8 @@ it just returns C<$uri> unmodified.
 =head1 SEE ALSO
 
 There are several other CPAN modules to deal with IRI namespaces, for instance
-L<RDF::Trine::Namespace>, L<RDF::Trine::NamespaceMap>, L<RDF::Prefixes>,
-L<RDF::Simple::NS>, L<RDF::RDFa::Parser::Profile::PrefixCC>,
+L<RDF::Trine::Namespace>, L<RDF::Trine::NamespaceMap>, L<URI::NamespaceMap>,
+L<RDF::Prefixes>, L<RDF::Simple::NS>, L<RDF::RDFa::Parser::Profile::PrefixCC>,
 L<Class::RDF::NS>, L<XML::Namespace>, L<XML::CommonNS> etc.
 
 =cut
diff --git a/lib/RDF/NS/Trine.pm b/lib/RDF/NS/Trine.pm
index b40eb38..c87a642 100644
--- a/lib/RDF/NS/Trine.pm
+++ b/lib/RDF/NS/Trine.pm
@@ -23,21 +23,27 @@ sub BLANK {
   use RDF::NS::Trine;
   use constant NS => RDF::NS::Trine->new('20120829');
 
-  NS->foaf_Person;        # a RDF::Trine::Node::Resource
-  NS->URI('foaf:Person);  # same
+  NS->foaf_Person;        # iri('http://xmlns.com/foaf/0.1/Person')
+  NS->uri('foaf:Person);  #  same RDF::Trine::Node::Resource
   NS->foaf_Person->uri;   # http://xmlns.com/foaf/0.1/Person
 
-  NS->_;                  # a RDF::Trine::Node::Blank
-  NS->_abc;               # a blank node with id 'abc'
-  NS->URI('_:abc');       # same
+  NS->_;                  # RDF::Trine::Node::Blank
+  NS->_abc;               # blank node with id 'abc'
+  NS->uri('_:abc');       # same
 
 =head1 DESCRIPTION
 
-In contrast to L<RDF::NS>, which should be consulted for documentation, this
-returns no plain string URIs but instances of L<RDF::Trine::Node::Resource>
-or L<RDF::Trine::Node::Blank>.
+RDF::NS::Trine works like L<RDF::NS> but it returns instances of
+L<RDF::Trine::Node::Resource> (and L<RDF::Trine::Node::Blank> instead of
+strings.
 
 Before using this module, make sure to install L<RDF::Trine>, which is not
 installed automatically together with L<RDF::NS>!
 
+=head1 ADDITIONAL METHODS
+
+=head1 BLANK ( [ $short ] )
+
+Returns a new L<RDF::Trine::Node::Blank>.
+
 =cut
diff --git a/lib/RDF/NS/URIS.pm b/lib/RDF/NS/URIS.pm
new file mode 100644
index 0000000..4e50a24
--- /dev/null
+++ b/lib/RDF/NS/URIS.pm
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+package RDF::NS::URIS;
+#ABSTRACT: Popular RDF namespace prefixes from prefix.cc as URI objects
+
+use URI;
+use base 'RDF::NS';
+
+sub GET {
+    URI->new($_[1]);
+}
+
+1;
+
+=head1 SYNOPSIS
+
+  use RDF::NS::URIS;
+  use constant NS => RDF::NS::URIS->new('20120829');
+
+  NS->foaf_Person;             # an URI object
+  NS->uri('foaf:Person);       # same
+  NS->foaf_Person->as_string;  # http://xmlns.com/foaf/0.1/Person
+
+=head1 DESCRIPTION
+
+RDF::NS::URIS works like L<RDF::NS> but it returns instances of L<URI> instead
+of plain strings.
+
+=head1 SEE ALSO
+
+L<URI::NamespaceMap>
+
+=cut
diff --git a/t/trine.t b/t/trine.t
index a1fd3f8..7a336e4 100644
--- a/t/trine.t
+++ b/t/trine.t
@@ -2,10 +2,10 @@ use strict;
 use warnings;
 use Test::More;
 
-eval { require RDF::Trine::Node::Resource; };
+eval { require RDF::Trine; };
 my $version = $RDF::Trine::VERSION || 0; 
 if ( $@ or $version < 0.140) {
-	diag("RDF::Trine missing or too old - skip tests of RDF::NS::Trine");
+	diag("RDF::Trine missing: $version - skip tests of RDF::NS::Trine");
 	ok(1, "skip tests");
 	done_testing;
 	exit 0;
diff --git a/t/uris.t b/t/uris.t
new file mode 100644
index 0000000..706d31f
--- /dev/null
+++ b/t/uris.t
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use Test::More;
+
+use RDF::NS::URIS;
+use constant NS => RDF::NS::URIS->new('20120829');
+
+use URI;
+
+my $foaf = 'http://xmlns.com/foaf/0.1/';
+my $person = $foaf."Person";
+
+is NS->foaf,               URI->new($foaf);
+is NS->foaf_Person,        URI->new($person);
+is NS->URI('foaf:Person'), URI->new($person);
+is NS->foaf_Person->as_string, $person;
+
+done_testing;
diff --git a/update.pl b/update.pl
index ac08eb9..43c75d2 100755
--- a/update.pl
+++ b/update.pl
@@ -1,5 +1,7 @@
 #!/usr/bin/perl
 
+use strict;
+use warnings;
 use LWP::Simple qw(mirror);
 use RDF::NS;
 use File::Temp;
@@ -24,18 +26,18 @@ my $url = "http://prefix.cc/popular/all.file.txt";
 mirror($url,$tmp) or die "Failed to load $url";
 my $new = RDF::NS->LOAD( $tmp, warn => 1 );
 
-$new->UPDATE( "share/prefix.cc", $new_version );
+my $diff = $new->UPDATE( "share/prefix.cc", $new_version );
 
 foreach my $change (qw(create delete update)) {
     my $prefixes = $diff->{$change} or next;
     foreach my $prefix (@$prefixes) {
         if ($change eq 'create') {
-            printf "+ $prefix %s\n", $ns->URI($prefix);
+            printf "+ $prefix %s\n", $new->URI($prefix);
         } elsif ($change eq 'delete') {
-            printf "- $prefix %s\n", $old->URI($prefix);
+            printf "- $prefix %s\n", $cur->URI($prefix);
         } else {
-            printf "- $prefix %s\n", $old->URI($prefix);
-            printf "+ $prefix %s\n", $ns->URI($prefix);
+            printf "- $prefix %s\n", $cur->URI($prefix);
+            printf "+ $prefix %s\n", $new->URI($prefix);
         }
     }
 }
@@ -46,7 +48,7 @@ push @log, "  added: " . join(",",@{$diff->{create}}) if @{$diff->{create}};
 push @log, "  removed: " . join(",",@{$diff->{delete}}) if @{$diff->{delete}};
 push @log, "  changed: " . join(",",@{$diff->{update}}) if @{$diff->{update}};
 
-foreach my $file (qw(dist.ini lib/RDF/NS.pm lib/RDF/NS/Trine.pm README)) {
+foreach my $file (qw(dist.ini lib/RDF/NS.pm lib/RDF/NS/Trine.pm lib/RDF/NS/URIS.pm README)) {
     print "$cur_version => $new_version in $file\n";
     local ($^I, at ARGV)=('.bak',$file);
     while(<>) {
@@ -64,14 +66,16 @@ do {
         }
         print; 
     } 
-}
+};
 
-print <<'GIT'
+print <<HELP;
 To store and release the changes, call:
  
-  git add Changes README dist.ini lib/RDF/NS.pm lib/RDF/NS/Trine.pm share/$new_version.txt
+  git add Changes README dist.ini lib/RDF/NS.pm lib/RDF/NS/Trine.pm share/prefix.cc
   git commit -m "update to $new_version"
   git tag $new_version
   dzil release
 
-GIT
+HELP
+
+1;

-- 
librdf-ns-perl Debian packaging



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