ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/Ext/Disco/Info.pm
Revision: 1.2
Committed: Wed Apr 25 19:28:46 2007 UTC (19 years, 6 months ago) by elmex
Branch: MAIN
Changes since 1.1: +3 -3 lines
Log Message:
renamed some files

File Contents

# User Rev Content
1 elmex 1.2 package Net::XMPP2::Ext::Disco::Info;
2 elmex 1.1 use Net::XMPP2::Namespaces qw/xmpp_ns/;
3    
4     =head1 NAME
5    
6 elmex 1.2 Net::XMPP2::Ext::Disco::Info - Service discovery items
7 elmex 1.1
8     =head1 SYNOPSIS
9    
10    
11     =head1 DESCRIPTION
12    
13     This class represents the result of a disco info request
14 elmex 1.2 sent by a C<Net::XMPP2::Ext::Disco> handler.
15 elmex 1.1
16     =head1 METHODS
17    
18     =cut
19    
20     sub new {
21     my $this = shift;
22     my $class = ref($this) || $this;
23     my $self = bless { @_ }, $class;
24     $self->init;
25     $self
26     }
27    
28     =head2 xml_node ()
29    
30     Returns the L<Net::XMPP2::Node> object of the IQ query.
31    
32     =cut
33    
34     sub xml_node {
35     my ($self) = @_;
36     $self->{xmlnode}
37     }
38    
39     =head2 jid ()
40    
41     Returns the JID these items belong to.
42    
43     =cut
44    
45     sub jid { $_[0]->{jid} }
46    
47     =head2 node ()
48    
49     Returns the node these items belong to (may be undef).
50    
51     =cut
52    
53     sub node { $_[0]->{node} }
54    
55     sub init {
56     my ($self) = @_;
57     my $node = $self->{xmlnode};
58    
59     my (@ids) = $node->find_all ([qw/disco_info identity/]);
60     for (@ids) {
61     push @{$self->{identities}}, {
62     category => $_->attr ('category'),
63     type => $_->attr ('type'),
64     name => $_->attr ('name'),
65     xml_node => $_,
66     };
67     }
68    
69     my (@fs) = $node->find_all ([qw/disco_info feature/]);
70     $self->{features}->{$_->attr ('var')} = $_ for @fs;
71    
72     }
73    
74     =head2 identities ()
75    
76     Returns a list of hashrefs which contain following keys:
77    
78     category, type, name, xml_node
79    
80     C<category> is the category of the identity. C<type> is the
81     type of the identity. C<name> is the human readable name of
82     the identity and might be undef. C<xml_node> is the L<Net::XMPP2::Node>
83     object of the <identity/> node.
84    
85     C<category> and C<type> may be one of those defined on:
86    
87     http://www.xmpp.org/registrar/disco-categories.html
88    
89     =cut
90    
91     sub identities {
92     my ($self) = @_;
93     @{$self->{identities}}
94     }
95    
96     =head2 features ()
97    
98     Returns a hashref of key/value pairs where the key is the feature name
99     as listed on:
100    
101     http://www.xmpp.org/registrar/disco-features.html
102    
103     and the value is a L<Net::XMPP2::Node> object for the <feature/> node.
104    
105     =cut
106    
107     sub features { $_[0]->{features} || {} }
108    
109    
110     =head2 debug_dump ()
111    
112     Prints the information of this Info object to stdout.
113    
114     =cut
115    
116     sub debug_dump {
117     my ($self) = @_;
118     printf "INFO FOR %s (%s):\n", $self->jid, $self->node;
119     for ($self->identities) {
120     printf " ID : %20s/%-10s (%s)\n", $_->{category}, $_->{type}, $_->{name}
121     }
122     for (sort keys %{$self->features}) {
123     printf " FEATURE: %s\n", $_;
124     }
125     print "END ITEMS\n";p
126    
127     }
128    
129     =head1 AUTHOR
130    
131     Robin Redeker, C<< <elmex at ta-sa.org> >>
132    
133     =head1 COPYRIGHT & LICENSE
134    
135     Copyright 2007 Robin Redeker, all rights reserved.
136    
137     This program is free software; you can redistribute it and/or modify it
138     under the same terms as Perl itself.
139    
140     =cut
141    
142     1;