| 1 |
package Net::XMPP2::Namespaces; |
| 2 |
use warnings; |
| 3 |
use strict; |
| 4 |
require Exporter; |
| 5 |
our @EXPORT_OK = qw/xmpp_ns set_xmpp_ns_alias xmpp_ns_maybe/; |
| 6 |
our @ISA = qw/Exporter/; |
| 7 |
|
| 8 |
our %NAMESPACES = ( |
| 9 |
client => 'jabber:client', |
| 10 |
component => 'jabber:component:accept', |
| 11 |
stream => 'http://etherx.jabber.org/streams', |
| 12 |
streams => 'urn:ietf:params:xml:ns:xmpp-streams', |
| 13 |
stanzas => 'urn:ietf:params:xml:ns:xmpp-stanzas', |
| 14 |
sasl => 'urn:ietf:params:xml:ns:xmpp-sasl', |
| 15 |
bind => 'urn:ietf:params:xml:ns:xmpp-bind', |
| 16 |
tls => 'urn:ietf:params:xml:ns:xmpp-tls', |
| 17 |
roster => 'jabber:iq:roster', |
| 18 |
register => 'jabber:iq:register', |
| 19 |
version => 'jabber:iq:version', |
| 20 |
session => 'urn:ietf:params:xml:ns:xmpp-session', |
| 21 |
xml => 'http://www.w3.org/XML/1998/namespace', |
| 22 |
disco_info => 'http://jabber.org/protocol/disco#info', |
| 23 |
disco_items => 'http://jabber.org/protocol/disco#items', |
| 24 |
register_f => 'http://jabber.org/features/iq-register', |
| 25 |
iqauth => 'http://jabber.org/features/iq-auth', |
| 26 |
data_form => 'jabber:x:data', |
| 27 |
iq_oob => 'jabber:iq:oob', |
| 28 |
x_oob => 'jabber:x:oob', |
| 29 |
muc => 'http://jabber.org/protocol/muc', |
| 30 |
muc_user => 'http://jabber.org/protocol/muc#user', |
| 31 |
muc_owner => 'http://jabber.org/protocol/muc#owner', |
| 32 |
search => 'jabber:iq:search', |
| 33 |
); |
| 34 |
|
| 35 |
=head1 NAME |
| 36 |
|
| 37 |
Net::XMPP2::Namespaces - XMPP namespace collection and aliasing class |
| 38 |
|
| 39 |
=head1 SYNOPSIS |
| 40 |
|
| 41 |
use Net::XMPP2::Namespaces qw/xmpp_ns set_xmpp_ns_alias/; |
| 42 |
|
| 43 |
set_xmpp_ns_alias (stanzas => 'urn:ietf:params:xml:ns:xmpp-stanzas'); |
| 44 |
|
| 45 |
=head1 DESCRIPTION |
| 46 |
|
| 47 |
This module represents a simple namespaces aliasing mechanism to ease handling |
| 48 |
of namespaces when traversing Net::XMPP2::Node objects and writing XML |
| 49 |
with Net::XMPP2::Writer. |
| 50 |
|
| 51 |
=head1 XMPP NAMESPACES |
| 52 |
|
| 53 |
There are already some aliases defined for the XMPP XML namespaces |
| 54 |
which make handling of namepsaces a bit easier: |
| 55 |
|
| 56 |
stream => http://etherx.jabber.org/streams |
| 57 |
xml => http://www.w3.org/XML/1998/namespace |
| 58 |
|
| 59 |
streams => urn:ietf:params:xml:ns:xmpp-streams |
| 60 |
session => urn:ietf:params:xml:ns:xmpp-session |
| 61 |
stanzas => urn:ietf:params:xml:ns:xmpp-stanzas |
| 62 |
sasl => urn:ietf:params:xml:ns:xmpp-sasl |
| 63 |
bind => urn:ietf:params:xml:ns:xmpp-bind |
| 64 |
tls => urn:ietf:params:xml:ns:xmpp-tls |
| 65 |
|
| 66 |
client => jabber:client |
| 67 |
roster => jabber:iq:roster |
| 68 |
version => jabber:iq:version |
| 69 |
|
| 70 |
iq_oob => jabber:iq:oob |
| 71 |
x_oob => jabber:x:oob |
| 72 |
|
| 73 |
disco_info => http://jabber.org/protocol/disco#info |
| 74 |
disco_items => http://jabber.org/protocol/disco#items |
| 75 |
|
| 76 |
register => http://jabber.org/features/iq-register |
| 77 |
iqauth => http://jabber.org/features/iq-auth |
| 78 |
data_form => jabber:x:data |
| 79 |
|
| 80 |
=head1 FUNCTIONS |
| 81 |
|
| 82 |
=over 4 |
| 83 |
|
| 84 |
=item B<xmpp_ns ($alias)> |
| 85 |
|
| 86 |
Returns am uri for the registered C<$alias> or undef if none exists. |
| 87 |
|
| 88 |
=cut |
| 89 |
|
| 90 |
sub xmpp_ns { return $NAMESPACES{$_[0]} } |
| 91 |
|
| 92 |
|
| 93 |
=item B<xmpp_ns_maybe ($alias_or_namespace_uri)> |
| 94 |
|
| 95 |
This method tries to find whether there is a alias C<$alias_or_namespace_uri> |
| 96 |
registered and if not it returns C<$alias_or_namespace_uri>. |
| 97 |
|
| 98 |
=cut |
| 99 |
|
| 100 |
sub xmpp_ns_maybe { |
| 101 |
my ($alias) = @_; |
| 102 |
return unless defined $alias; |
| 103 |
my $n = xmpp_ns ($alias); |
| 104 |
$n ? $n : $alias |
| 105 |
} |
| 106 |
|
| 107 |
=item B<set_xmpp_ns_alias ($alias, $namespace_uri)> |
| 108 |
|
| 109 |
Sets an C<$alias> for the C<$namespace_uri>. |
| 110 |
|
| 111 |
=cut |
| 112 |
|
| 113 |
sub set_xmpp_ns_alias { return $NAMESPACES{$_[0]} } |
| 114 |
|
| 115 |
=back |
| 116 |
|
| 117 |
=head1 AUTHOR |
| 118 |
|
| 119 |
Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >> |
| 120 |
|
| 121 |
=head1 COPYRIGHT & LICENSE |
| 122 |
|
| 123 |
Copyright 2007 Robin Redeker, all rights reserved. |
| 124 |
|
| 125 |
This program is free software; you can redistribute it and/or modify it |
| 126 |
under the same terms as Perl itself. |
| 127 |
|
| 128 |
=cut |
| 129 |
|
| 130 |
1; # End of Net::XMPP2 |