[SCM] librdf-ns-perl Debian packaging branch, master, updated. debian/20130208-1-22-g47de138
Jakob Voss
jakob at nichtich.de
Fri Apr 19 13:28:43 UTC 2013
The following commit has been merged in the master branch:
commit 124003b676368f9248a7e97655eff1f3fb881110
Author: Jakob Voss <jakob at nichtich.de>
Date: Tue May 22 19:58:46 2012 +0200
reverse lookup
diff --git a/lib/RDF/NS.pm b/lib/RDF/NS.pm
index 3ac4cc4..fbf8abb 100644
--- a/lib/RDF/NS.pm
+++ b/lib/RDF/NS.pm
@@ -55,6 +55,23 @@ sub FORMAT {
}
}
+sub PREFIX {
+ my ($self, $uri) = @_;
+ while ( my ($prefix, $namespace) = each %$self ) {
+ return $prefix if $uri eq $namespace;
+ }
+ undef;
+}
+
+sub PREFIXES {
+ my ($self, $uri) = @_;
+ my @prefixes;
+ while ( my ($prefix, $namespace) = each %$self ) {
+ push @prefixes, $prefix if $uri eq $namespace;
+ }
+ return @prefixes;
+}
+
sub TTL {
my $self = shift;
$self->MAP( sub { "\@prefix $_: <".$self->{$_}."> ." } , @_ );
@@ -234,6 +251,16 @@ Returns a list of tabular-separated prefix-namespace-mappings.
Returns a list of BEACON format prefix definitions (not including prefixes).
+=method 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.
+
+=method PREFIXES ( $uri )
+
+Get all known prefixes of a namespace URI.
+
=method SELECT ( prefix[es] )
In list context, returns a sorted list of prefix-namespace pairs, which
diff --git a/t/prefix.t b/t/prefix.t
new file mode 100644
index 0000000..f7d3bb8
--- /dev/null
+++ b/t/prefix.t
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+use Test::More;
+
+use RDF::NS;
+
+my $rdfs = 'http://www.w3.org/2000/01/rdf-schema#';
+
+my $ns = RDF::NS->new('20111028');
+
+is $ns->PREFIX('http://www.w3.org/1999/02/22-rdf-syntax-ns#'), 'rdf', 'PREFIX';
+
+my @nslist = sort $ns->PREFIXES('http://purl.org/dc/elements/1.1/');
+
+is_deeply \@nslist, [qw(dc dc11)], 'PREFIXES';
+
+done_testing;
--
librdf-ns-perl Debian packaging
More information about the Pkg-perl-cvs-commits
mailing list