RDF::Prefixes(3pm) | User Contributed Perl Documentation | RDF::Prefixes(3pm) |
RDF::Prefixes - simple way to turn URIs into QNames
my $context = RDF::Prefixes->new; say $context->qname('http://purl.org/dc/terms/title'); # dc:title say $context->qname('http://example.net/rdf/dc#title'); # dc2:title say $context->turtle; # @prefix dc: <http://purl.org/dc/terms/> . # @prefix dc2: <http://example.net/rdf/dc#> .
This module is not so much for managing namespaces/prefixes in code (see RDF::Trine::NamespaceMap for that), but as a helper for code that serialises data using namespaces.
It generates pretty prefixes, reducing "http://purl.org/dc/terms/" to "dc" rather than something too generic like like "ns01", and provides a context for keeping track of namespaces already used, so that when "http://purl.org/dc/elements/1.1/" is encountered, it won't stomp on the previous definition of "dc".
Suggestions for prefix mappings may be given, but there's no guarantee that they'll be used.
The only option right now is 'syntax' that is used by the to_string method.
Both hashrefs are optional.
Some URIs cannot be converted to QNames. In these cases, undef is returned.
foreach my $prefix (keys %$context) { printf("%s => %s\n", $prefix, $context->{$prefix}); }
my $context = RDF::Prefixes->new({}, {syntax=>'turtle'}); my $dc_title = 'http://purl.org/dc/terms/title'; print "# Prefixes\n" . $context;
Strings passed to and from this module are expected to be utf8 character strings, not byte strings. This is not explicitly checked for, but will be checked in a future version, so be warned!
URIs containing non-Latin characters should "just work".
Please report any bugs to <http://rt.cpan.org/>.
Toby Inkster <tobyink@cpan.org>.
Copyright 2010-2013 Toby Inkster
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
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.
2022-06-17 | perl v5.34.0 |