File Coverage

blib/lib/XML/CommonNS.pm
Criterion Covered Total %
statement 40 40 100.0
branch 3 6 50.0
condition n/a
subroutine 10 10 100.0
pod 1 1 100.0
total 54 57 94.7


line stmt bran cond sub pod time code
1             package XML::CommonNS;
2 2     2   50006 use strict;
  2         5  
  2         88  
3 2     2   11 use warnings;
  2         4  
  2         58  
4 2     2   1729 use XML::NamespaceFactory qw();
  2         6689  
  2         36  
5 2     2   14 use Exporter;
  2         6  
  2         81  
6 2     2   10 use vars qw($VERSION %NS @ISA @EXPORT_OK);
  2         3  
  2         339  
7             $VERSION = '0.06';
8             @ISA = qw(Exporter);
9              
10             sub BEGIN {
11 2     2   50 %NS = (
12             XML => 'http://www.w3.org/XML/1998/namespace',
13             XMLNS => 'http://www.w3.org/2000/xmlns/',
14             XLINK => 'http://www.w3.org/1999/xlink',
15             SVG => 'http://www.w3.org/2000/svg',
16             XHTML => 'http://www.w3.org/1999/xhtml',
17             XHTML2 => 'http://www.w3.org/2002/06/xhtml2',
18             XFORMS => 'http://www.w3.org/2002/xforms/cr',
19             XMLEVENTS => 'http://www.w3.org/2001/xml-events',
20             DC => 'http://purl.org/dc/elements/1.1/',
21             DC_TERMS => 'http://purl.org/dc/terms/',
22             RDF => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
23             RDFS => 'http://www.w3.org/2000/01/rdf-schema#',
24             OWL => 'http://www.w3.org/2002/07/owl#',
25             FOAF => 'http://xmlns.com/foaf/0.1/',
26             REL => 'http://purl.org/vocab/relationship/',
27             RSS1 => 'http://purl.org/rss/1.0/',
28             COMMENTS => 'http://purl.org/net/rssmodules/blogcomments/',
29             SYN => 'http://purl.org/rss/1.0/modules/syndication/',
30             RNG => 'http://relaxng.org/ns/structure/1.0',
31             XSD => 'http://www.w3.org/2001/XMLSchema',
32             XSI => 'http://www.w3.org/2001/XMLSchema-instance',
33             MATHML => 'http://www.w3.org/1998/Math/MathML',
34             XSLT => 'http://www.w3.org/1999/XSL/Transform',
35             XSLFO => 'http://www.w3.org/1999/XSL/Format',
36             SOAPENC11 => 'http://schemas.xmlsoap.org/soap/encoding/',
37             SOAPENV11 => 'http://schemas.xmlsoap.org/soap/envelope/',
38             SOAPENC12 => 'http://www.w3.org/2003/05/soap-encoding',
39             SOAPENV12 => 'http://www.w3.org/2003/05/soap-envelope',
40             WSDL11 => 'http://schemas.xmlsoap.org/wsdl/',
41             WSDL12 => 'http://www.w3.org/2003/06/wsdl',
42             );
43              
44 2         19 while (my ($k, $v) = each %NS) {
45 60         276 push @EXPORT_OK, '$' . $k;
46             }
47             }
48              
49             sub import {
50 2     2   27 my $class = shift;
51 2         5 my $pkg = caller;
52 2         5 my @opt = @_;
53              
54 2     2   9 no strict 'refs';
  2         4  
  2         266  
55 2 50       39 @opt = keys %NS if $opt[0] eq ':all';
56 2         6 for my $exp (@opt) {
57 3 50       9 die "No namespace available for key $exp" unless exists $NS{$exp};
58 3         8 __PACKAGE__->uri($exp);
59 3         252 __PACKAGE__->export_to_level( 1, $class, '$' . $exp );
60             }
61              
62 2         1578 return 1;
63             }
64              
65             sub uri {
66 4     4 1 2418 my ($self, $exp) = @_;
67 2     2   10 no strict 'refs';
  2         6  
  2         261  
68 4 50       7 unless (defined ${__PACKAGE__ . "::$exp"} ) {
  4         27  
69 4         19 ${__PACKAGE__ . "::$exp"} = XML::NamespaceFactory->new($NS{$exp});
  4         36  
70             }
71 4         6 return ${__PACKAGE__ . "::$exp"};
  4         14  
72             }
73              
74             1;
75              
76             =pod
77              
78             =head1 NAME
79              
80             XML::CommonNS - A list of commonly used namespaces
81              
82             =head1 SYNOPSIS
83              
84             # import $RDF, $RDFS, $OWL, $DC
85             use XML::CommonNS qw(RDF RDFS OWL DC);
86            
87             my %CONFIG = (
88             Namespaces => {
89             rdf => "$RDF",
90             rdfs => "$RDFS",
91             owl => "$OWL",
92             foaf => "$FOAF",
93             },
94             ExpandQNames => 1,
95             );
96            
97             # or the uri() method
98            
99             my $foaf = XML::CommonNS->uri('FOAF');
100            
101             =head1 DESCRIPTION
102             All you need do to use this module is import the namespaces you
103              
104             want from the list below. All of those will then become available
105             to you. They are XML::NamespaceFactory object and can thus be used
106             both as simple strings and as XML::NamespaceFactory objects. See
107             XML::NamespaceFactory for how that may help you.
108              
109             I hesitated for a while before releasing this module. As a directory
110             of namespaces that can't (and almost certainly shouldn't) be
111             exhaustive, it implies editorial decisions and I wasn't certain it
112             was CPAN worthy. However, after getting really tired of tracking
113             down namespaces in every single small XML muning script I made,
114             I wrote it for myself. After a while using it, I don't see why others
115             wouldn't find it useful as well.
116              
117             =head1 NAMESPACES
118              
119             The currently available namespaces are listed below. Should you
120             consider one worthy of addition (it needs to be common enough)
121             please simply notify me. Those marked with a start are subject to
122             change. I WILL change them when the corresponding specification
123             changes.
124              
125             XML http://www.w3.org/XML/1998/namespace
126             XMLNS http://www.w3.org/2000/xmlns/
127             XLINK http://www.w3.org/1999/xlink
128             SVG http://www.w3.org/2000/svg
129             XHTML http://www.w3.org/1999/xhtml
130             XHTML2 http://www.w3.org/2002/06/xhtml2
131             XFORMS http://www.w3.org/2002/xforms/cr
132             XMLEVENTS http://www.w3.org/2001/xml-events
133             DC http://purl.org/dc/elements/1.1/
134             DC_TERMS http://purl.org/dc/terms/
135             RDF http://www.w3.org/1999/02/22-rdf-syntax-ns#
136             RDFS http://www.w3.org/2000/01/rdf-schema#
137             OWL http://www.w3.org/2002/07/owl#
138             FOAF http://xmlns.com/foaf/0.1/
139             REL http://purl.org/vocab/relationship/
140             RSS1 http://purl.org/rss/1.0/
141             COMMENTS http://purl.org/net/rssmodules/blogcomments/
142             SYN http://purl.org/rss/1.0/modules/syndication/
143             RNG http://relaxng.org/ns/structure/1.0
144             XSD http://www.w3.org/2001/XMLSchema
145             XSI http://www.w3.org/2001/XMLSchema-instance
146             MATHML http://www.w3.org/1998/Math/MathML
147             XSLT http://www.w3.org/1999/XSL/Transform
148             XSLFO http://www.w3.org/1999/XSL/Format
149             SOAPENC11 http://schemas.xmlsoap.org/soap/encoding/
150             SOAPENV11 http://schemas.xmlsoap.org/soap/envelope/
151             SOAPENC12 http://www.w3.org/2003/05/soap-encoding
152             SOAPENV12 http://www.w3.org/2003/05/soap-envelope
153             WSDL11 http://schemas.xmlsoap.org/wsdl/
154             WSDL12 http://www.w3.org/2003/06/wsdl
155              
156             =head1 METHODS
157              
158             =over
159              
160             =item uri
161            
162             Allows you to directly retrieve one of the URI objects without doing the import() dance.
163            
164             =back
165              
166             =head1 AUTHOR
167              
168             Chris Prather, E<lt>chris@prather.orgE<gt>
169             Robin Berjon, E<lt>robin.berjon@expway.frE<gt>
170              
171             =head1 COPYRIGHT AND LICENSE
172              
173             Copyright 2003 by Robin Berjon
174              
175             This library is free software; you can redistribute it and/or modify
176             it under the same terms as Perl itself.
177              
178             =cut