1URI::NamespaceMap(3)  User Contributed Perl Documentation URI::NamespaceMap(3)
2
3
4

NAME

6       URI::NamespaceMap - Class holding a collection of namespaces
7

VERSION

9       Version 1.08
10

SYNOPSIS

12         use URI::NamespaceMap;
13         my $map = URI::NamespaceMap->new( { xsd => 'http://www.w3.org/2001/XMLSchema#' } );
14         $map->namespace_uri('xsd')->as_string;
15         my $foaf = URI::Namespace->new( 'http://xmlns.com/foaf/0.1/' );
16         $map->add_mapping(foaf => $foaf);
17         $map->add_mapping(rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' );
18         $map->list_prefixes;  #  ( 'foaf', 'rdf', 'xsd' )
19         $map->foaf; # Returns URI::Namespace object
20         while (my ($prefix, $nsURI) = $map->each_map) {
21                $node->setNamespace($nsURI->as_string, $prefix); # For use with XML::LibXML
22         }
23

DESCRIPTION

25       This module provides an object to manage multiple namespaces for
26       creating URI::Namespace objects and for serializing.
27

METHODS

29       "new ( [ \%namespaces | @prefixes | @uris ] )"
30           Returns a new namespace map object. You can pass a hash reference
31           with mappings from local names to namespace URIs (given as string
32           or RDF::Trine::Node::Resource) or namespaces_map with a hashref.
33
34           You may also pass an arrayref containing just prefixes and/or
35           namespace URIs, and the module will try to guess the missing part.
36           To use this feature, you need RDF::NS::Curated, RDF::NS,
37           XML::CommonNS or RDF::Prefixes, or preferably all of them. With
38           that, you can do e.g.
39
40             my $map = URI::NamespaceMap->new( 'rdf', 'xsd', 'foaf' );
41
42           and have the correct mappings added automatically.
43
44       "add_mapping ( $name => $uri )"
45           Adds a new namespace to the map. The namespace URI can be passed as
46           string or a URI::Namespace object.
47
48       "remove_mapping ( $name )"
49           Removes a namespace from the map given a prefix.
50
51       "namespace_uri ( $name )"
52           Returns the URI::Namespace object (if any) associated with the
53           given prefix.
54
55       $name
56           This module creates a method for all the prefixes, so you can say
57           e.g.
58
59             $map->foaf
60
61           and get a URI::Namespace object for the FOAF namespace. Since
62           URI::Namespace does the same for local names, you can then say e.g.
63
64             $map->foaf->name
65
66           to get a full URI.
67
68       "list_namespaces"
69           Returns an array of URI::Namespace objects with all the namespaces.
70
71       "list_prefixes"
72           Returns an array of prefixes.
73
74       "each_map"
75           Returns an 2-element list where the first element is a prefix and
76           the second is the corresponding URI::Namespace object.
77
78       "guess_and_add ( @string_or_uri )"
79           Like in the constructor, an array of strings can be given, and the
80           module will attempt to guess appropriate mappings, and add them to
81           the map.
82
83       "uri ( $prefixed_name )"
84           Returns a URI for an abbreviated string such as 'foaf:Person'.
85
86       prefix_for "uri ($uri)"
87           Returns the associated prefix (or potentially multiple prefixes,
88           when called in list context) for the given URI.
89
90       abbreviate "uri ($uri)"
91           Complement to "namespace_uri". Returns the given URI in "foo:bar"
92           format or "undef" if it wasn't matched, therefore the idiom
93
94               my $str = $nsmap->abbreviate($uri_node) || $uri->as_string;
95
96           may be useful for certain serialization tasks.
97

WARNING

99       Avoid using the names 'can', 'isa', 'VERSION', and 'DOES' as namespace
100       prefix, because these names are defined as method for every Perl object
101       by default. The method names 'new' and 'uri' are also forbidden. Names
102       of methods of Moose::Object must also be avoided.
103
104       Using them will result in an error.
105

AUTHORS

107       Chris Prather, "<chris@prather.org>" Kjetil Kjernsmo,
108       "<kjetilk@cpan.org>" Gregory Todd Williams, "<gwilliams@cpan.org>" Toby
109       Inkster, "<tobyink@cpan.org>"
110

CONTRIBUTORS

112       Dorian Taylor Paul Williams
113

BUGS

115       Please report any bugs using github <https://github.com/kjetilk/URI-
116       NamespaceMap/issues>
117

SUPPORT

119       You can find documentation for this module with the perldoc command.
120
121           perldoc URI::NamespaceMap
122
124       Copyright 2012,2013,2014,2015,2016,2017,2018 Gregory Todd Williams,
125       Chris Prather and Kjetil Kjernsmo
126
127       This program is free software; you can redistribute it and/or modify it
128       under the same terms as Perl itself.
129
130
131
132perl v5.28.1                      2019-04-15              URI::NamespaceMap(3)
Impressum