Debian Codegraph @

README

raw
1 NAME
2 URI::NamespaceMap - Class holding a collection of namespaces
3
4 VERSION
5 Version 1.12
6
7 SYNOPSIS
8 use URI::NamespaceMap;
9 my $map = URI::NamespaceMap->new( { xsd => 'http://www.w3.org/2001/XMLSchema#' } );
10 $map->namespace_uri('xsd')->as_string;
11 my $foaf = URI::Namespace->new( 'http://xmlns.com/foaf/0.1/' );
12 $map->add_mapping(foaf => $foaf);
13 $map->add_mapping(rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' );
14 $map->list_prefixes; # ( 'foaf', 'rdf', 'xsd' )
15 $map->foaf; # Returns URI::Namespace object
16 while (my ($prefix, $nsURI) = $map->each_map) {
17 $node->setNamespace($nsURI->as_string, $prefix); # For use with XML::LibXML
18 }
19
20 DESCRIPTION
21 This module provides an object to manage multiple namespaces for creating
22 URI::Namespace objects and for serializing.
23
24 METHODS
25 `new ( [ \%namespaces | @prefixes | @uris ] )`
26 Returns a new namespace map object. You can pass a hash reference with
27 mappings from local names to namespace URIs (given as string or
28 RDF::Trine::Node::Resource) or namespaces_map with a hashref.
29
30 You may also pass an arrayref containing just prefixes and/or
31 namespace URIs, and the module will try to guess the missing part. To
32 use this feature, you need RDF::NS::Curated, RDF::NS, XML::CommonNS or
33 RDF::Prefixes, or preferably all of them. With that, you can do e.g.
34
35 my $map = URI::NamespaceMap->new( 'rdf', 'xsd', 'foaf' );
36
37 and have the correct mappings added automatically.
38
39 `add_mapping ( $name => $uri )`
40 Adds a new namespace to the map. The namespace URI can be passed as
41 string or a URI::Namespace object.
42
43 `remove_mapping ( $name )`
44 Removes a namespace from the map given a prefix.
45
46 `namespace_uri ( $name )`
47 Returns the URI::Namespace object (if any) associated with the given
48 prefix.
49
50 $name
51 This module creates a method for all the prefixes, so you can say e.g.
52
53 $map->foaf
54
55 and get a URI::Namespace object for the FOAF namespace. Since
56 URI::Namespace does the same for local names, you can then say e.g.
57
58 $map->foaf->name
59
60 to get a full URI.
61
62 `list_namespaces`
63 Returns an array of URI::Namespace objects with all the namespaces.
64
65 `list_prefixes`
66 Returns an array of prefixes.
67
68 `each_map`
69 Returns an 2-element list where the first element is a prefix and the
70 second is the corresponding URI::Namespace object.
71
72 `guess_and_add ( @string_or_uri )`
73 Like in the constructor, an array of strings can be given, and the
74 module will attempt to guess appropriate mappings, and add them to the
75 map.
76
77 `uri ( $prefixed_name )`
78 Returns a URI for an abbreviated string such as 'foaf:Person'.
79
80 prefix_for `uri ($uri)`
81 Returns the associated prefix (or potentially multiple prefixes, when
82 called in list context) for the given URI.
83
84 abbreviate `uri ($uri)`
85 Complement to "namespace_uri". Returns the given URI in `foo:bar`
86 format or `undef` if it wasn't matched, therefore the idiom
87
88 my $str = $nsmap->abbreviate($uri_node) || $uri->as_string;
89
90 may be useful for certain serialization tasks.
91
92 WARNING
93 Avoid using the names 'can', 'isa', 'VERSION', and 'DOES' as namespace
94 prefix, because these names are defined as method for every Perl object by
95 default. The method names 'new' and 'uri' are also forbidden. Names of
96 methods of Moose::Object must also be avoided.
97
98 Using them will result in an error.
99
100 AUTHORS
101 Chris Prather, `<[email protected]>` Kjetil Kjernsmo, `<[email protected]>`
102 Gregory Todd Williams, `<[email protected]>` Toby Inkster,
103 `<[email protected]>`
104
105 CONTRIBUTORS
106 Dorian Taylor Paul Williams Zakariyya Mughal Chris Prather
107
108 BUGS
109 Please report any bugs using github
110 <https://github.com/kjetilk/URI-NamespaceMap/issues>
111
112 SUPPORT
113 You can find documentation for this module with the perldoc command.
114
115 perldoc URI::NamespaceMap
116
117 COPYRIGHT & LICENSE
118 Copyright 2012,2013,2014,2015,2016,2017,2018,2019 Gregory Todd Williams,
119 Chris Prather and Kjetil Kjernsmo
120
121 This program is free software; you can redistribute it and/or modify it
122 under the same terms as Perl itself.
123