ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/Ext/Disco/Info.pm
Revision: 1.3
Committed: Wed Jul 4 16:05:22 2007 UTC (19 years, 4 months ago) by elmex
Branch: MAIN
Changes since 1.2: +12 -8 lines
Log Message:
major documentation refresh. preparing for release

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