This is an automated email from the git hooks/post-receive script. js pushed a commit to branch master in repository librdf-ns-perl.
commit da4a39a6cf9e4b42960fdfbdbb61f940f0834da0 Author: Jakob Voss <v...@gbv.de> Date: Wed Jan 11 17:01:59 2017 +0100 Look up prefixes in sorted order (#17) --- README.md | 8 ++++---- lib/RDF/NS.pm | 12 ++++++------ t/prefix.t | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0533eac..3afac2e 100644 --- a/README.md +++ b/README.md @@ -126,13 +126,13 @@ Returns a list of BEACON format prefix definitions (not including prefixes). 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 and with deterministic response, better create a reverse -hash (method REVERSE). +are defined, the first in sorted order is returned. If you need to call this +method frequently and with deterministic response, better create a reverse hash +(method REVERSE). ## PREFIXES ( $uri ) -Get all known prefixes of a namespace URI. +Get all known prefixes of a namespace URI in sorted order. ## REVERSE diff --git a/lib/RDF/NS.pm b/lib/RDF/NS.pm index 7ce7342..78d8a4d 100644 --- a/lib/RDF/NS.pm +++ b/lib/RDF/NS.pm @@ -107,7 +107,7 @@ sub FORMAT { sub PREFIX { my ($self, $uri) = @_; - foreach my $prefix ( keys %$self ) { + foreach my $prefix ( sort keys %$self ) { return $prefix if $uri eq $self->{$prefix}; } return; @@ -119,7 +119,7 @@ sub PREFIXES { while ( my ($prefix, $namespace) = each %$self ) { push @prefixes, $prefix if $uri eq $namespace; } - return @prefixes; + return(sort(@prefixes)); } sub REVERSE { @@ -379,13 +379,13 @@ Returns a list of BEACON format prefix definitions (not including prefixes). 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 and with deterministic response, better create a reverse -hash (method REVERSE). +are defined, the first in sorted order is returned. If you need to call this +method frequently and with deterministic response, better create a reverse hash +(method REVERSE). =head2 PREFIXES ( $uri ) -Get all known prefixes of a namespace URI. +Get all known prefixes of a namespace URI in sorted order. =head2 REVERSE diff --git a/t/prefix.t b/t/prefix.t index 5b2639b..081858a 100644 --- a/t/prefix.t +++ b/t/prefix.t @@ -12,7 +12,8 @@ my $ns = RDF::NS->new('20111028'); is $ns->PREFIX('http://www.w3.org/1999/02/22-rdf-syntax-ns#'), 'rdf', 'PREFIX'; is $ns->PREFIX('http://127.0.0.1/dev/null'), undef, 'not existing prefix'; -is_deeply [ sort $ns->PREFIXES($dc) ], [qw(dc dc11)], 'PREFIXES has dc, dc11'; +is $ns->PREFIX($dc), 'dc', 'PREFIX dc'; +is_deeply [ $ns->PREFIXES($dc) ], [qw(dc dc11)], 'PREFIXES has dc, dc11'; my $rev = $ns->REVERSE; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/librdf-ns-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits